Skip to content

Commit 45c5635

Browse files
authored
Merge branch 'main' into feature/filter-repo-by-type
2 parents 21d32d4 + f74c869 commit 45c5635

File tree

115 files changed

+1719
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+1719
-608
lines changed

.eslintrc.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ rules:
296296
jquery/no-delegate: [2]
297297
jquery/no-each: [0]
298298
jquery/no-extend: [2]
299-
jquery/no-fade: [0]
299+
jquery/no-fade: [2]
300300
jquery/no-filter: [0]
301301
jquery/no-find: [0]
302302
jquery/no-global-eval: [2]
@@ -309,7 +309,7 @@ rules:
309309
jquery/no-is-function: [2]
310310
jquery/no-is: [0]
311311
jquery/no-load: [2]
312-
jquery/no-map: [0]
312+
jquery/no-map: [2]
313313
jquery/no-merge: [2]
314314
jquery/no-param: [2]
315315
jquery/no-parent: [0]
@@ -451,7 +451,7 @@ rules:
451451
no-jquery/no-load: [2]
452452
no-jquery/no-map-collection: [0]
453453
no-jquery/no-map-util: [2]
454-
no-jquery/no-map: [0]
454+
no-jquery/no-map: [2]
455455
no-jquery/no-merge: [2]
456456
no-jquery/no-node-name: [2]
457457
no-jquery/no-noop: [2]

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ ifdef DEPS_PLAYWRIGHT
164164
endif
165165

166166
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
167-
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
168-
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
167+
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape}}/api/v1"|g
168+
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g
169169
SWAGGER_EXCLUDE := code.gitea.io/sdk
170170
SWAGGER_NEWLINE_COMMAND := -e '$$a\'
171171

docs/content/usage/actions/comparison.zh-cn.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ Gitea Actions目前不支持此功能,如果使用它,结果将始终为空
9595

9696
## 缺失的功能
9797

98-
### 变量
99-
100-
请参阅[变量](https://docs.github.com/zh/actions/learn-github-actions/variables)
101-
102-
目前变量功能正在开发中。
103-
10498
### 问题匹配器
10599

106100
问题匹配器是一种扫描Actions输出以查找指定正则表达式模式并在用户界面中突出显示该信息的方法。

docs/content/usage/issue-pull-request-templates.en-us.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ menu:
1919

2020
Some projects have a standard list of questions that users need to answer
2121
when creating an issue or pull request. Gitea supports adding templates to the
22-
main branch of the repository so that they can autopopulate the form when users are
22+
**default branch of the repository** so that they can autopopulate the form when users are
2323
creating issues and pull requests. This will cut down on the initial back and forth
2424
of getting some clarifying details.
25+
It is currently not possible to provide generic issue/pull-request templates globally.
2526

2627
Additionally, the New Issue page URL can be suffixed with `?title=Issue+Title&body=Issue+Text` and the form will be populated with those strings. Those strings will be used instead of the template if there is one.
2728

models/actions/artifact.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const (
2626
ArtifactStatusUploadConfirmed // 2, ArtifactStatusUploadConfirmed is the status of an artifact upload that is confirmed
2727
ArtifactStatusUploadError // 3, ArtifactStatusUploadError is the status of an artifact upload that is errored
2828
ArtifactStatusExpired // 4, ArtifactStatusExpired is the status of an artifact that is expired
29+
ArtifactStatusPendingDeletion // 5, ArtifactStatusPendingDeletion is the status of an artifact that is pending deletion
30+
ArtifactStatusDeleted // 6, ArtifactStatusDeleted is the status of an artifact that is deleted
2931
)
3032

3133
func init() {
@@ -147,8 +149,28 @@ func ListNeedExpiredArtifacts(ctx context.Context) ([]*ActionArtifact, error) {
147149
Where("expired_unix < ? AND status = ?", timeutil.TimeStamp(time.Now().Unix()), ArtifactStatusUploadConfirmed).Find(&arts)
148150
}
149151

152+
// ListPendingDeleteArtifacts returns all artifacts in pending-delete status.
153+
// limit is the max number of artifacts to return.
154+
func ListPendingDeleteArtifacts(ctx context.Context, limit int) ([]*ActionArtifact, error) {
155+
arts := make([]*ActionArtifact, 0, limit)
156+
return arts, db.GetEngine(ctx).
157+
Where("status = ?", ArtifactStatusPendingDeletion).Limit(limit).Find(&arts)
158+
}
159+
150160
// SetArtifactExpired sets an artifact to expired
151161
func SetArtifactExpired(ctx context.Context, artifactID int64) error {
152162
_, err := db.GetEngine(ctx).Where("id=? AND status = ?", artifactID, ArtifactStatusUploadConfirmed).Cols("status").Update(&ActionArtifact{Status: int64(ArtifactStatusExpired)})
153163
return err
154164
}
165+
166+
// SetArtifactNeedDelete sets an artifact to need-delete, cron job will delete it
167+
func SetArtifactNeedDelete(ctx context.Context, runID int64, name string) error {
168+
_, err := db.GetEngine(ctx).Where("run_id=? AND artifact_name=? AND status = ?", runID, name, ArtifactStatusUploadConfirmed).Cols("status").Update(&ActionArtifact{Status: int64(ArtifactStatusPendingDeletion)})
169+
return err
170+
}
171+
172+
// SetArtifactDeleted sets an artifact to deleted
173+
func SetArtifactDeleted(ctx context.Context, artifactID int64) error {
174+
_, err := db.GetEngine(ctx).ID(artifactID).Cols("status").Update(&ActionArtifact{Status: int64(ArtifactStatusDeleted)})
175+
return err
176+
}

models/issues/review.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,14 @@ func IsOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organizatio
292292

293293
// CreateReview creates a new review based on opts
294294
func CreateReview(ctx context.Context, opts CreateReviewOptions) (*Review, error) {
295+
ctx, committer, err := db.TxContext(ctx)
296+
if err != nil {
297+
return nil, err
298+
}
299+
defer committer.Close()
300+
sess := db.GetEngine(ctx)
301+
295302
review := &Review{
296-
Type: opts.Type,
297303
Issue: opts.Issue,
298304
IssueID: opts.Issue.ID,
299305
Reviewer: opts.Reviewer,
@@ -303,15 +309,39 @@ func CreateReview(ctx context.Context, opts CreateReviewOptions) (*Review, error
303309
CommitID: opts.CommitID,
304310
Stale: opts.Stale,
305311
}
312+
306313
if opts.Reviewer != nil {
314+
review.Type = opts.Type
307315
review.ReviewerID = opts.Reviewer.ID
308-
} else {
309-
if review.Type != ReviewTypeRequest {
310-
review.Type = ReviewTypeRequest
316+
317+
reviewCond := builder.Eq{"reviewer_id": opts.Reviewer.ID, "issue_id": opts.Issue.ID}
318+
// make sure user review requests are cleared
319+
if opts.Type != ReviewTypePending {
320+
if _, err := sess.Where(reviewCond.And(builder.Eq{"type": ReviewTypeRequest})).Delete(new(Review)); err != nil {
321+
return nil, err
322+
}
311323
}
324+
// make sure if the created review gets dismissed no old review surface
325+
// other types can be ignored, as they don't affect branch protection
326+
if opts.Type == ReviewTypeApprove || opts.Type == ReviewTypeReject {
327+
if _, err := sess.Where(reviewCond.And(builder.In("type", ReviewTypeApprove, ReviewTypeReject))).
328+
Cols("dismissed").Update(&Review{Dismissed: true}); err != nil {
329+
return nil, err
330+
}
331+
}
332+
333+
} else if opts.ReviewerTeam != nil {
334+
review.Type = ReviewTypeRequest
312335
review.ReviewerTeamID = opts.ReviewerTeam.ID
336+
337+
} else {
338+
return nil, fmt.Errorf("provide either reviewer or reviewer team")
339+
}
340+
341+
if _, err := sess.Insert(review); err != nil {
342+
return nil, err
313343
}
314-
return review, db.Insert(ctx, review)
344+
return review, committer.Commit()
315345
}
316346

317347
// GetCurrentReview returns the current pending review of reviewer for given issue

models/unittest/unit_tests.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ func AssertSuccessfulInsert(t assert.TestingT, beans ...any) {
131131
}
132132

133133
// AssertCount assert the count of a bean
134-
func AssertCount(t assert.TestingT, bean, expected any) {
135-
assert.EqualValues(t, expected, GetCount(t, bean))
134+
func AssertCount(t assert.TestingT, bean, expected any) bool {
135+
return assert.EqualValues(t, expected, GetCount(t, bean))
136136
}
137137

138138
// AssertInt64InRange assert value is in range [low, high]
@@ -150,7 +150,7 @@ func GetCountByCond(t assert.TestingT, tableName string, cond builder.Cond) int6
150150
}
151151

152152
// AssertCountByCond test the count of database entries matching bean
153-
func AssertCountByCond(t assert.TestingT, tableName string, cond builder.Cond, expected int) {
154-
assert.EqualValues(t, expected, GetCountByCond(t, tableName, cond),
153+
func AssertCountByCond(t assert.TestingT, tableName string, cond builder.Cond, expected int) bool {
154+
return assert.EqualValues(t, expected, GetCountByCond(t, tableName, cond),
155155
"Failed consistency test, the counted bean (of table %s) was %+v", tableName, cond)
156156
}

modules/actions/github.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func canGithubEventMatch(eventName string, triggedEvent webhook_module.HookEvent
5252
case webhook_module.HookEventPullRequest,
5353
webhook_module.HookEventPullRequestSync,
5454
webhook_module.HookEventPullRequestAssign,
55-
webhook_module.HookEventPullRequestLabel:
55+
webhook_module.HookEventPullRequestLabel,
56+
webhook_module.HookEventPullRequestReviewRequest,
57+
webhook_module.HookEventPullRequestMilestone:
5658
return true
5759

5860
default:

modules/actions/workflows.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ func detectMatched(gitRepo *git.Repository, commit *git.Commit, triggedEvent web
221221
webhook_module.HookEventPullRequest,
222222
webhook_module.HookEventPullRequestSync,
223223
webhook_module.HookEventPullRequestAssign,
224-
webhook_module.HookEventPullRequestLabel:
224+
webhook_module.HookEventPullRequestLabel,
225+
webhook_module.HookEventPullRequestReviewRequest,
226+
webhook_module.HookEventPullRequestMilestone:
225227
return matchPullRequestEvent(gitRepo, commit, payload.(*api.PullRequestPayload), evt)
226228

227229
case // pull_request_review
@@ -397,13 +399,13 @@ func matchPullRequestEvent(gitRepo *git.Repository, commit *git.Commit, prPayloa
397399
} else {
398400
// See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
399401
// Actions with the same name:
400-
// opened, edited, closed, reopened, assigned, unassigned
402+
// opened, edited, closed, reopened, assigned, unassigned, review_requested, review_request_removed, milestoned, demilestoned
401403
// Actions need to be converted:
402404
// synchronized -> synchronize
403405
// label_updated -> labeled
404406
// label_cleared -> unlabeled
405407
// Unsupported activity types:
406-
// converted_to_draft, ready_for_review, locked, unlocked, review_requested, review_request_removed, auto_merge_enabled, auto_merge_disabled
408+
// converted_to_draft, ready_for_review, locked, unlocked, auto_merge_enabled, auto_merge_disabled, enqueued, dequeued
407409

408410
action := prPayload.Action
409411
switch action {

modules/base/tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func CreateTimeLimitCode(data string, minutes int, startInf any) string {
115115

116116
// create sha1 encode string
117117
sh := sha1.New()
118-
_, _ = sh.Write([]byte(fmt.Sprintf("%s%s%s%s%d", data, setting.SecretKey, startStr, endStr, minutes)))
118+
_, _ = sh.Write([]byte(fmt.Sprintf("%s%s%s%s%d", data, hex.EncodeToString(setting.GetGeneralTokenSigningSecret()), startStr, endStr, minutes)))
119119
encoded := hex.EncodeToString(sh.Sum(nil))
120120

121121
code := fmt.Sprintf("%s%06d%s", startStr, minutes, encoded)

modules/context/context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package context
66

77
import (
88
"context"
9+
"encoding/hex"
910
"fmt"
1011
"html/template"
1112
"io"
@@ -124,7 +125,7 @@ func NewWebContext(base *Base, render Render, session session.Store) *Context {
124125
func Contexter() func(next http.Handler) http.Handler {
125126
rnd := templates.HTMLRenderer()
126127
csrfOpts := CsrfOptions{
127-
Secret: setting.SecretKey,
128+
Secret: hex.EncodeToString(setting.GetGeneralTokenSigningSecret()),
128129
Cookie: setting.CSRFCookieName,
129130
SetCookie: true,
130131
Secure: setting.SessionConfig.Secure,

modules/context/context_response.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ func (ctx *Context) HTML(status int, name base.TplName) {
9090
}
9191
}
9292

93+
// JSONTemplate renders the template as JSON response
94+
// keep in mind that the template is processed in HTML context, so JSON-things should be handled carefully, eg: by JSEscape
95+
func (ctx *Context) JSONTemplate(tmpl base.TplName) {
96+
t, err := ctx.Render.TemplateLookup(string(tmpl), nil)
97+
if err != nil {
98+
ctx.ServerError("unable to find template", err)
99+
return
100+
}
101+
ctx.Resp.Header().Set("Content-Type", "application/json")
102+
if err = t.Execute(ctx.Resp, ctx.Data); err != nil {
103+
ctx.ServerError("unable to execute template", err)
104+
}
105+
}
106+
93107
// RenderToString renders the template content to a string
94108
func (ctx *Context) RenderToString(name base.TplName, data map[string]any) (string, error) {
95109
var buf strings.Builder

modules/context/context_template.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ package context
55

66
import (
77
"context"
8-
"errors"
98
"time"
10-
11-
"code.gitea.io/gitea/modules/log"
129
)
1310

1411
var _ context.Context = TemplateContext(nil)
@@ -36,14 +33,3 @@ func (c TemplateContext) Err() error {
3633
func (c TemplateContext) Value(key any) any {
3734
return c.parentContext().Value(key)
3835
}
39-
40-
// DataRaceCheck checks whether the template context function "ctx()" returns the consistent context
41-
// as the current template's rendering context (request context), to help to find data race issues as early as possible.
42-
// When the code is proven to be correct and stable, this function should be removed.
43-
func (c TemplateContext) DataRaceCheck(dataCtx context.Context) (string, error) {
44-
if c.parentContext() != dataCtx {
45-
log.Error("TemplateContext.DataRaceCheck: parent context mismatch\n%s", log.Stack(2))
46-
return "", errors.New("parent context mismatch")
47-
}
48-
return "", nil
49-
}

modules/git/repo_base_nogogit.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ type Repository struct {
2727

2828
gpgSettings *GPGSettings
2929

30+
batchInUse bool
3031
batchCancel context.CancelFunc
3132
batchReader *bufio.Reader
3233
batchWriter WriteCloserError
3334

35+
checkInUse bool
3436
checkCancel context.CancelFunc
3537
checkReader *bufio.Reader
3638
checkWriter WriteCloserError
@@ -79,23 +81,28 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
7981

8082
// CatFileBatch obtains a CatFileBatch for this repository
8183
func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bufio.Reader, func()) {
82-
if repo.batchCancel == nil || repo.batchReader.Buffered() > 0 {
84+
if repo.batchCancel == nil || repo.batchInUse {
8385
log.Debug("Opening temporary cat file batch for: %s", repo.Path)
8486
return CatFileBatch(ctx, repo.Path)
8587
}
86-
return repo.batchWriter, repo.batchReader, func() {}
88+
repo.batchInUse = true
89+
return repo.batchWriter, repo.batchReader, func() {
90+
repo.batchInUse = false
91+
}
8792
}
8893

8994
// CatFileBatchCheck obtains a CatFileBatchCheck for this repository
9095
func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func()) {
91-
if repo.checkCancel == nil || repo.checkReader.Buffered() > 0 {
92-
log.Debug("Opening temporary cat file batch-check: %s", repo.Path)
96+
if repo.checkCancel == nil || repo.checkInUse {
97+
log.Debug("Opening temporary cat file batch-check for: %s", repo.Path)
9398
return CatFileBatchCheck(ctx, repo.Path)
9499
}
95-
return repo.checkWriter, repo.checkReader, func() {}
100+
repo.checkInUse = true
101+
return repo.checkWriter, repo.checkReader, func() {
102+
repo.checkInUse = false
103+
}
96104
}
97105

98-
// Close this repository, in particular close the underlying gogitStorage if this is not nil
99106
func (repo *Repository) Close() (err error) {
100107
if repo == nil {
101108
return nil
@@ -105,12 +112,14 @@ func (repo *Repository) Close() (err error) {
105112
repo.batchReader = nil
106113
repo.batchWriter = nil
107114
repo.batchCancel = nil
115+
repo.batchInUse = false
108116
}
109117
if repo.checkCancel != nil {
110118
repo.checkCancel()
111119
repo.checkCancel = nil
112120
repo.checkReader = nil
113121
repo.checkWriter = nil
122+
repo.checkInUse = false
114123
}
115124
repo.LastCommitCache = nil
116125
repo.tagCache = nil

0 commit comments

Comments
 (0)