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.

Update issue indexer after merging a PR (#30715)

Fix #30684

(cherry picked from commit f09e68ec33262d5356779572a0b1c66e6e86590f)

Conflicts:
tests/integration/pull_merge_test.go
trivial context conflict

authored by

Zettat123 and committed by
Earl Warren
8f0f6bf8 7d3ca90d

+77
+16
services/indexer/notify.go
··· 152 152 func (r *indexerNotifier) IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { 153 153 issue_indexer.UpdateIssueIndexer(ctx, issue.ID) 154 154 } 155 + 156 + func (r *indexerNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { 157 + if err := pr.LoadIssue(ctx); err != nil { 158 + log.Error("LoadIssue: %v", err) 159 + return 160 + } 161 + issue_indexer.UpdateIssueIndexer(ctx, pr.Issue.ID) 162 + } 163 + 164 + func (r *indexerNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { 165 + if err := pr.LoadIssue(ctx); err != nil { 166 + log.Error("LoadIssue: %v", err) 167 + return 168 + } 169 + issue_indexer.UpdateIssueIndexer(ctx, pr.Issue.ID) 170 + }
+61
tests/integration/pull_merge_test.go
··· 27 27 "code.gitea.io/gitea/modules/git" 28 28 "code.gitea.io/gitea/modules/gitrepo" 29 29 "code.gitea.io/gitea/modules/hostmatcher" 30 + "code.gitea.io/gitea/modules/queue" 30 31 "code.gitea.io/gitea/modules/setting" 31 32 api "code.gitea.io/gitea/modules/structs" 32 33 "code.gitea.io/gitea/modules/test" ··· 600 601 assert.EqualValues(t, "Closed", prStatus) 601 602 }) 602 603 } 604 + 605 + func TestPullMergeIndexerNotifier(t *testing.T) { 606 + onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { 607 + // create a pull request 608 + session := loginUser(t, "user1") 609 + testRepoFork(t, session, "user2", "repo1", "user1", "repo1") 610 + testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") 611 + createPullResp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "Indexer notifier test pull") 612 + 613 + assert.NoError(t, queue.GetManager().FlushAll(context.Background(), 0)) 614 + time.Sleep(time.Second) 615 + 616 + repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ 617 + OwnerName: "user2", 618 + Name: "repo1", 619 + }) 620 + issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ 621 + RepoID: repo1.ID, 622 + Title: "Indexer notifier test pull", 623 + IsPull: true, 624 + IsClosed: false, 625 + }) 626 + 627 + // build the request for searching issues 628 + link, _ := url.Parse("/api/v1/repos/issues/search") 629 + query := url.Values{} 630 + query.Add("state", "closed") 631 + query.Add("type", "pulls") 632 + query.Add("q", "notifier") 633 + link.RawQuery = query.Encode() 634 + 635 + // search issues 636 + searchIssuesResp := session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) 637 + var apiIssuesBefore []*api.Issue 638 + DecodeJSON(t, searchIssuesResp, &apiIssuesBefore) 639 + assert.Len(t, apiIssuesBefore, 0) 640 + 641 + // merge the pull request 642 + elem := strings.Split(test.RedirectURL(createPullResp), "/") 643 + assert.EqualValues(t, "pulls", elem[3]) 644 + testPullMerge(t, session, elem[1], elem[2], elem[4], repo_model.MergeStyleMerge, false) 645 + 646 + // check if the issue is closed 647 + issue = unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ 648 + ID: issue.ID, 649 + }) 650 + assert.True(t, issue.IsClosed) 651 + 652 + assert.NoError(t, queue.GetManager().FlushAll(context.Background(), 0)) 653 + time.Sleep(time.Second) 654 + 655 + // search issues again 656 + searchIssuesResp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) 657 + var apiIssuesAfter []*api.Issue 658 + DecodeJSON(t, searchIssuesResp, &apiIssuesAfter) 659 + if assert.Len(t, apiIssuesAfter, 1) { 660 + assert.Equal(t, issue.ID, apiIssuesAfter[0].ID) 661 + } 662 + }) 663 + }