Skip to content

Commit 3d31b59

Browse files
GiteaBotlunny
andauthored
Fix code owners will not be mentioned when a pull request comes from a forked repository (#30476) (#30496)
Backport #30476 by @lunny Fix #30277 Caused by #29783 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent 7ffc0ac commit 3d31b59

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

services/issue/pull.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ func PullRequestCodeOwnersReview(ctx context.Context, issue *issues_model.Issue,
5151
return nil, err
5252
}
5353

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

58+
if pr.BaseRepo.IsFork {
59+
return nil, nil
60+
}
61+
6262
repo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
6363
if err != nil {
6464
return nil, err

tests/integration/pull_create_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package integration
55

66
import (
7+
"fmt"
78
"net/http"
89
"net/http/httptest"
910
"net/url"
@@ -57,6 +58,30 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo string, toSel
5758
return resp
5859
}
5960

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

tests/integration/pull_review_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,18 @@ func TestPullView_CodeOwner(t *testing.T) {
161161
assert.NoError(t, err)
162162

163163
session := loginUser(t, "user5")
164-
testPullCreate(t, session, "user5", "test_codeowner", true, forkedRepo.DefaultBranch, "codeowner-basebranch-forked", "Test Pull Request2")
164+
165+
// create a pull request on the forked repository, code reviewers should not be mentioned
166+
testPullCreateDirectly(t, session, "user5", "test_codeowner", forkedRepo.DefaultBranch, "", "", "codeowner-basebranch-forked", "Test Pull Request on Forked Repository")
165167

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

0 commit comments

Comments
 (0)