Skip to content

Commit b5f61df

Browse files
authored
Merge branch 'main' into issue-updates
2 parents e9ded26 + 35d5e4a commit b5f61df

File tree

94 files changed

+1188
-415
lines changed

Some content is hidden

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

94 files changed

+1188
-415
lines changed

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输出以查找指定正则表达式模式并在用户界面中突出显示该信息的方法。

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

0 commit comments

Comments
 (0)