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 'Don't notify when a user self-request as reviewer' (#6287) from gabrielgio/forgejo:bug/5567_irrelevant_notification into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6287
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>

0ko bb88e1da 1e7b922e

+100 -1
+2 -1
services/issue/assignee.go
··· 72 72 return nil, err 73 73 } 74 74 75 - if comment != nil { 75 + // don't notify if the user is requesting itself as reviewer 76 + if comment != nil && doer.ID != reviewer.ID { 76 77 notify_service.PullRequestReviewRequest(ctx, doer, issue, reviewer, isAdd, comment) 77 78 } 78 79
+98
tests/integration/pull_review_test.go
··· 5 5 6 6 import ( 7 7 "context" 8 + "fmt" 8 9 "net/http" 9 10 "net/http/httptest" 10 11 "net/url" ··· 19 20 "code.gitea.io/gitea/models/unittest" 20 21 user_model "code.gitea.io/gitea/models/user" 21 22 "code.gitea.io/gitea/modules/gitrepo" 23 + repo_module "code.gitea.io/gitea/modules/repository" 22 24 "code.gitea.io/gitea/modules/test" 23 25 issue_service "code.gitea.io/gitea/services/issue" 24 26 repo_service "code.gitea.io/gitea/services/repository" ··· 60 62 id, err := strconv.ParseInt(commentID, 10, 64) 61 63 require.NoError(t, err) 62 64 return unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: id}) 65 + } 66 + 67 + func TestPullView_SelfReviewNotification(t *testing.T) { 68 + onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { 69 + user1Session := loginUser(t, "user1") 70 + user2Session := loginUser(t, "user2") 71 + 72 + user1csrf := GetCSRF(t, user1Session, "/") 73 + oldUser1NotificationCount := getUserNotificationCount(t, user1Session, user1csrf) 74 + 75 + user2csrf := GetCSRF(t, user2Session, "/") 76 + oldUser2NotificationCount := getUserNotificationCount(t, user2Session, user2csrf) 77 + 78 + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) 79 + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 80 + 81 + repo, _, f := tests.CreateDeclarativeRepo(t, user2, "test_reviewer", nil, nil, []*files_service.ChangeRepoFile{ 82 + { 83 + Operation: "create", 84 + TreePath: "CODEOWNERS", 85 + ContentReader: strings.NewReader("README.md @user5\n"), 86 + }, 87 + }) 88 + defer f() 89 + 90 + // we need to add user1 as collaborator so it can be added as reviewer 91 + err := repo_module.AddCollaborator(db.DefaultContext, repo, user1) 92 + require.NoError(t, err) 93 + 94 + // create a new branch to prepare for pull request 95 + _, err = files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ 96 + NewBranch: "codeowner-basebranch", 97 + Files: []*files_service.ChangeRepoFile{ 98 + { 99 + Operation: "update", 100 + TreePath: "README.md", 101 + ContentReader: strings.NewReader("# This is a new project\n"), 102 + }, 103 + }, 104 + }) 105 + require.NoError(t, err) 106 + 107 + // Create a pull request. 108 + resp := testPullCreate(t, user2Session, "user2", "test_reviewer", false, repo.DefaultBranch, "codeowner-basebranch", "Test Pull Request") 109 + prURL := test.RedirectURL(resp) 110 + elem := strings.Split(prURL, "/") 111 + assert.EqualValues(t, "pulls", elem[3]) 112 + 113 + req := NewRequest(t, http.MethodGet, prURL) 114 + resp = MakeRequest(t, req, http.StatusOK) 115 + doc := NewHTMLParser(t, resp.Body) 116 + attributeFilter := fmt.Sprintf("[data-update-url='/%s/%s/issues/request_review']", user2.Name, repo.Name) 117 + issueID, ok := doc.Find(attributeFilter).Attr("data-issue-id") 118 + assert.True(t, ok, "doc must contain data-issue-id") 119 + 120 + user1csrf = GetCSRF(t, user1Session, "/") 121 + testAssignReviewer(t, user1Session, user1csrf, user2.Name, repo.Name, issueID, "1", http.StatusOK) 122 + 123 + // both user notification should keep the same notification count since 124 + // user2 added itself as reviewer. 125 + user1csrf = GetCSRF(t, user1Session, "/") 126 + notificationCount := getUserNotificationCount(t, user1Session, user1csrf) 127 + assert.Equal(t, oldUser1NotificationCount, notificationCount) 128 + 129 + user2csrf = GetCSRF(t, user2Session, "/") 130 + notificationCount = getUserNotificationCount(t, user2Session, user2csrf) 131 + assert.Equal(t, oldUser2NotificationCount, notificationCount) 132 + }) 63 133 } 64 134 65 135 func TestPullView_ResolveInvalidatedReviewComment(t *testing.T) { ··· 474 544 }) 475 545 } 476 546 547 + func testNofiticationCount(t *testing.T, session *TestSession, csrf string, expectedSubmitStatus int) *httptest.ResponseRecorder { 548 + options := map[string]string{ 549 + "_csrf": csrf, 550 + } 551 + 552 + req := NewRequestWithValues(t, "GET", "/", options) 553 + return session.MakeRequest(t, req, expectedSubmitStatus) 554 + } 555 + 556 + func testAssignReviewer(t *testing.T, session *TestSession, csrf, owner, repo, pullID, reviewer string, expectedSubmitStatus int) *httptest.ResponseRecorder { 557 + options := map[string]string{ 558 + "_csrf": csrf, 559 + "action": "attach", 560 + "issue_ids": pullID, 561 + "id": reviewer, 562 + } 563 + 564 + submitURL := path.Join(owner, repo, "issues", "request_review") 565 + req := NewRequestWithValues(t, "POST", submitURL, options) 566 + return session.MakeRequest(t, req, expectedSubmitStatus) 567 + } 568 + 477 569 func testSubmitReview(t *testing.T, session *TestSession, csrf, owner, repo, pullNumber, commitID, reviewType string, expectedSubmitStatus int) *httptest.ResponseRecorder { 478 570 options := map[string]string{ 479 571 "_csrf": csrf, ··· 502 594 req = NewRequestWithValues(t, "POST", closeURL, options) 503 595 return session.MakeRequest(t, req, http.StatusOK) 504 596 } 597 + 598 + func getUserNotificationCount(t *testing.T, session *TestSession, csrf string) string { 599 + resp := testNofiticationCount(t, session, csrf, http.StatusOK) 600 + doc := NewHTMLParser(t, resp.Body) 601 + return doc.Find(`.notification_count`).Text() 602 + }