loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'Fix conversation template' (#4691) from 0ko/forgejo:ui-roles-reviews into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4691
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>

+88 -34
+1 -1
templates/repo/issue/view_content/conversation.tmpl
··· 77 77 </span> 78 78 </div> 79 79 <div class="comment-header-right actions tw-flex tw-items-center"> 80 - {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole "IsPull" .Issue.IsPull}} 80 + {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole "IsPull" $.Issue.IsPull}} 81 81 {{if not $.Repository.IsArchived}} 82 82 {{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}} 83 83 {{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" true "issue" true "diff" true "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
+87 -33
tests/integration/issues_comment_labels_test.go
··· 15 15 ) 16 16 17 17 // TestIssuesCommentLabels is a test for user (role) labels in comment headers in PRs and issues. 18 - // It covers a few labels and combinations. 19 18 func TestIssuesCommentLabels(t *testing.T) { 19 + user := "user2" 20 + repo := "repo1" 21 + 22 + ownerTooltip := "This user is the owner of this repository." 23 + authorTooltipPR := "This user is the author of this pull request." 24 + authorTooltipIssue := "This user is the author of this issue." 25 + contributorTooltip := "This user has previously committed in this repository." 26 + newContributorTooltip := "This is the first contribution of this user to the repository." 27 + 28 + // Test pulls 20 29 onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { 21 - user := "user2" 22 - repo := "repo1" 23 - compareLink := path.Join(user, repo, "compare", "master...comment-labels") 24 30 sessionUser1 := loginUser(t, "user1") 25 31 sessionUser2 := loginUser(t, "user2") 26 - sessionUser5 := loginUser(t, "user5") 27 - 28 - ownerTooltip := "This user is the owner of this repository." 29 - authorTooltipPR := "This user is the author of this pull request." 30 - authorTooltipIssue := "This user is the author of this issue." 31 - firstTooltip := "This is the first contribution of this user to the repository." 32 + sessionUser11 := loginUser(t, "user11") 32 33 33 34 // Open a new PR as user2 34 - testEditFileToNewBranch(t, sessionUser2, user, repo, "master", "comment-labels", "README.md", "test of comment labels") 35 - sessionUser2.MakeRequest(t, NewRequestWithValues(t, "POST", compareLink, 35 + testEditFileToNewBranch(t, sessionUser2, user, repo, "master", "comment-labels", "README.md", "test of comment labels\naline") 36 + sessionUser2.MakeRequest(t, NewRequestWithValues(t, "POST", path.Join(user, repo, "compare", "master...comment-labels"), 36 37 map[string]string{ 37 - "_csrf": GetCSRF(t, sessionUser2, compareLink), 38 + "_csrf": GetCSRF(t, sessionUser2, path.Join(user, repo, "compare", "master...comment-labels")), 38 39 "title": "Pull used for testing commit labels", 39 40 }, 40 41 ), http.StatusOK) 41 42 42 43 // Pull number, expected to be 6 43 44 testID := "6" 45 + 44 46 // Add a few comments 45 47 // (first: Owner) 46 - testEasyLeavePRComment(t, sessionUser2, user, repo, testID, "New comment from user2 on this PR") // Author, Owner 47 - testEasyLeavePRComment(t, sessionUser1, user, repo, testID, "New comment from user1 on this PR") // First-time contributor 48 - testEasyLeavePRComment(t, sessionUser5, user, repo, testID, "New comment from user5 on this PR") // no labels 48 + testEasyLeavePRReviewComment(t, sessionUser2, user, repo, testID, "README.md", "1", "New review comment from user2 on this line", "") 49 49 50 - // Fetch the PR page 50 + // Have to fetch reply ID for reviews 51 51 response := sessionUser2.MakeRequest(t, NewRequest(t, "GET", path.Join(user, repo, "pulls", testID)), http.StatusOK) 52 52 page := NewHTMLParser(t, response.Body) 53 + replyID, _ := page.Find(".comment-form input[name='reply']").Attr("value") 54 + 55 + testEasyLeavePRReviewComment(t, sessionUser2, user, repo, testID, "README.md", "1", "Another review comment from user2 on this line", replyID) 56 + testEasyLeavePRComment(t, sessionUser2, user, repo, testID, "New comment from user2 on this PR") // Author, Owner 57 + testEasyLeavePRComment(t, sessionUser1, user, repo, testID, "New comment from user1 on this PR") // Contributor 58 + testEasyLeavePRComment(t, sessionUser11, user, repo, testID, "New comment from user11 on this PR") // First-time contributor 59 + 60 + // Fetch the PR page 61 + response = sessionUser2.MakeRequest(t, NewRequest(t, "GET", path.Join(user, repo, "pulls", testID)), http.StatusOK) 62 + page = NewHTMLParser(t, response.Body) 53 63 commentHeads := page.Find(".timeline .comment .comment-header .comment-header-right") 54 - assert.EqualValues(t, 4, commentHeads.Length()) 64 + assert.EqualValues(t, 6, commentHeads.Length()) 55 65 56 66 // Test the first comment and it's label "Owner" 57 67 labels := commentHeads.Eq(0).Find(".role-label") 58 68 assert.EqualValues(t, 1, labels.Length()) 59 69 testIssueCommentUserLabel(t, labels.Eq(0), "Owner", ownerTooltip) 60 70 61 - // Test the second comment and it's labels "Author" and "Owner" 71 + // Test the second (review) comment and it's labels "Author" and "Owner" 62 72 labels = commentHeads.Eq(1).Find(".role-label") 63 73 assert.EqualValues(t, 2, labels.Length()) 64 74 testIssueCommentUserLabel(t, labels.Eq(0), "Author", authorTooltipPR) 65 75 testIssueCommentUserLabel(t, labels.Eq(1), "Owner", ownerTooltip) 66 76 67 - // Test the third comment and it's label "First-time contributor" 77 + // Test the third (review) comment and it's labels "Author" and "Owner" 78 + labels = commentHeads.Eq(2).Find(".role-label") 79 + assert.EqualValues(t, 2, labels.Length()) 80 + testIssueCommentUserLabel(t, labels.Eq(0), "Author", authorTooltipPR) 81 + testIssueCommentUserLabel(t, labels.Eq(1), "Owner", ownerTooltip) 82 + 83 + // Test the fourth comment and it's labels "Author" and "Owner" 68 84 labels = commentHeads.Eq(3).Find(".role-label") 69 - assert.EqualValues(t, 1, labels.Length()) 70 - testIssueCommentUserLabel(t, labels.Eq(0), "First-time contributor", firstTooltip) 85 + assert.EqualValues(t, 2, labels.Length()) 86 + testIssueCommentUserLabel(t, labels.Eq(0), "Author", authorTooltipPR) 87 + testIssueCommentUserLabel(t, labels.Eq(1), "Owner", ownerTooltip) 71 88 72 - // Test the fourth comment and it's lack of labels 89 + // Test the fivth comment and it's label "Contributor" 73 90 labels = commentHeads.Eq(4).Find(".role-label") 74 - assert.EqualValues(t, 0, labels.Length()) 91 + assert.EqualValues(t, 1, labels.Length()) 92 + testIssueCommentUserLabel(t, labels.Eq(0), "Contributor", contributorTooltip) 93 + 94 + // Test the sixth comment and it's label "First-time contributor" 95 + labels = commentHeads.Eq(5).Find(".role-label") 96 + assert.EqualValues(t, 1, labels.Length()) 97 + testIssueCommentUserLabel(t, labels.Eq(0), "First-time contributor", newContributorTooltip) 98 + }) 99 + 100 + // Test issues 101 + onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { 102 + sessionUser1 := loginUser(t, "user1") 103 + sessionUser2 := loginUser(t, "user2") 104 + sessionUser5 := loginUser(t, "user5") 75 105 76 106 // Open a new issue in the same repo 77 107 sessionUser2.MakeRequest(t, NewRequestWithValues(t, "POST", path.Join(user, repo, "issues/new"), 78 108 map[string]string{ 79 - "_csrf": GetCSRF(t, sessionUser2, compareLink), 109 + "_csrf": GetCSRF(t, sessionUser2, path.Join(user, repo)), 80 110 "title": "Issue used for testing commit labels", 81 111 }, 82 112 ), http.StatusOK) 83 113 84 - // Issue number, expected to be 7 after the PR 85 - testID = "7" 114 + // Issue number, expected to be 6 115 + testID := "6" 86 116 // Add a few comments 87 117 // (first: Owner) 88 118 testEasyLeaveIssueComment(t, sessionUser2, user, repo, testID, "New comment from user2 on this issue") // Author, Owner 119 + testEasyLeaveIssueComment(t, sessionUser1, user, repo, testID, "New comment from user1 on this issue") // Contributor 89 120 testEasyLeaveIssueComment(t, sessionUser5, user, repo, testID, "New comment from user5 on this issue") // no labels 90 121 91 122 // Fetch the issue page 92 - response = sessionUser2.MakeRequest(t, NewRequest(t, "GET", path.Join(user, repo, "issues", testID)), http.StatusOK) 93 - page = NewHTMLParser(t, response.Body) 94 - commentHeads = page.Find(".timeline .comment .comment-header .comment-header-right") 95 - assert.EqualValues(t, 3, commentHeads.Length()) 123 + response := sessionUser2.MakeRequest(t, NewRequest(t, "GET", path.Join(user, repo, "issues", testID)), http.StatusOK) 124 + page := NewHTMLParser(t, response.Body) 125 + commentHeads := page.Find(".timeline .comment .comment-header .comment-header-right") 126 + assert.EqualValues(t, 4, commentHeads.Length()) 96 127 97 128 // Test the first comment and it's label "Owner" 98 - labels = commentHeads.Eq(0).Find(".role-label") 129 + labels := commentHeads.Eq(0).Find(".role-label") 99 130 assert.EqualValues(t, 1, labels.Length()) 100 131 testIssueCommentUserLabel(t, labels.Eq(0), "Owner", ownerTooltip) 101 132 ··· 105 136 testIssueCommentUserLabel(t, labels.Eq(0), "Author", authorTooltipIssue) 106 137 testIssueCommentUserLabel(t, labels.Eq(1), "Owner", ownerTooltip) 107 138 108 - // Test the third comment and it's lack of labels 139 + // Test the third comment and it's label "Contributor" 140 + labels = commentHeads.Eq(2).Find(".role-label") 141 + assert.EqualValues(t, 1, labels.Length()) 142 + testIssueCommentUserLabel(t, labels.Eq(0), "Contributor", contributorTooltip) 143 + 144 + // Test the fifth comment and it's lack of labels 109 145 labels = commentHeads.Eq(3).Find(".role-label") 110 146 assert.EqualValues(t, 0, labels.Length()) 111 147 }) ··· 141 177 "status": "", 142 178 }), 200) 143 179 } 180 + 181 + // testEasyLeavePRReviewComment is used to add review comments to specific lines of changed files in the diff of the PR. 182 + func testEasyLeavePRReviewComment(t *testing.T, session *TestSession, user, repo, id, file, line, message, replyID string) { 183 + t.Helper() 184 + values := map[string]string{ 185 + "_csrf": GetCSRF(t, session, path.Join(user, repo, "pulls", id, "files")), 186 + "origin": "diff", 187 + "side": "proposed", 188 + "line": line, 189 + "path": file, 190 + "content": message, 191 + "single_review": "true", 192 + } 193 + if len(replyID) > 0 { 194 + values["reply"] = replyID 195 + } 196 + session.MakeRequest(t, NewRequestWithValues(t, "POST", path.Join(user, repo, "pulls", id, "files/reviews/comments"), values), http.StatusOK) 197 + }