]> source.dussan.org Git - gitea.git/commitdiff
Fix code owners will not be mentioned when a pull request comes from a forked reposit...
authorLunny Xiao <xiaolunwen@gmail.com>
Mon, 15 Apr 2024 14:11:07 +0000 (22:11 +0800)
committerGitHub <noreply@github.com>
Mon, 15 Apr 2024 14:11:07 +0000 (16:11 +0200)
Fix #30277
Caused by #29783

services/issue/pull.go
tests/integration/pull_create_test.go
tests/integration/pull_review_test.go

index b7b63a70246a83fb9eb4e058be4b3aac5d66abe3..4a0009e82fe8ccb611e9ee8486b0cae6ac337625 100644 (file)
@@ -51,14 +51,14 @@ func PullRequestCodeOwnersReview(ctx context.Context, issue *issues_model.Issue,
                return nil, err
        }
 
-       if pr.HeadRepo.IsFork {
-               return nil, nil
-       }
-
        if err := pr.LoadBaseRepo(ctx); err != nil {
                return nil, err
        }
 
+       if pr.BaseRepo.IsFork {
+               return nil, nil
+       }
+
        repo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
        if err != nil {
                return nil, err
index 029ea65d7190fe265d62ba41507d1aad8bdb2c3f..609bd73fd514cb14e73b25642624c9384d210da2 100644 (file)
@@ -4,6 +4,7 @@
 package integration
 
 import (
+       "fmt"
        "net/http"
        "net/http/httptest"
        "net/url"
@@ -57,6 +58,30 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo string, toSel
        return resp
 }
 
+func testPullCreateDirectly(t *testing.T, session *TestSession, baseRepoOwner, baseRepoName, baseBranch, headRepoOwner, headRepoName, headBranch, title string) *httptest.ResponseRecorder {
+       headCompare := headBranch
+       if headRepoOwner != "" {
+               if headRepoName != "" {
+                       headCompare = fmt.Sprintf("%s/%s:%s", headRepoOwner, headRepoName, headBranch)
+               } else {
+                       headCompare = fmt.Sprintf("%s:%s", headRepoOwner, headBranch)
+               }
+       }
+       req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/compare/%s...%s", baseRepoOwner, baseRepoName, baseBranch, headCompare))
+       resp := session.MakeRequest(t, req, http.StatusOK)
+
+       // Submit the form for creating the pull
+       htmlDoc := NewHTMLParser(t, resp.Body)
+       link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
+       assert.True(t, exists, "The template has changed")
+       req = NewRequestWithValues(t, "POST", link, map[string]string{
+               "_csrf": htmlDoc.GetCSRF(),
+               "title": title,
+       })
+       resp = session.MakeRequest(t, req, http.StatusOK)
+       return resp
+}
+
 func TestPullCreate(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, u *url.URL) {
                session := loginUser(t, "user1")
index 9a5877697c0ba34ff4aed20bec208554cc988ea6..2d8b3cb4ab2e96070f07d38ab44ecc2efd1ae382 100644 (file)
@@ -161,10 +161,18 @@ func TestPullView_CodeOwner(t *testing.T) {
                        assert.NoError(t, err)
 
                        session := loginUser(t, "user5")
-                       testPullCreate(t, session, "user5", "test_codeowner", true, forkedRepo.DefaultBranch, "codeowner-basebranch-forked", "Test Pull Request2")
+
+                       // create a pull request on the forked repository, code reviewers should not be mentioned
+                       testPullCreateDirectly(t, session, "user5", "test_codeowner", forkedRepo.DefaultBranch, "", "", "codeowner-basebranch-forked", "Test Pull Request on Forked Repository")
 
                        pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: forkedRepo.ID, HeadBranch: "codeowner-basebranch-forked"})
                        unittest.AssertExistsIf(t, false, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 8})
+
+                       // create a pull request to base repository, code reviewers should be mentioned
+                       testPullCreateDirectly(t, session, repo.OwnerName, repo.Name, repo.DefaultBranch, forkedRepo.OwnerName, forkedRepo.Name, "codeowner-basebranch-forked", "Test Pull Request3")
+
+                       pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkedRepo.ID, HeadBranch: "codeowner-basebranch-forked"})
+                       unittest.AssertExistsIf(t, true, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 8})
                })
        })
 }