From 828701ff2de67e179e79c79e6b52e92e770df789 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 19 Mar 2024 12:19:48 +0800 Subject: [PATCH 01/34] Fix template error when comment review doesn't exist (#29888) Fix #29885 --- models/fixtures/comment.yml | 8 + models/fixtures/review.yml | 9 + routers/web/repo/pull_review_test.go | 17 ++ templates/repo/diff/comments.tmpl | 2 +- templates/repo/diff/conversation.tmpl | 128 ++++----- .../repo/issue/view_content/comments.tmpl | 28 +- .../repo/issue/view_content/conversation.tmpl | 248 +++++++++--------- tests/integration/pull_review_test.go | 14 +- 8 files changed, 258 insertions(+), 196 deletions(-) diff --git a/models/fixtures/comment.yml b/models/fixtures/comment.yml index 17586caa2191f..74fc716180d1d 100644 --- a/models/fixtures/comment.yml +++ b/models/fixtures/comment.yml @@ -75,3 +75,11 @@ content: "comment in private pository" created_unix: 946684811 updated_unix: 946684811 + +- + id: 9 + type: 22 # review + poster_id: 2 + issue_id: 2 # in repo_id 1 + review_id: 20 + created_unix: 946684810 diff --git a/models/fixtures/review.yml b/models/fixtures/review.yml index 7a8808006849c..ac97e24c2be0c 100644 --- a/models/fixtures/review.yml +++ b/models/fixtures/review.yml @@ -170,3 +170,12 @@ content: "review request for user15" updated_unix: 946684835 created_unix: 946684835 + +- + id: 20 + type: 22 + reviewer_id: 1 + issue_id: 2 + content: "Review Comment" + updated_unix: 946684810 + created_unix: 946684810 diff --git a/routers/web/repo/pull_review_test.go b/routers/web/repo/pull_review_test.go index 5f035f1eb04cb..8344ff409113f 100644 --- a/routers/web/repo/pull_review_test.go +++ b/routers/web/repo/pull_review_test.go @@ -4,6 +4,7 @@ package repo import ( + "net/http" "net/http/httptest" "testing" @@ -73,4 +74,20 @@ func TestRenderConversation(t *testing.T) { renderConversation(ctx, preparedComment, "timeline") assert.Contains(t, resp.Body.String(), `
{{end}} - {{if and .Review}} + {{if .Review}} {{if eq .Review.Type 0}}
{{ctx.Locale.Tr "repo.issues.review.pending"}} diff --git a/templates/repo/diff/conversation.tmpl b/templates/repo/diff/conversation.tmpl index aaeac3c550dbd..507f17fd94b70 100644 --- a/templates/repo/diff/conversation.tmpl +++ b/templates/repo/diff/conversation.tmpl @@ -1,66 +1,72 @@ -{{$resolved := (index .comments 0).IsResolved}} -{{$invalid := (index .comments 0).Invalidated}} -{{$resolveDoer := (index .comments 0).ResolveDoer}} -{{$isNotPending := (not (eq (index .comments 0).Review.Type 0))}} -{{$referenceUrl := printf "%s#%s" $.Issue.Link (index .comments 0).HashTag}} -
- {{if $resolved}} -
-
- {{svg "octicon-check" 16 "icon gt-mr-2"}} - {{$resolveDoer.Name}} {{ctx.Locale.Tr "repo.issues.review.resolved_by"}} - {{if $invalid}} - - - {{ctx.Locale.Tr "repo.issues.review.outdated"}} - - {{end}} +{{if len .comments}} + {{$comment := index .comments 0}} + {{$resolved := $comment.IsResolved}} + {{$invalid := $comment.Invalidated}} + {{$resolveDoer := $comment.ResolveDoer}} + {{$hasReview := and $comment.Review}} + {{$isReviewPending := and $hasReview (eq $comment.Review.Type 0)}} + {{$referenceUrl := printf "%s#%s" $.Issue.Link $comment.HashTag}} +
+ {{if $resolved}} +
+
+ {{svg "octicon-check" 16 "icon gt-mr-2"}} + {{$resolveDoer.Name}} {{ctx.Locale.Tr "repo.issues.review.resolved_by"}} + {{if $invalid}} + + + {{ctx.Locale.Tr "repo.issues.review.outdated"}} + + {{end}} +
+
+ + +
-
- - + {{end}} +
+
+ + {{template "repo/diff/comments" dict "root" $ "comments" .comments}} +
-
- {{end}} -
-
- - {{template "repo/diff/comments" dict "root" $ "comments" .comments}} - -
-
-
- - +
+
+ + +
+ {{if and $.CanMarkConversation $hasReview (not $isReviewPending)}} + + {{end}} + {{if and $.SignedUserID (not $.Repository.IsArchived)}} + + {{end}}
- {{if and $.CanMarkConversation $isNotPending}} - - {{end}} - {{if and $.SignedUserID (not $.Repository.IsArchived)}} - - {{end}} + {{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" $comment.ReviewID "root" $ "comment" $comment}}
- {{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" (index .comments 0).ReviewID "root" $ "comment" (index .comments 0)}}
-
+{{else}} + {{template "repo/diff/conversation_outdated"}} +{{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index a9c6bbe31859d..c9170d97469c5 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -371,27 +371,31 @@ {{else if eq .Type 22}}
+ {{$reviewType := -1}} + {{if .Review}}{{$reviewType = .Review.Type}}{{end}} {{if not .OriginalAuthor}} {{/* Some timeline avatars need a offset to correctly align with their speech bubble. The condition depends on review type and for positive reviews whether there is a comment element or not */}} - + {{ctx.AvatarUtils.Avatar .Poster 40}} {{end}} - {{svg (printf "octicon-%s" .Review.Type.Icon)}} + + {{if .Review}}{{svg (printf "octicon-%s" .Review.Type.Icon)}}{{end}} + {{template "repo/issue/view_content/comments_authorlink" dict "ctxData" $ "comment" .}} - {{if eq .Review.Type 1}} + {{if eq $reviewType 1}} {{ctx.Locale.Tr "repo.issues.review.approve" $createdStr}} - {{else if eq .Review.Type 2}} + {{else if eq $reviewType 2}} {{ctx.Locale.Tr "repo.issues.review.comment" $createdStr}} - {{else if eq .Review.Type 3}} + {{else if eq $reviewType 3}} {{ctx.Locale.Tr "repo.issues.review.reject" $createdStr}} {{else}} {{ctx.Locale.Tr "repo.issues.review.comment" $createdStr}} {{end}} - {{if .Review.Dismissed}} + {{if and .Review .Review.Dismissed}}
{{ctx.Locale.Tr "repo.issues.review.dismissed_label"}}
{{end}}
@@ -451,7 +455,7 @@
{{end}} - {{if .Review.CodeComments}} + {{if and .Review .Review.CodeComments}}
{{range $filename, $lines := .Review.CodeComments}} {{range $line, $comms := $lines}} @@ -607,10 +611,12 @@ {{template "shared/user/authorlink" .Poster}} {{$reviewerName := ""}} - {{if eq .Review.OriginalAuthor ""}} - {{$reviewerName = .Review.Reviewer.Name}} - {{else}} - {{$reviewerName = .Review.OriginalAuthor}} + {{if .Review}} + {{if eq .Review.OriginalAuthor ""}} + {{$reviewerName = .Review.Reviewer.Name}} + {{else}} + {{$reviewerName = .Review.OriginalAuthor}} + {{end}} {{end}} {{ctx.Locale.Tr "repo.issues.review.dismissed" $reviewerName $createdStr}} diff --git a/templates/repo/issue/view_content/conversation.tmpl b/templates/repo/issue/view_content/conversation.tmpl index b6e075d0ced57..d93589539c618 100644 --- a/templates/repo/issue/view_content/conversation.tmpl +++ b/templates/repo/issue/view_content/conversation.tmpl @@ -1,137 +1,143 @@ -{{$invalid := (index .comments 0).Invalidated}} -{{$resolved := (index .comments 0).IsResolved}} -{{$resolveDoer := (index .comments 0).ResolveDoer}} -{{$isNotPending := (not (eq (index .comments 0).Review.Type 0))}} -
-
-
- {{(index .comments 0).TreePath}} - {{if $invalid}} - - {{ctx.Locale.Tr "repo.issues.review.outdated"}} - - {{end}} -
-
- {{if or $invalid $resolved}} - - - {{end}} +{{if len .comments}} + {{$comment := index .comments 0}} + {{$invalid := $comment.Invalidated}} + {{$resolved := $comment.IsResolved}} + {{$resolveDoer := $comment.ResolveDoer}} + {{$hasReview := and $comment.Review}} + {{$isReviewPending := and $hasReview (eq $comment.Review.Type 0)}} +
+
+
+ {{$comment.TreePath}} + {{if $invalid}} + + {{ctx.Locale.Tr "repo.issues.review.outdated"}} + + {{end}} +
+
+ {{if or $invalid $resolved}} + + + {{end}} +
-
- {{$diff := (CommentMustAsDiff ctx (index .comments 0))}} - {{if $diff}} - {{$file := (index $diff.Files 0)}} -
-
-
- - - {{template "repo/diff/section_unified" dict "file" $file "root" $}} - -
+ {{$diff := (CommentMustAsDiff ctx $comment)}} + {{if $diff}} + {{$file := (index $diff.Files 0)}} +
+
+
+ + + {{template "repo/diff/section_unified" dict "file" $file "root" $}} + +
+
-
- {{end}} -
-
- {{range .comments}} - {{$createdSubStr:= TimeSinceUnix .CreatedUnix ctx.Locale}} -
-
-
-
- {{if not .OriginalAuthor}} - - {{ctx.AvatarUtils.Avatar .Poster 20}} - - {{end}} - - {{if .OriginalAuthor}} - - {{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}} - {{.OriginalAuthor}} - - {{if $.Repository.OriginalURL}} - ({{ctx.Locale.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname}}) + {{end}} +
+
+ {{range .comments}} + {{$createdSubStr:= TimeSinceUnix .CreatedUnix ctx.Locale}} +
+
+
+
+ {{if not .OriginalAuthor}} + + {{ctx.AvatarUtils.Avatar .Poster 20}} + + {{end}} + + {{if .OriginalAuthor}} + + {{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}} + {{.OriginalAuthor}} + + {{if $.Repository.OriginalURL}} + ({{ctx.Locale.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname}}) + {{end}} + {{else}} + {{template "shared/user/authorlink" .Poster}} {{end}} - {{else}} - {{template "shared/user/authorlink" .Poster}} + {{ctx.Locale.Tr "repo.issues.commented_at" .HashTag $createdSubStr}} + +
+
+ {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}} + {{if not $.Repository.IsArchived}} + {{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}} + {{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" true "issue" true "diff" true "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}} {{end}} - {{ctx.Locale.Tr "repo.issues.commented_at" .HashTag $createdSubStr}} - +
-
- {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}} - {{if not $.Repository.IsArchived}} - {{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}} - {{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" true "issue" true "diff" true "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}} +
+
+ {{if .RenderedContent}} + {{.RenderedContent}} + {{else}} + {{ctx.Locale.Tr "repo.issues.no_content"}} + {{end}} +
+
{{.Content}}
+
+ {{if .Attachments}} + {{template "repo/issue/view_content/attachments" dict "Attachments" .Attachments "RenderedContent" .RenderedContent}} {{end}}
-
-
-
- {{if .RenderedContent}} - {{.RenderedContent}} - {{else}} - {{ctx.Locale.Tr "repo.issues.no_content"}} - {{end}} -
-
{{.Content}}
-
- {{if .Attachments}} - {{template "repo/issue/view_content/attachments" dict "Attachments" .Attachments "RenderedContent" .RenderedContent}} + {{$reactions := .Reactions.GroupByType}} + {{if $reactions}} + {{template "repo/issue/view_content/reactions" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}} {{end}}
- {{$reactions := .Reactions.GroupByType}} - {{if $reactions}} - {{template "repo/issue/view_content/reactions" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}} - {{end}} -
-
- {{end}} -
-
-
- {{if $resolved}} -
- {{svg "octicon-check" 16 "gt-mr-2"}} - {{$resolveDoer.Name}} {{ctx.Locale.Tr "repo.issues.review.resolved_by"}}
{{end}}
-
- {{if and $.CanMarkConversation $isNotPending}} - - {{end}} - {{if and $.SignedUserID (not $.Repository.IsArchived)}} - - {{end}} +
+
+ {{if $resolved}} +
+ {{svg "octicon-check" 16 "gt-mr-2"}} + {{$resolveDoer.Name}} {{ctx.Locale.Tr "repo.issues.review.resolved_by"}} +
+ {{end}} +
+
+ {{if and $.CanMarkConversation $hasReview (not $isReviewPending)}} + + {{end}} + {{if and $.SignedUserID (not $.Repository.IsArchived)}} + + {{end}} +
+ {{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" $comment.ReviewID "root" $ "comment" $comment}}
- {{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" (index .comments 0).ReviewID "root" $ "comment" (index .comments 0)}}
-
+{{else}} + {{template "repo/diff/conversation_outdated"}} +{{end}} diff --git a/tests/integration/pull_review_test.go b/tests/integration/pull_review_test.go index 459aa5a58b183..bdfecb32805c4 100644 --- a/tests/integration/pull_review_test.go +++ b/tests/integration/pull_review_test.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/test" repo_service "code.gitea.io/gitea/services/repository" files_service "code.gitea.io/gitea/services/repository/files" "code.gitea.io/gitea/tests" @@ -26,10 +27,19 @@ func TestPullView_ReviewerMissed(t *testing.T) { session := loginUser(t, "user1") req := NewRequest(t, "GET", "/pulls") - session.MakeRequest(t, req, http.StatusOK) + resp := session.MakeRequest(t, req, http.StatusOK) + assert.True(t, test.IsNormalPageCompleted(resp.Body.String())) req = NewRequest(t, "GET", "/user2/repo1/pulls/3") - session.MakeRequest(t, req, http.StatusOK) + resp = session.MakeRequest(t, req, http.StatusOK) + assert.True(t, test.IsNormalPageCompleted(resp.Body.String())) + + // if some reviews are missing, the page shouldn't fail + err := db.TruncateBeans(db.DefaultContext, &issues_model.Review{}) + assert.NoError(t, err) + req = NewRequest(t, "GET", "/user2/repo1/pulls/2") + resp = session.MakeRequest(t, req, http.StatusOK) + assert.True(t, test.IsNormalPageCompleted(resp.Body.String())) } func TestPullView_CodeOwner(t *testing.T) { From 656d8e2267dbdbb595704d507a780533038bb7ed Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 19 Mar 2024 12:46:40 +0800 Subject: [PATCH 02/34] Fix milestoneID filter bug in issue list (#29897) Fix #29717 --- routers/web/repo/issue.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index a0a500f0b233b..fb03ed9d9c1e9 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -446,13 +446,13 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt linkStr := "%s?q=%s&type=%s&sort=%s&state=%s&labels=%s&milestone=%d&project=%d&assignee=%d&poster=%d&archived=%t" ctx.Data["AllStatesLink"] = fmt.Sprintf(linkStr, ctx.Link, url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "all", url.QueryEscape(selectLabels), - mentionedID, projectID, assigneeID, posterID, archived) + milestoneID, projectID, assigneeID, posterID, archived) ctx.Data["OpenLink"] = fmt.Sprintf(linkStr, ctx.Link, url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "open", url.QueryEscape(selectLabels), - mentionedID, projectID, assigneeID, posterID, archived) + milestoneID, projectID, assigneeID, posterID, archived) ctx.Data["ClosedLink"] = fmt.Sprintf(linkStr, ctx.Link, url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "closed", url.QueryEscape(selectLabels), - mentionedID, projectID, assigneeID, posterID, archived) + milestoneID, projectID, assigneeID, posterID, archived) ctx.Data["SelLabelIDs"] = labelIDs ctx.Data["SelectLabels"] = selectLabels ctx.Data["ViewType"] = viewType From 17d7ab5ad4ce3d0fbc1251572c22687c237a30b1 Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Tue, 19 Mar 2024 06:28:43 +0100 Subject: [PATCH 03/34] Notify reviewers added via CODEOWNERS (#29842) --- services/issue/assignee.go | 23 +++++++++++++++--- services/issue/issue.go | 20 ++++++++++++---- services/issue/pull.go | 49 +++++++++++++++++++++++++++----------- services/pull/pull.go | 7 ++++-- 4 files changed, 75 insertions(+), 24 deletions(-) diff --git a/services/issue/assignee.go b/services/issue/assignee.go index b5f472ba530c1..8740a6664a5a7 100644 --- a/services/issue/assignee.go +++ b/services/issue/assignee.go @@ -226,16 +226,33 @@ func TeamReviewRequest(ctx context.Context, issue *issues_model.Issue, doer *use return nil, nil } + return comment, teamReviewRequestNotify(ctx, issue, doer, reviewer, isAdd, comment) +} + +func ReviewRequestNotify(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, reviewNotifers []*ReviewRequestNotifier) { + for _, reviewNotifer := range reviewNotifers { + if reviewNotifer.Reviwer != nil { + notify_service.PullRequestReviewRequest(ctx, issue.Poster, issue, reviewNotifer.Reviwer, reviewNotifer.IsAdd, reviewNotifer.Comment) + } else if reviewNotifer.ReviewTeam != nil { + if err := teamReviewRequestNotify(ctx, issue, issue.Poster, reviewNotifer.ReviewTeam, reviewNotifer.IsAdd, reviewNotifer.Comment); err != nil { + log.Error("teamReviewRequestNotify: %v", err) + } + } + } +} + +// teamReviewRequestNotify notify all user in this team +func teamReviewRequestNotify(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, reviewer *organization.Team, isAdd bool, comment *issues_model.Comment) error { // notify all user in this team if err := comment.LoadIssue(ctx); err != nil { - return nil, err + return err } members, err := organization.GetTeamMembers(ctx, &organization.SearchMembersOptions{ TeamID: reviewer.ID, }) if err != nil { - return nil, err + return err } for _, member := range members { @@ -246,7 +263,7 @@ func TeamReviewRequest(ctx context.Context, issue *issues_model.Issue, doer *use notify_service.PullRequestReviewRequest(ctx, doer, issue, member, isAdd, comment) } - return comment, err + return err } // CanDoerChangeReviewRequests returns if the doer can add/remove review requests of a PR diff --git a/services/issue/issue.go b/services/issue/issue.go index 7662c9d9e8c87..94b0ee6f693eb 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -85,17 +85,27 @@ func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_mode } } - if err := issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil { - return err - } + var reviewNotifers []*ReviewRequestNotifier - if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) { - if err := PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest); err != nil { + if err := db.WithTx(ctx, func(ctx context.Context) error { + if err := issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil { return err } + + if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) { + var err error + reviewNotifers, err = PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest) + if err != nil { + return err + } + } + return nil + }); err != nil { + return err } notify_service.IssueChangeTitle(ctx, doer, issue, oldTitle) + ReviewRequestNotify(ctx, issue, issue.Poster, reviewNotifers) return nil } diff --git a/services/issue/pull.go b/services/issue/pull.go index 698e2622f5406..8e85c11e9b873 100644 --- a/services/issue/pull.go +++ b/services/issue/pull.go @@ -33,34 +33,41 @@ func getMergeBase(repo *git.Repository, pr *issues_model.PullRequest, baseBranch return mergeBase, err } -func PullRequestCodeOwnersReview(ctx context.Context, pull *issues_model.Issue, pr *issues_model.PullRequest) error { +type ReviewRequestNotifier struct { + Comment *issues_model.Comment + IsAdd bool + Reviwer *user_model.User + ReviewTeam *org_model.Team +} + +func PullRequestCodeOwnersReview(ctx context.Context, pull *issues_model.Issue, pr *issues_model.PullRequest) ([]*ReviewRequestNotifier, error) { files := []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"} if pr.IsWorkInProgress(ctx) { - return nil + return nil, nil } if err := pr.LoadHeadRepo(ctx); err != nil { - return err + return nil, err } if pr.HeadRepo.IsFork { - return nil + return nil, nil } if err := pr.LoadBaseRepo(ctx); err != nil { - return err + return nil, err } repo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo) if err != nil { - return err + return nil, err } defer repo.Close() commit, err := repo.GetBranchCommit(pr.BaseRepo.DefaultBranch) if err != nil { - return err + return nil, err } var data string @@ -78,14 +85,14 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *issues_model.Issue, // get the mergebase mergeBase, err := getMergeBase(repo, pr, git.BranchPrefix+pr.BaseBranch, pr.GetGitRefName()) if err != nil { - return err + return nil, err } // https://github.com/go-gitea/gitea/issues/29763, we need to get the files changed // between the merge base and the head commit but not the base branch and the head commit changedFiles, err := repo.GetFilesChangedBetween(mergeBase, pr.HeadCommitID) if err != nil { - return err + return nil, err } uniqUsers := make(map[int64]*user_model.User) @@ -103,20 +110,34 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *issues_model.Issue, } } + notifiers := make([]*ReviewRequestNotifier, 0, len(uniqUsers)+len(uniqTeams)) + for _, u := range uniqUsers { if u.ID != pull.Poster.ID { - if _, err := issues_model.AddReviewRequest(ctx, pull, u, pull.Poster); err != nil { + comment, err := issues_model.AddReviewRequest(ctx, pull, u, pull.Poster) + if err != nil { log.Warn("Failed add assignee user: %s to PR review: %s#%d, error: %s", u.Name, pr.BaseRepo.Name, pr.ID, err) - return err + return nil, err } + notifiers = append(notifiers, &ReviewRequestNotifier{ + Comment: comment, + IsAdd: true, + Reviwer: pull.Poster, + }) } } for _, t := range uniqTeams { - if _, err := issues_model.AddTeamReviewRequest(ctx, pull, t, pull.Poster); err != nil { + comment, err := issues_model.AddTeamReviewRequest(ctx, pull, t, pull.Poster) + if err != nil { log.Warn("Failed add assignee team: %s to PR review: %s#%d, error: %s", t.Name, pr.BaseRepo.Name, pr.ID, err) - return err + return nil, err } + notifiers = append(notifiers, &ReviewRequestNotifier{ + Comment: comment, + IsAdd: true, + ReviewTeam: t, + }) } - return nil + return notifiers, nil } diff --git a/services/pull/pull.go b/services/pull/pull.go index 57873b63ba6bf..8a9c6db91764e 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -77,6 +77,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss } defer baseGitRepo.Close() + var reviewNotifers []*issue_service.ReviewRequestNotifier if err := db.WithTx(ctx, func(ctx context.Context) error { if err := issues_model.NewPullRequest(ctx, repo, issue, labelIDs, uuids, pr); err != nil { return err @@ -136,7 +137,8 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss } if !pr.IsWorkInProgress(ctx) { - if err := issue_service.PullRequestCodeOwnersReview(ctx, issue, pr); err != nil { + reviewNotifers, err = issue_service.PullRequestCodeOwnersReview(ctx, issue, pr) + if err != nil { return err } } @@ -150,11 +152,12 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss } baseGitRepo.Close() // close immediately to avoid notifications will open the repository again + issue_service.ReviewRequestNotify(ctx, issue, issue.Poster, reviewNotifers) + mentions, err := issues_model.FindAndUpdateIssueMentions(ctx, issue, issue.Poster, issue.Content) if err != nil { return err } - notify_service.NewPullRequest(ctx, pr, mentions) if len(issue.Labels) > 0 { notify_service.IssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil) From 98217b034076157547cf688cc10f47cd3275c872 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 19 Mar 2024 16:23:40 +0900 Subject: [PATCH 04/34] Fix invalid link of the commit status when ref is tag (#29752) Fix #29731 Caused by #24634 Also remove fixme. ps: we can not fix the existed runs, as wrong refs are all recorded in DB, and we can not know whether they are branch or tag: ![image](https://github.com/go-gitea/gitea/assets/18380374/cb7cf266-f73f-419a-be1a-4689fdd1952a) --- services/actions/notifier.go | 16 ++- tests/integration/actions_trigger_test.go | 119 ++++++++++++++++++++++ 2 files changed, 132 insertions(+), 3 deletions(-) diff --git a/services/actions/notifier.go b/services/actions/notifier.go index aa88d4e0d87b1..eec5f814da22d 100644 --- a/services/actions/notifier.go +++ b/services/actions/notifier.go @@ -515,6 +515,12 @@ func (*actionsNotifier) MergePullRequest(ctx context.Context, doer *user_model.U } func (n *actionsNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { + commitID, _ := git.NewIDFromString(opts.NewCommitID) + if commitID.IsZero() { + log.Trace("new commitID is empty") + return + } + ctx = withMethod(ctx, "PushCommits") apiPusher := convert.ToUser(ctx, pusher, nil) @@ -547,9 +553,9 @@ func (n *actionsNotifier) CreateRef(ctx context.Context, pusher *user_model.User apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeNone}) newNotifyInput(repo, pusher, webhook_module.HookEventCreate). - WithRef(refFullName.ShortName()). // FIXME: should we use a full ref name + WithRef(refFullName.String()). WithPayload(&api.CreatePayload{ - Ref: refFullName.ShortName(), + Ref: refFullName.String(), Sha: refID, RefType: refFullName.RefType(), Repo: apiRepo, @@ -566,7 +572,7 @@ func (n *actionsNotifier) DeleteRef(ctx context.Context, pusher *user_model.User newNotifyInput(repo, pusher, webhook_module.HookEventDelete). WithPayload(&api.DeletePayload{ - Ref: refFullName.ShortName(), + Ref: refFullName.String(), RefType: refFullName.RefType(), PusherType: api.PusherTypeUser, Repo: apiRepo, @@ -623,6 +629,10 @@ func (n *actionsNotifier) UpdateRelease(ctx context.Context, doer *user_model.Us } func (n *actionsNotifier) DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { + if rel.IsTag { + // has sent same action in `PushCommits`, so skip it. + return + } ctx = withMethod(ctx, "DeleteRelease") notifyRelease(ctx, doer, rel, api.HookReleaseDeleted) } diff --git a/tests/integration/actions_trigger_test.go b/tests/integration/actions_trigger_test.go index 9a8bfc5db6ecf..2a2fdceb61e90 100644 --- a/tests/integration/actions_trigger_test.go +++ b/tests/integration/actions_trigger_test.go @@ -12,6 +12,7 @@ import ( actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" + git_model "code.gitea.io/gitea/models/git" issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" @@ -19,9 +20,11 @@ import ( user_model "code.gitea.io/gitea/models/user" actions_module "code.gitea.io/gitea/modules/actions" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/test" pull_service "code.gitea.io/gitea/services/pull" + release_service "code.gitea.io/gitea/services/release" repo_service "code.gitea.io/gitea/services/repository" files_service "code.gitea.io/gitea/services/repository/files" @@ -324,3 +327,119 @@ func TestSkipCI(t *testing.T) { assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID})) }) } + +func TestCreateDeleteRefEvent(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + + // create the repo + repo, err := repo_service.CreateRepository(db.DefaultContext, user2, user2, repo_service.CreateRepoOptions{ + Name: "create-delete-ref-event", + Description: "test create delete ref ci event", + AutoInit: true, + Gitignores: "Go", + License: "MIT", + Readme: "Default", + DefaultBranch: "main", + IsPrivate: false, + }) + assert.NoError(t, err) + assert.NotEmpty(t, repo) + + // enable actions + err = repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, []repo_model.RepoUnit{{ + RepoID: repo.ID, + Type: unit_model.TypeActions, + }}, nil) + assert.NoError(t, err) + + // add workflow file to the repo + addWorkflowToBaseResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ + Files: []*files_service.ChangeRepoFile{ + { + Operation: "create", + TreePath: ".gitea/workflows/createdelete.yml", + ContentReader: strings.NewReader("name: test\non:\n [create,delete]\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"), + }, + }, + Message: "add workflow", + OldBranch: "main", + NewBranch: "main", + Author: &files_service.IdentityOptions{ + Name: user2.Name, + Email: user2.Email, + }, + Committer: &files_service.IdentityOptions{ + Name: user2.Name, + Email: user2.Email, + }, + Dates: &files_service.CommitDateOptions{ + Author: time.Now(), + Committer: time.Now(), + }, + }) + assert.NoError(t, err) + assert.NotEmpty(t, addWorkflowToBaseResp) + + // Get the commit ID of the default branch + gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo) + assert.NoError(t, err) + defer gitRepo.Close() + branch, err := git_model.GetBranch(db.DefaultContext, repo.ID, repo.DefaultBranch) + assert.NoError(t, err) + + // create a branch + err = repo_service.CreateNewBranchFromCommit(db.DefaultContext, user2, repo, gitRepo, branch.CommitID, "test-create-branch") + assert.NoError(t, err) + run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ + Title: "add workflow", + RepoID: repo.ID, + Event: "create", + Ref: "refs/heads/test-create-branch", + WorkflowID: "createdelete.yml", + CommitSHA: branch.CommitID, + }) + assert.NotNil(t, run) + + // create a tag + err = release_service.CreateNewTag(db.DefaultContext, user2, repo, branch.CommitID, "test-create-tag", "test create tag event") + assert.NoError(t, err) + run = unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ + Title: "add workflow", + RepoID: repo.ID, + Event: "create", + Ref: "refs/tags/test-create-tag", + WorkflowID: "createdelete.yml", + CommitSHA: branch.CommitID, + }) + assert.NotNil(t, run) + + // delete the branch + err = repo_service.DeleteBranch(db.DefaultContext, user2, repo, gitRepo, "test-create-branch") + assert.NoError(t, err) + run = unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ + Title: "add workflow", + RepoID: repo.ID, + Event: "delete", + Ref: "main", + WorkflowID: "createdelete.yml", + CommitSHA: branch.CommitID, + }) + assert.NotNil(t, run) + + // delete the tag + tag, err := repo_model.GetRelease(db.DefaultContext, repo.ID, "test-create-tag") + assert.NoError(t, err) + err = release_service.DeleteReleaseByID(db.DefaultContext, repo, tag, user2, true) + assert.NoError(t, err) + run = unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ + Title: "add workflow", + RepoID: repo.ID, + Event: "delete", + Ref: "main", + WorkflowID: "createdelete.yml", + CommitSHA: branch.CommitID, + }) + assert.NotNil(t, run) + }) +} From 5a8559ec47a271e45bf5836eaf5e9040a0f1d6bf Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 19 Mar 2024 11:36:54 +0100 Subject: [PATCH 05/34] Fix border on focus in dashboard repo search (#29893) Before: Screenshot 2024-03-18 at 22 35 10 After: image --- web_src/css/base.css | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web_src/css/base.css b/web_src/css/base.css index ea5ba9ce8756a..b47de5ad50dfb 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -283,7 +283,9 @@ ol.ui.list li, .ui.action.input:not([class*="left action"]) > input:focus + .ui.dropdown.selection, .ui.action.input:not([class*="left action"]) > input:focus + .ui.dropdown.selection:hover, .ui.action.input:not([class*="left action"]) > input:focus + .button, -.ui.action.input:not([class*="left action"]) > input:focus + .button:hover { +.ui.action.input:not([class*="left action"]) > input:focus + .button:hover, +.ui.action.input:not([class*="left action"]) > input:focus + .icon + .button, +.ui.action.input:not([class*="left action"]) > input:focus + .icon + .button:hover { border-left-color: var(--color-primary); } .ui.action.input:not([class*="left action"]) > input:focus { @@ -1956,6 +1958,10 @@ table th[data-sortt-desc] .svg { justify-content: center; } +.ui.icon.input > i.icon { + transition: none; +} + .flex-items-block > .item, .flex-text-block { display: flex; From fa100618c4b644346bf5666f92d33dce0747d0a2 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 19 Mar 2024 17:28:46 +0100 Subject: [PATCH 06/34] Forbid jQuery `.css` and refactor all usage (#29852) Tested all functionality. There is a [pre-existing bug](https://github.com/go-gitea/gitea/issues/29853) when moving a project panels which is not caused by this refactoring. --------- Co-authored-by: wxiaoguang --- .eslintrc.yaml | 4 +- web_src/js/features/colorpicker.js | 8 +- web_src/js/features/comp/ColorPicker.js | 16 ++-- web_src/js/features/comp/LabelEdit.js | 6 +- web_src/js/features/imagediff.js | 108 ++++++++++++------------ web_src/js/features/repo-legacy.js | 2 +- web_src/js/features/repo-projects.js | 7 +- 7 files changed, 78 insertions(+), 73 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index b65fe56cf284a..72039a601380a 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -286,7 +286,7 @@ rules: jquery/no-class: [0] jquery/no-clone: [2] jquery/no-closest: [0] - jquery/no-css: [0] + jquery/no-css: [2] jquery/no-data: [0] jquery/no-deferred: [2] jquery/no-delegate: [2] @@ -409,7 +409,7 @@ rules: no-jquery/no-constructor-attributes: [2] no-jquery/no-contains: [2] no-jquery/no-context-prop: [2] - no-jquery/no-css: [0] + no-jquery/no-css: [2] no-jquery/no-data: [0] no-jquery/no-deferred: [2] no-jquery/no-delegate: [2] diff --git a/web_src/js/features/colorpicker.js b/web_src/js/features/colorpicker.js index a5fdb3f5a6e53..df0353376d756 100644 --- a/web_src/js/features/colorpicker.js +++ b/web_src/js/features/colorpicker.js @@ -1,10 +1,12 @@ -export async function createColorPicker($els) { - if (!$els || !$els.length) return; +import $ from 'jquery'; + +export async function createColorPicker(els) { + if (!els.length) return; await Promise.all([ import(/* webpackChunkName: "minicolors" */'@claviska/jquery-minicolors'), import(/* webpackChunkName: "minicolors" */'@claviska/jquery-minicolors/jquery.minicolors.css'), ]); - $els.minicolors(); + return $(els).minicolors(); } diff --git a/web_src/js/features/comp/ColorPicker.js b/web_src/js/features/comp/ColorPicker.js index 5665b7a24aae1..d7e703880377a 100644 --- a/web_src/js/features/comp/ColorPicker.js +++ b/web_src/js/features/comp/ColorPicker.js @@ -2,11 +2,15 @@ import $ from 'jquery'; import {createColorPicker} from '../colorpicker.js'; export function initCompColorPicker() { - createColorPicker($('.color-picker')); + (async () => { + await createColorPicker(document.querySelectorAll('.color-picker')); - $('.precolors .color').on('click', function () { - const color_hex = $(this).data('color-hex'); - $('.color-picker').val(color_hex); - $('.minicolors-swatch-color').css('background-color', color_hex); - }); + for (const el of document.querySelectorAll('.precolors .color')) { + el.addEventListener('click', (e) => { + const color = e.target.getAttribute('data-color-hex'); + const parent = e.target.closest('.color.picker'); + $(parent.querySelector('.color-picker')).minicolors('value', color); + }); + } + })(); } diff --git a/web_src/js/features/comp/LabelEdit.js b/web_src/js/features/comp/LabelEdit.js index 26800ae05c92e..44fc9d9b6b37e 100644 --- a/web_src/js/features/comp/LabelEdit.js +++ b/web_src/js/features/comp/LabelEdit.js @@ -43,7 +43,6 @@ export function initCompLabelEdit(selector) { // Edit label $('.edit-label-button').on('click', function () { - $('.edit-label .color-picker').minicolors('value', $(this).data('color')); $('#label-modal-id').val($(this).data('id')); const $nameInput = $('.edit-label .label-name-input'); @@ -60,9 +59,8 @@ export function initCompLabelEdit(selector) { (!this.hasAttribute('data-exclusive') || !isExclusiveScopeName($nameInput.val()))); updateExclusiveLabelEdit('.edit-label'); - $('.edit-label .label-desc-input').val($(this).data('description')); - $('.edit-label .color-picker').val($(this).data('color')); - $('.edit-label .minicolors-swatch-color').css('background-color', $(this).data('color')); + $('.edit-label .label-desc-input').val(this.getAttribute('data-description')); + $('.edit-label .color-picker').minicolors('value', this.getAttribute('data-color')); $('.edit-label.modal').modal({ onApprove() { diff --git a/web_src/js/features/imagediff.js b/web_src/js/features/imagediff.js index 80b7e83385cc7..293e1f809a799 100644 --- a/web_src/js/features/imagediff.js +++ b/web_src/js/features/imagediff.js @@ -133,24 +133,25 @@ export function initImageDiff() { $container.find('.bounds-info-before .bounds-info-height').text(`${sizes.image2[0].naturalHeight}px`).addClass(heightChanged ? 'red' : ''); } - sizes.image1.css({ - width: sizes.size1.width * factor, - height: sizes.size1.height * factor - }); - sizes.image1.parent().css({ - margin: `10px auto`, - width: sizes.size1.width * factor + 2, - height: sizes.size1.height * factor + 2 - }); - sizes.image2.css({ - width: sizes.size2.width * factor, - height: sizes.size2.height * factor - }); - sizes.image2.parent().css({ - margin: `10px auto`, - width: sizes.size2.width * factor + 2, - height: sizes.size2.height * factor + 2 - }); + const image1 = sizes.image1[0]; + if (image1) { + const container = image1.parentNode; + image1.style.width = `${sizes.size1.width * factor}px`; + image1.style.height = `${sizes.size1.height * factor}px`; + container.style.margin = '10px auto'; + container.style.width = `${sizes.size1.width * factor + 2}px`; + container.style.height = `${sizes.size1.height * factor + 2}px`; + } + + const image2 = sizes.image2[0]; + if (image2) { + const container = image2.parentNode; + image2.style.width = `${sizes.size2.width * factor}px`; + image2.style.height = `${sizes.size2.height * factor}px`; + container.style.margin = '10px auto'; + container.style.width = `${sizes.size2.width * factor + 2}px`; + container.style.height = `${sizes.size2.height * factor + 2}px`; + } } function initSwipe(sizes) { @@ -159,36 +160,39 @@ export function initImageDiff() { factor = (diffContainerWidth - 12) / sizes.max.width; } - sizes.image1.css({ - width: sizes.size1.width * factor, - height: sizes.size1.height * factor - }); - sizes.image1.parent().css({ - margin: `0px ${sizes.ratio[0] * factor}px`, - width: sizes.size1.width * factor + 2, - height: sizes.size1.height * factor + 2 - }); - sizes.image1.parent().parent().css({ - padding: `${sizes.ratio[1] * factor}px 0 0 0`, - width: sizes.max.width * factor + 2 - }); - sizes.image2.css({ - width: sizes.size2.width * factor, - height: sizes.size2.height * factor - }); - sizes.image2.parent().css({ - margin: `${sizes.ratio[3] * factor}px ${sizes.ratio[2] * factor}px`, - width: sizes.size2.width * factor + 2, - height: sizes.size2.height * factor + 2 - }); - sizes.image2.parent().parent().css({ - width: sizes.max.width * factor + 2, - height: sizes.max.height * factor + 2 - }); - $container.find('.diff-swipe').css({ - width: sizes.max.width * factor + 2, - height: sizes.max.height * factor + 30 /* extra height for inner "position: absolute" elements */, - }); + const image1 = sizes.image1[0]; + if (image1) { + const container = image1.parentNode; + const swipeFrame = container.parentNode; + image1.style.width = `${sizes.size1.width * factor}px`; + image1.style.height = `${sizes.size1.height * factor}px`; + container.style.margin = `0px ${sizes.ratio[0] * factor}px`; + container.style.width = `${sizes.size1.width * factor + 2}px`; + container.style.height = `${sizes.size1.height * factor + 2}px`; + swipeFrame.style.padding = `${sizes.ratio[1] * factor}px 0 0 0`; + swipeFrame.style.width = `${sizes.max.width * factor + 2}px`; + } + + const image2 = sizes.image2[0]; + if (image2) { + const container = image2.parentNode; + const swipeFrame = container.parentNode; + image2.style.width = `${sizes.size2.width * factor}px`; + image2.style.height = `${sizes.size2.height * factor}px`; + container.style.margin = `${sizes.ratio[3] * factor}px ${sizes.ratio[2] * factor}px`; + container.style.width = `${sizes.size2.width * factor + 2}px`; + container.style.height = `${sizes.size2.height * factor + 2}px`; + swipeFrame.style.width = `${sizes.max.width * factor + 2}px`; + swipeFrame.style.height = `${sizes.max.height * factor + 2}px`; + } + + // extra height for inner "position: absolute" elements + const swipe = $container.find('.diff-swipe')[0]; + if (swipe) { + swipe.style.width = `${sizes.max.width * factor + 2}px`; + swipe.style.height = `${sizes.max.height * factor + 30}px`; + } + $container.find('.swipe-bar').on('mousedown', function(e) { e.preventDefault(); @@ -200,13 +204,9 @@ export function initImageDiff() { e2.preventDefault(); const value = Math.max(0, Math.min(e2.clientX - $swipeFrame.offset().left, width)); + $swipeBar[0].style.left = `${value}px`; + $container.find('.swipe-container')[0].style.width = `${$swipeFrame.width() - value}px`; - $swipeBar.css({ - left: value - }); - $container.find('.swipe-container').css({ - width: $swipeFrame.width() - value - }); $(document).on('mouseup.diff-swipe', () => { $(document).off('.diff-swipe'); }); diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 96cfa78d0b7a2..5afb407223b0f 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -389,7 +389,7 @@ async function onEditContent(event) { dz.emit('complete', attachment); dz.files.push(attachment); fileUuidDict[attachment.uuid] = {submitted: true}; - $dropzone.find(`img[src='${imgSrc}']`).css('max-width', '100%'); + $dropzone.find(`img[src='${imgSrc}']`)[0].style.maxWidth = '100%'; const $input = $(``).val(attachment.uuid); $dropzone.find('.files').append($input); } diff --git a/web_src/js/features/repo-projects.js b/web_src/js/features/repo-projects.js index 1f86711ab16e0..e95d875ec4e2e 100644 --- a/web_src/js/features/repo-projects.js +++ b/web_src/js/features/repo-projects.js @@ -72,7 +72,7 @@ async function initRepoProjectSortable() { await PUT($(column).data('url'), { data: { sorting: i, - color: rgbToHex($(column).css('backgroundColor')), + color: rgbToHex(window.getComputedStyle($(column)[0]).backgroundColor), }, }); } catch (error) { @@ -111,8 +111,9 @@ export function initRepoProject() { const $projectColorInput = $(this).find('#new_project_column_color'); const $boardColumn = $(this).closest('.project-column'); - if ($boardColumn.css('backgroundColor')) { - setLabelColor($projectHeader, rgbToHex($boardColumn.css('backgroundColor'))); + const bgColor = $boardColumn[0].style.backgroundColor; + if (bgColor) { + setLabelColor($projectHeader, rgbToHex(bgColor)); } $(this).find('.edit-project-column-button').on('click', async function (e) { From 8bf4173e31a4018fb277c871df7d8d31c98dba0b Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Wed, 20 Mar 2024 01:08:42 +0200 Subject: [PATCH 07/34] Switch to the maintained vitest extension (#29914) https://marketplace.visualstudio.com/items?itemName=zixuanchen.vitest-explorer was moved to https://marketplace.visualstudio.com/items?itemName=vitest.explorer Signed-off-by: Yarden Shoham --- .devcontainer/devcontainer.json | 4 ++-- .gitpod.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a4a6ce8fcf608..d391cf78cf7da 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,7 @@ "features": { // installs nodejs into container "ghcr.io/devcontainers/features/node:1": { - "version":"20" + "version": "20" }, "ghcr.io/devcontainers/features/git-lfs:1.1.0": {}, "ghcr.io/devcontainers-contrib/features/poetry:2": {}, @@ -24,7 +24,7 @@ "DavidAnson.vscode-markdownlint", "Vue.volar", "ms-azuretools.vscode-docker", - "zixuanchen.vitest-explorer", + "vitest.explorer", "qwtel.sqlite-viewer", "GitHub.vscode-pull-request-github" ] diff --git a/.gitpod.yml b/.gitpod.yml index ed2f57f4bf6cd..f573d55a767cc 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -42,7 +42,7 @@ vscode: - DavidAnson.vscode-markdownlint - Vue.volar - ms-azuretools.vscode-docker - - zixuanchen.vitest-explorer + - vitest.explorer - qwtel.sqlite-viewer - GitHub.vscode-pull-request-github From 55a8f4510af5ef67e484d45dd3789c29f120d58e Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Wed, 20 Mar 2024 01:39:36 +0200 Subject: [PATCH 08/34] Remove jQuery `.attr` from the issue author dropdown (#29915) - Switched from jQuery `.attr` to plain javascript `.getAttribute` - Tested the issue author dropdown functionality and it works as before Signed-off-by: Yarden Shoham --- web_src/js/features/repo-issue-list.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web_src/js/features/repo-issue-list.js b/web_src/js/features/repo-issue-list.js index 880ecf94892cf..48658fd723ca5 100644 --- a/web_src/js/features/repo-issue-list.js +++ b/web_src/js/features/repo-issue-list.js @@ -93,9 +93,9 @@ function initRepoIssueListAuthorDropdown() { const $searchDropdown = $('.user-remote-search'); if (!$searchDropdown.length) return; - let searchUrl = $searchDropdown.attr('data-search-url'); - const actionJumpUrl = $searchDropdown.attr('data-action-jump-url'); - const selectedUserId = $searchDropdown.attr('data-selected-user-id'); + let searchUrl = $searchDropdown[0].getAttribute('data-search-url'); + const actionJumpUrl = $searchDropdown[0].getAttribute('data-action-jump-url'); + const selectedUserId = $searchDropdown[0].getAttribute('data-selected-user-id'); if (!searchUrl.includes('?')) searchUrl += '?'; $searchDropdown.dropdown('setting', { From 4cfda0241993eabb50ed937dab2ffa7deff3d36e Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Wed, 20 Mar 2024 01:44:21 +0200 Subject: [PATCH 09/34] Remove jQuery `.attr` from the quick pull request button text (#29916) - Switched from jQuery `.attr` to plain javascript `.getAttribute` - Tested the quick pull request button text change functionality and it works as before Signed-off-by: Yarden Shoham --- web_src/js/features/repo-editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/repo-editor.js b/web_src/js/features/repo-editor.js index ba00573c07eec..1ab0a578656cd 100644 --- a/web_src/js/features/repo-editor.js +++ b/web_src/js/features/repo-editor.js @@ -72,7 +72,7 @@ export function initRepoEditor() { hideElem($('.quick-pull-branch-name')); document.querySelector('.quick-pull-branch-name input').required = false; } - $('#commit-button').text($(this).attr('button_text')); + $('#commit-button').text(this.getAttribute('button_text')); }); const joinTreePath = ($fileNameEl) => { From cb98e27992cae7d62e527e922cae3c0f738a7cab Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Wed, 20 Mar 2024 01:49:15 +0200 Subject: [PATCH 10/34] Remove jQuery `.attr` from the image diff (#29917) - Switched from jQuery `.attr` to plain javascript `.setAttribute` - Tested the image diff functionality and it works as before Signed-off-by: Yarden Shoham --- web_src/js/features/imagediff.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/imagediff.js b/web_src/js/features/imagediff.js index 293e1f809a799..2bac13b0bf689 100644 --- a/web_src/js/features/imagediff.js +++ b/web_src/js/features/imagediff.js @@ -70,7 +70,7 @@ export function initImageDiff() { $('.image-diff:not([data-image-diff-loaded])').each(async function() { const $container = $(this); - $container.attr('data-image-diff-loaded', 'true'); + this.setAttribute('data-image-diff-loaded', 'true'); // the container may be hidden by "viewed" checkbox, so use the parent's width for reference const diffContainerWidth = Math.max($container.closest('.diff-file-box').width() - 300, 100); From dd043854ee8963057daa7b835fc700731ae5fb9e Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Wed, 20 Mar 2024 02:04:24 +0200 Subject: [PATCH 11/34] Remove jQuery `.attr` from the archive download and compare page branch selector (#29918) - Switched from jQuery `.attr` to plain javascript `.getAttribute` - Tested the archive download and compare page branch selector functionality and it works as before Signed-off-by: Yarden Shoham --- web_src/js/features/repo-common.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web_src/js/features/repo-common.js b/web_src/js/features/repo-common.js index a8221bbea87e5..9e11ffe19789d 100644 --- a/web_src/js/features/repo-common.js +++ b/web_src/js/features/repo-common.js @@ -34,7 +34,7 @@ async function getArchive($target, url, first) { export function initRepoArchiveLinks() { $('.archive-link').on('click', function (event) { event.preventDefault(); - const url = $(this).attr('href'); + const url = this.getAttribute('href'); if (!url) return; getArchive($(event.target), url, true); }); @@ -80,10 +80,10 @@ export function initRepoCommonFilterSearchDropdown(selector) { fullTextSearch: 'exact', selectOnKeydown: false, onChange(_text, _value, $choice) { - if ($choice.attr('data-url')) { - window.location.href = $choice.attr('data-url'); + if ($choice[0].getAttribute('data-url')) { + window.location.href = $choice[0].getAttribute('data-url'); } }, - message: {noResults: $dropdown.attr('data-no-results')}, + message: {noResults: $dropdown[0].getAttribute('data-no-results')}, }); } From adc61c5d71651acc316bbc3a7fee6f2c0c60b06e Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Wed, 20 Mar 2024 02:09:52 +0200 Subject: [PATCH 12/34] Remove jQuery `.attr` from the user search box (#29919) - Switched from jQuery `.attr` to plain javascript `.getAttribute` - Tested the user search box and it works as before Signed-off-by: Yarden Shoham --- web_src/js/features/comp/SearchUserBox.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/web_src/js/features/comp/SearchUserBox.js b/web_src/js/features/comp/SearchUserBox.js index 992d4ef0206db..541052c174455 100644 --- a/web_src/js/features/comp/SearchUserBox.js +++ b/web_src/js/features/comp/SearchUserBox.js @@ -5,9 +5,12 @@ const {appSubUrl} = window.config; const looksLikeEmailAddressCheck = /^\S+@\S+$/; export function initCompSearchUserBox() { - const $searchUserBox = $('#search-user-box'); - const allowEmailInput = $searchUserBox.attr('data-allow-email') === 'true'; - const allowEmailDescription = $searchUserBox.attr('data-allow-email-description'); + const searchUserBox = document.getElementById('search-user-box'); + if (!searchUserBox) return; + + const $searchUserBox = $(searchUserBox); + const allowEmailInput = searchUserBox.getAttribute('data-allow-email') === 'true'; + const allowEmailDescription = searchUserBox.getAttribute('data-allow-email-description') ?? undefined; $searchUserBox.search({ minCharacters: 2, apiSettings: { From 6ed2c29b1459daa6e7b0cf63b9c08fd9c001ac09 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Wed, 20 Mar 2024 02:38:16 +0200 Subject: [PATCH 13/34] Don't lock using GitHub actions (#29913) We have our bot for this. See: - https://github.com/GiteaBot/gitea-backporter?tab=readme-ov-file#locks - https://github.com/GiteaBot/gitea-backporter/blob/main/src/lock.ts Signed-off-by: Yarden Shoham Co-authored-by: silverwind --- .github/workflows/cron-lock.yml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 .github/workflows/cron-lock.yml diff --git a/.github/workflows/cron-lock.yml b/.github/workflows/cron-lock.yml deleted file mode 100644 index 665313135b679..0000000000000 --- a/.github/workflows/cron-lock.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: cron-lock - -on: - schedule: - - cron: "0 0 * * *" # every day at 00:00 UTC - workflow_dispatch: - -permissions: - issues: write - pull-requests: write - -concurrency: - group: lock - -jobs: - action: - runs-on: ubuntu-latest - if: github.repository == 'go-gitea/gitea' - steps: - - uses: dessant/lock-threads@v5 - with: - issue-inactive-days: 10 - pr-inactive-days: 7 From f371f84fa3456c2a71470632b6458d81e4892a54 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 20 Mar 2024 09:45:27 +0800 Subject: [PATCH 14/34] Restore deleted branches when syncing (#29898) Regression of #29493. If a branch has been deleted, repushing it won't restore it. Lunny may have noticed that, but I didn't delve into the comment then overlooked it: https://github.com/go-gitea/gitea/pull/29493#discussion_r1509046867 The additional comments added are to explain the issue I found during testing, which are unrelated to the fixes. --- routers/private/hook_post_receive.go | 8 +++++--- services/repository/branch.go | 4 ++-- tests/integration/git_push_test.go | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 3dad39f7b1df7..a09956f73865d 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -75,6 +75,10 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { updates = append(updates, option) if repo.IsEmpty && (refFullName.BranchName() == "master" || refFullName.BranchName() == "main") { // put the master/main branch first + // FIXME: It doesn't always work, since the master/main branch may not be the first batch of updates. + // If the user pushes many branches at once, the Git hook will call the internal API in batches, rather than all at once. + // See https://github.com/go-gitea/gitea/blob/cb52b17f92e2d2293f7c003649743464492bca48/cmd/hook.go#L27 + // If the user executes `git push origin --all` and pushes more than 30 branches, the master/main may not be the default branch. copy(updates[1:], updates) updates[0] = option } @@ -129,9 +133,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { commitIDs = append(commitIDs, update.NewCommitID) } - if err := repo_service.SyncBranchesToDB(ctx, repo.ID, opts.UserID, branchNames, commitIDs, func(commitID string) (*git.Commit, error) { - return gitRepo.GetCommit(commitID) - }); err != nil { + if err := repo_service.SyncBranchesToDB(ctx, repo.ID, opts.UserID, branchNames, commitIDs, gitRepo.GetCommit); err != nil { ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{ Err: fmt.Sprintf("Failed to sync branch to DB in repository: %s/%s Error: %v", ownerName, repoName, err), }) diff --git a/services/repository/branch.go b/services/repository/branch.go index 8d8cfa2d19d82..db7acdb5052e6 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -318,11 +318,11 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames, for i, branchName := range branchNames { commitID := commitIDs[i] branch, exist := branchMap[branchName] - if exist && branch.CommitID == commitID { + if exist && branch.CommitID == commitID && !branch.IsDeleted { continue } - commit, err := getCommit(branchName) + commit, err := getCommit(commitID) if err != nil { return fmt.Errorf("get commit of %s failed: %v", branchName, err) } diff --git a/tests/integration/git_push_test.go b/tests/integration/git_push_test.go index cb2910b175e8d..0a357248077ea 100644 --- a/tests/integration/git_push_test.go +++ b/tests/integration/git_push_test.go @@ -69,6 +69,23 @@ func testGitPush(t *testing.T, u *url.URL) { return pushed, deleted }) }) + + t.Run("Push to deleted branch", func(t *testing.T) { + runTestGitPush(t, u, func(t *testing.T, gitPath string) (pushed, deleted []string) { + doGitPushTestRepository(gitPath, "origin", "master")(t) // make sure master is the default branch instead of a branch we are going to delete + pushed = append(pushed, "master") + + doGitCreateBranch(gitPath, "branch-1")(t) + doGitPushTestRepository(gitPath, "origin", "branch-1")(t) + pushed = append(pushed, "branch-1") + + // delete and restore + doGitPushTestRepository(gitPath, "origin", "--delete", "branch-1")(t) + doGitPushTestRepository(gitPath, "origin", "branch-1")(t) + + return pushed, deleted + }) + }) } func runTestGitPush(t *testing.T, u *url.URL, gitOperation func(t *testing.T, gitPath string) (pushed, deleted []string)) { From 02bbdd478706032f3d4948333aa4ea38e33f8e32 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 20 Mar 2024 12:26:19 +0800 Subject: [PATCH 15/34] Fix the wrong default value of ENABLE_OPENID_SIGNIN on docs (#29925) Fix #29923 --- docs/content/administration/config-cheat-sheet.en-us.md | 2 +- docs/content/administration/config-cheat-sheet.zh-cn.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md index 04923acdcb9ab..2309021f94937 100644 --- a/docs/content/administration/config-cheat-sheet.en-us.md +++ b/docs/content/administration/config-cheat-sheet.en-us.md @@ -590,7 +590,7 @@ And the following unique queues: ## OpenID (`openid`) -- `ENABLE_OPENID_SIGNIN`: **false**: Allow authentication in via OpenID. +- `ENABLE_OPENID_SIGNIN`: **true**: Allow authentication in via OpenID. - `ENABLE_OPENID_SIGNUP`: **! DISABLE\_REGISTRATION**: Allow registering via OpenID. - `WHITELISTED_URIS`: **_empty_**: If non-empty, list of POSIX regex patterns matching OpenID URI's to permit. diff --git a/docs/content/administration/config-cheat-sheet.zh-cn.md b/docs/content/administration/config-cheat-sheet.zh-cn.md index 1f98db78aafd8..3115e4cc06453 100644 --- a/docs/content/administration/config-cheat-sheet.zh-cn.md +++ b/docs/content/administration/config-cheat-sheet.zh-cn.md @@ -562,7 +562,7 @@ Gitea 创建以下非唯一队列: ## OpenID (`openid`) -- `ENABLE_OPENID_SIGNIN`: **false**:允许通过OpenID进行身份验证。 +- `ENABLE_OPENID_SIGNIN`: **true**:允许通过OpenID进行身份验证。 - `ENABLE_OPENID_SIGNUP`: **! DISABLE\_REGISTRATION**:允许通过OpenID进行注册。 - `WHITELISTED_URIS`: **_empty_**:如果非空,是一组匹配OpenID URI的POSIX正则表达式模式,用于允许访问。 - `BLACKLISTED_URIS`: **_empty_**:如果非空,是一组匹配OpenID URI的POSIX正则表达式模式,用于阻止访问。 From 35cfd98e121005f90f6d0d55d9a69e37d7990010 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 20 Mar 2024 12:59:01 +0800 Subject: [PATCH 16/34] Show Actions post step when it's running (#29926) The post step was always waiting, even if all steps were done. Then, once the task was done, the post step became success immediately. Before: xnip_240320_120228 After: xnip_240320_120443 --- modules/actions/task_state.go | 14 ++++++++++-- modules/actions/task_state_test.go | 34 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/modules/actions/task_state.go b/modules/actions/task_state.go index fe925bbb5d987..31a74be3fd360 100644 --- a/modules/actions/task_state.go +++ b/modules/actions/task_state.go @@ -41,6 +41,12 @@ func FullSteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep { } logIndex += preStep.LogLength + // lastHasRunStep is the last step that has run. + // For example, + // 1. preStep(Success) -> step1(Success) -> step2(Running) -> step3(Waiting) -> postStep(Waiting): lastHasRunStep is step1. + // 2. preStep(Success) -> step1(Success) -> step2(Success) -> step3(Success) -> postStep(Success): lastHasRunStep is step3. + // 3. preStep(Success) -> step1(Success) -> step2(Failure) -> step3 -> postStep(Waiting): lastHasRunStep is step2. + // So its Stopped is the Started of postStep when there are no more steps to run. var lastHasRunStep *actions_model.ActionTaskStep for _, step := range task.Steps { if step.Status.HasRun() { @@ -56,11 +62,15 @@ func FullSteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep { Name: postStepName, Status: actions_model.StatusWaiting, } - if task.Status.IsDone() { + // If the lastHasRunStep is the last step, or it has failed, postStep has started. + if lastHasRunStep.Status.IsFailure() || lastHasRunStep == task.Steps[len(task.Steps)-1] { postStep.LogIndex = logIndex postStep.LogLength = task.LogLength - postStep.LogIndex - postStep.Status = task.Status postStep.Started = lastHasRunStep.Stopped + postStep.Status = actions_model.StatusRunning + } + if task.Status.IsDone() { + postStep.Status = task.Status postStep.Stopped = task.Stopped } ret := make([]*actions_model.ActionTaskStep, 0, len(task.Steps)+2) diff --git a/modules/actions/task_state_test.go b/modules/actions/task_state_test.go index 3a599fbcbd2b0..28213d781befe 100644 --- a/modules/actions/task_state_test.go +++ b/modules/actions/task_state_test.go @@ -103,6 +103,40 @@ func TestFullSteps(t *testing.T) { {Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100}, }, }, + { + name: "all steps finished but task is running", + task: &actions_model.ActionTask{ + Steps: []*actions_model.ActionTaskStep{ + {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090}, + }, + Status: actions_model.StatusRunning, + Started: 10000, + Stopped: 0, + LogLength: 100, + }, + want: []*actions_model.ActionTaskStep{ + {Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010}, + {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090}, + {Name: postStepName, Status: actions_model.StatusRunning, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 0}, + }, + }, + { + name: "skipped task", + task: &actions_model.ActionTask{ + Steps: []*actions_model.ActionTaskStep{ + {Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, + }, + Status: actions_model.StatusSkipped, + Started: 0, + Stopped: 0, + LogLength: 0, + }, + want: []*actions_model.ActionTaskStep{ + {Name: preStepName, Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, + {Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, + {Name: postStepName, Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 4c476fa41dc29dc24afda0925023ae3d0b9707cd Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 20 Mar 2024 13:56:42 +0800 Subject: [PATCH 17/34] Remove unnecessary ".Link" usages (#29909) In HTML, `?key=val` already means "use the current link with new query parameters" --- templates/admin/emails/list.tmpl | 8 +-- templates/admin/org/list.tmpl | 12 ++-- templates/explore/repo_list.tmpl | 2 +- templates/explore/search.tmpl | 8 +-- templates/projects/list.tmpl | 10 ++-- templates/repo/actions/list.tmpl | 12 ++-- templates/repo/diff/box.tmpl | 6 +- templates/repo/issue/filter_list.tmpl | 58 +++++++++---------- templates/repo/issue/labels/label_list.tmpl | 8 +-- .../repo/issue/milestone/filter_list.tmpl | 12 ++-- templates/repo/view_file.tmpl | 2 +- templates/shared/issuelist.tmpl | 2 +- templates/shared/search/code/results.tmpl | 2 +- templates/user/dashboard/issues.tmpl | 16 ++--- templates/user/dashboard/milestones.tmpl | 14 ++--- .../notification_subscriptions.tmpl | 28 ++++----- templates/user/settings/keys_gpg.tmpl | 2 +- templates/user/settings/keys_ssh.tmpl | 2 +- tests/integration/explore_user_test.go | 12 ++-- 19 files changed, 108 insertions(+), 108 deletions(-) diff --git a/templates/admin/emails/list.tmpl b/templates/admin/emails/list.tmpl index 1e552fba889b8..660df55999ebf 100644 --- a/templates/admin/emails/list.tmpl +++ b/templates/admin/emails/list.tmpl @@ -15,10 +15,10 @@
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index efb0a8847e12e..4609d1b8b4159 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -18,12 +18,12 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}}
diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 17c8bcb6a3c5f..7de3df5bee5c1 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -32,7 +32,7 @@
diff --git a/templates/projects/list.tmpl b/templates/projects/list.tmpl index 414c9dca2ef06..d87e7e0663b32 100644 --- a/templates/projects/list.tmpl +++ b/templates/projects/list.tmpl @@ -1,11 +1,11 @@ {{if and $.CanWriteProjects (not $.Repository.IsArchived)}} diff --git a/templates/repo/actions/list.tmpl b/templates/repo/actions/list.tmpl index 62d30305b3603..55c0494566430 100644 --- a/templates/repo/actions/list.tmpl +++ b/templates/repo/actions/list.tmpl @@ -8,9 +8,9 @@
- + {{ctx.Locale.Tr "actions.runs.status_no_select"}} {{range .StatusInfoList}} - + {{.DisplayedStatus}} {{end}} diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 39df6faea50dc..d2ee5db1b82cd 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -68,7 +68,7 @@ binaryFileMessage: "{{ctx.Locale.Tr "repo.diff.bin"}}", showMoreMessage: "{{ctx.Locale.Tr "repo.diff.show_more"}}", statisticsMessage: "{{ctx.Locale.Tr "repo.diff.stats_desc_file"}}", - linkLoadMore: "{{$.Link}}?skip-to={{.Diff.End}}&file-only=true", + linkLoadMore: "?skip-to={{.Diff.End}}&file-only=true", }; // for first time loading, the diffFileInfo is a plain object @@ -184,7 +184,7 @@ {{ctx.Locale.Tr "repo.diff.file_suppressed_line_too_long"}} {{else}} {{ctx.Locale.Tr "repo.diff.file_suppressed"}} - {{ctx.Locale.Tr "repo.diff.load"}} + {{ctx.Locale.Tr "repo.diff.load"}} {{end}} {{else}} {{ctx.Locale.Tr "repo.diff.bin_not_shown"}} @@ -220,7 +220,7 @@

{{ctx.Locale.Tr "repo.diff.too_many_files"}} - {{ctx.Locale.Tr "repo.diff.show_more"}} + {{ctx.Locale.Tr "repo.diff.show_more"}}

{{end}} diff --git a/templates/repo/issue/filter_list.tmpl b/templates/repo/issue/filter_list.tmpl index bb13f63b9889b..696b7db46b62a 100644 --- a/templates/repo/issue/filter_list.tmpl +++ b/templates/repo/issue/filter_list.tmpl @@ -23,8 +23,8 @@
{{ctx.Locale.Tr "repo.issues.filter_label_exclude"}}
- {{ctx.Locale.Tr "repo.issues.filter_label_no_select"}} - {{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}} + {{ctx.Locale.Tr "repo.issues.filter_label_no_select"}} + {{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}} {{$previousExclusiveScope := "_no_scope"}} {{range .Labels}} {{$exclusiveScope := .ExclusiveScope}} @@ -32,7 +32,7 @@
{{end}} {{$previousExclusiveScope = $exclusiveScope}} - + {{if .IsExcluded}} {{svg "octicon-circle-slash"}} {{else if .IsSelected}} @@ -62,13 +62,13 @@
-
{{ctx.Locale.Tr "repo.issues.filter_milestone_all"}} - {{ctx.Locale.Tr "repo.issues.filter_milestone_none"}} + {{ctx.Locale.Tr "repo.issues.filter_milestone_all"}} + {{ctx.Locale.Tr "repo.issues.filter_milestone_none"}} {{if .OpenMilestones}}
{{ctx.Locale.Tr "repo.issues.filter_milestone_open"}}
{{range .OpenMilestones}} - + {{svg "octicon-milestone" 16 "mr-2"}} {{.Name}} @@ -78,7 +78,7 @@
{{ctx.Locale.Tr "repo.issues.filter_milestone_closed"}}
{{range .ClosedMilestones}} - + {{svg "octicon-milestone" 16 "mr-2"}} {{.Name}} @@ -99,15 +99,15 @@ {{svg "octicon-search" 16}}
- {{ctx.Locale.Tr "repo.issues.filter_project_all"}} - {{ctx.Locale.Tr "repo.issues.filter_project_none"}} + {{ctx.Locale.Tr "repo.issues.filter_project_all"}} + {{ctx.Locale.Tr "repo.issues.filter_project_none"}} {{if .OpenProjects}}
{{ctx.Locale.Tr "repo.issues.new.open_projects"}}
{{range .OpenProjects}} - + {{svg .IconName 18 "gt-mr-3 tw-shrink-0"}}{{.Title}} {{end}} @@ -118,7 +118,7 @@ {{ctx.Locale.Tr "repo.issues.new.closed_projects"}}
{{range .ClosedProjects}} - + {{svg .IconName 18 "gt-mr-3"}}{{.Title}} {{end}} @@ -130,7 +130,7 @@ - {{ctx.Locale.Tr "repo.issues.filter_assginee_no_select"}} - {{ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee"}} + {{ctx.Locale.Tr "repo.issues.filter_assginee_no_select"}} + {{ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee"}}
{{range .Assignees}} - + {{ctx.AvatarUtils.Avatar . 20}}{{template "repo/search_name" .}} {{end}} @@ -175,14 +175,14 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}}
{{end}} @@ -194,13 +194,13 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}}
diff --git a/templates/repo/issue/labels/label_list.tmpl b/templates/repo/issue/labels/label_list.tmpl index ca8d40f1e0c1f..ca28e3af2d0fa 100644 --- a/templates/repo/issue/labels/label_list.tmpl +++ b/templates/repo/issue/labels/label_list.tmpl @@ -9,10 +9,10 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}}
diff --git a/templates/repo/issue/milestone/filter_list.tmpl b/templates/repo/issue/milestone/filter_list.tmpl index 0eea42d6ee61f..45f9866a165b3 100644 --- a/templates/repo/issue/milestone/filter_list.tmpl +++ b/templates/repo/issue/milestone/filter_list.tmpl @@ -5,11 +5,11 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}}
diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index cdd415a47a99b..8c1e7982eb536 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -37,7 +37,7 @@
{{if .HasSourceRenderedToggle}} {{end}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index fb502413fa19e..adb2f61c54a11 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -21,7 +21,7 @@ {{end}} {{range .Labels}} - {{RenderLabel $.Context ctx.Locale .}} + {{RenderLabel $.Context ctx.Locale .}} {{end}}
diff --git a/templates/shared/search/code/results.tmpl b/templates/shared/search/code/results.tmpl index de5ee0c311efe..68b183e9bf430 100644 --- a/templates/shared/search/code/results.tmpl +++ b/templates/shared/search/code/results.tmpl @@ -1,7 +1,7 @@
diff --git a/templates/user/dashboard/milestones.tmpl b/templates/user/dashboard/milestones.tmpl index 7b62c9fc27c23..944043e80624c 100644 --- a/templates/user/dashboard/milestones.tmpl +++ b/templates/user/dashboard/milestones.tmpl @@ -12,7 +12,7 @@
{{range .Repos}} {{with $Repo := .}} - - {{ctx.Locale.Tr "repo.milestones.filter_sort.earliest_due_data"}} - {{ctx.Locale.Tr "repo.milestones.filter_sort.latest_due_date"}} - {{ctx.Locale.Tr "repo.milestones.filter_sort.least_complete"}} - {{ctx.Locale.Tr "repo.milestones.filter_sort.most_complete"}} - {{ctx.Locale.Tr "repo.milestones.filter_sort.most_issues"}} - {{ctx.Locale.Tr "repo.milestones.filter_sort.least_issues"}} + {{ctx.Locale.Tr "repo.milestones.filter_sort.earliest_due_data"}} + {{ctx.Locale.Tr "repo.milestones.filter_sort.latest_due_date"}} + {{ctx.Locale.Tr "repo.milestones.filter_sort.least_complete"}} + {{ctx.Locale.Tr "repo.milestones.filter_sort.most_complete"}} + {{ctx.Locale.Tr "repo.milestones.filter_sort.most_issues"}} + {{ctx.Locale.Tr "repo.milestones.filter_sort.least_issues"}}
diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl index a37f0c352e046..d39e628263b7b 100644 --- a/templates/user/notification/notification_subscriptions.tmpl +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -14,14 +14,14 @@ diff --git a/templates/user/settings/keys_gpg.tmpl b/templates/user/settings/keys_gpg.tmpl index e57658b197338..2f90d0bdad8c4 100644 --- a/templates/user/settings/keys_gpg.tmpl +++ b/templates/user/settings/keys_gpg.tmpl @@ -73,7 +73,7 @@ {{ctx.Locale.Tr "settings.delete_key"}} {{if and (not .Verified) (ne $.VerifyingID .KeyID)}} - {{ctx.Locale.Tr "settings.gpg_key_verify"}} + {{ctx.Locale.Tr "settings.gpg_key_verify"}} {{end}}
diff --git a/templates/user/settings/keys_ssh.tmpl b/templates/user/settings/keys_ssh.tmpl index 94ee2a1a55cda..5577cd0ffd1cc 100644 --- a/templates/user/settings/keys_ssh.tmpl +++ b/templates/user/settings/keys_ssh.tmpl @@ -61,7 +61,7 @@ {{ctx.Locale.Tr "settings.delete_key"}} {{if and (not .Verified) (ne $.VerifyingFingerprint .Fingerprint)}} - {{ctx.Locale.Tr "settings.ssh_key_verify"}} + {{ctx.Locale.Tr "settings.ssh_key_verify"}} {{end}} diff --git a/tests/integration/explore_user_test.go b/tests/integration/explore_user_test.go index 046caf378eff5..441d89cea5416 100644 --- a/tests/integration/explore_user_test.go +++ b/tests/integration/explore_user_test.go @@ -16,17 +16,17 @@ func TestExploreUser(t *testing.T) { defer tests.PrepareTestEnv(t)() cases := []struct{ sortOrder, expected string }{ - {"", "/explore/users?sort=newest&q="}, - {"newest", "/explore/users?sort=newest&q="}, - {"oldest", "/explore/users?sort=oldest&q="}, - {"alphabetically", "/explore/users?sort=alphabetically&q="}, - {"reversealphabetically", "/explore/users?sort=reversealphabetically&q="}, + {"", "?sort=newest&q="}, + {"newest", "?sort=newest&q="}, + {"oldest", "?sort=oldest&q="}, + {"alphabetically", "?sort=alphabetically&q="}, + {"reversealphabetically", "?sort=reversealphabetically&q="}, } for _, c := range cases { req := NewRequest(t, "GET", "/explore/users?sort="+c.sortOrder) resp := MakeRequest(t, req, http.StatusOK) h := NewHTMLParser(t, resp.Body) - href, _ := h.Find(`.ui.dropdown .menu a.active.item[href^="/explore/users"]`).Attr("href") + href, _ := h.Find(`.ui.dropdown .menu a.active.item[href^="?sort="]`).Attr("href") assert.Equal(t, c.expected, href) } From 91699a9bb1fc59029a2605912f1e380eff7297fa Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 20 Mar 2024 14:58:10 +0800 Subject: [PATCH 18/34] Remove unnecessary ".Link" usages (#29929) Follow #29909 --- templates/admin/notice.tmpl | 2 +- templates/admin/stacktrace.tmpl | 4 ++-- templates/repo/wiki/new.tmpl | 2 +- templates/user/auth/reset_passwd.tmpl | 2 +- templates/user/dashboard/issues.tmpl | 16 ++++++++-------- templates/user/dashboard/milestones.tmpl | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/templates/admin/notice.tmpl b/templates/admin/notice.tmpl index e0abe4f8c0639..26462596bc5bb 100644 --- a/templates/admin/notice.tmpl +++ b/templates/admin/notice.tmpl @@ -49,7 +49,7 @@ - diff --git a/templates/admin/stacktrace.tmpl b/templates/admin/stacktrace.tmpl index 42944615c38b8..950aa0ea86a12 100644 --- a/templates/admin/stacktrace.tmpl +++ b/templates/admin/stacktrace.tmpl @@ -4,8 +4,8 @@
diff --git a/templates/repo/wiki/new.tmpl b/templates/repo/wiki/new.tmpl index 640f8ca9cd607..411c7fc869044 100644 --- a/templates/repo/wiki/new.tmpl +++ b/templates/repo/wiki/new.tmpl @@ -9,7 +9,7 @@ {{ctx.Locale.Tr "repo.wiki.new_page_button"}} {{end}}
- + {{.CsrfTokenHtml}}
diff --git a/templates/user/auth/reset_passwd.tmpl b/templates/user/auth/reset_passwd.tmpl index 4d569e206c0e6..f8303feef38d9 100644 --- a/templates/user/auth/reset_passwd.tmpl +++ b/templates/user/auth/reset_passwd.tmpl @@ -51,7 +51,7 @@
{{if and .has_two_factor (not .scratch_code)}} - {{ctx.Locale.Tr "auth.use_scratch_code"}} + {{ctx.Locale.Tr "auth.use_scratch_code"}} {{end}}
{{else}} diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl index c9972f942671b..88afcf58ec273 100644 --- a/templates/user/dashboard/issues.tmpl +++ b/templates/user/dashboard/issues.tmpl @@ -5,29 +5,29 @@