Skip to content

Commit 60181eb

Browse files
authored
Fix code owners will not be mentioned when a pull request comes from a forked repository (#30476) (#30497)
Backport #30476 Fix #30277 Caused by #29783
1 parent a0ca311 commit 60181eb

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

services/issue/pull.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ func PullRequestCodeOwnersReview(ctx context.Context, issue *issues_model.Issue,
5050
return nil, err
5151
}
5252

53-
if pr.HeadRepo.IsFork {
54-
return nil, nil
55-
}
56-
5753
if err := pr.LoadBaseRepo(ctx); err != nil {
5854
return nil, err
5955
}
6056

57+
if pr.BaseRepo.IsFork {
58+
return nil, nil
59+
}
60+
6161
repo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
6262
if err != nil {
6363
return nil, err

tests/integration/pull_create_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch, titl
6262
return resp
6363
}
6464

65+
func testPullCreateDirectly(t *testing.T, session *TestSession, baseRepoOwner, baseRepoName, baseBranch, headRepoOwner, headRepoName, headBranch, title string) *httptest.ResponseRecorder {
66+
headCompare := headBranch
67+
if headRepoOwner != "" {
68+
if headRepoName != "" {
69+
headCompare = fmt.Sprintf("%s/%s:%s", headRepoOwner, headRepoName, headBranch)
70+
} else {
71+
headCompare = fmt.Sprintf("%s:%s", headRepoOwner, headBranch)
72+
}
73+
}
74+
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/compare/%s...%s", baseRepoOwner, baseRepoName, baseBranch, headCompare))
75+
resp := session.MakeRequest(t, req, http.StatusOK)
76+
77+
// Submit the form for creating the pull
78+
htmlDoc := NewHTMLParser(t, resp.Body)
79+
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
80+
assert.True(t, exists, "The template has changed")
81+
req = NewRequestWithValues(t, "POST", link, map[string]string{
82+
"_csrf": htmlDoc.GetCSRF(),
83+
"title": title,
84+
})
85+
resp = session.MakeRequest(t, req, http.StatusOK)
86+
return resp
87+
}
88+
6589
func TestPullCreate(t *testing.T) {
6690
onGiteaRun(t, func(t *testing.T, u *url.URL) {
6791
session := loginUser(t, "user1")

tests/integration/pull_review_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,18 @@ func TestPullView_CodeOwner(t *testing.T) {
159159
assert.NoError(t, err)
160160

161161
session := loginUser(t, "user5")
162-
createPullRequest(t, session, "user5", "test_codeowner", forkedRepo.DefaultBranch, "codeowner-basebranch-forked", "Test Pull Request2")
162+
163+
// create a pull request on the forked repository, code reviewers should not be mentioned
164+
testPullCreateDirectly(t, session, "user5", "test_codeowner", forkedRepo.DefaultBranch, "", "", "codeowner-basebranch-forked", "Test Pull Request on Forked Repository")
163165

164166
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: forkedRepo.ID, HeadBranch: "codeowner-basebranch-forked"})
165167
unittest.AssertExistsIf(t, false, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 8})
168+
169+
// create a pull request to base repository, code reviewers should be mentioned
170+
testPullCreateDirectly(t, session, repo.OwnerName, repo.Name, repo.DefaultBranch, forkedRepo.OwnerName, forkedRepo.Name, "codeowner-basebranch-forked", "Test Pull Request3")
171+
172+
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkedRepo.ID, HeadBranch: "codeowner-basebranch-forked"})
173+
unittest.AssertExistsIf(t, true, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 8})
166174
})
167175
})
168176
}

0 commit comments

Comments
 (0)