Skip to content

Commit

Permalink
[PORT] Fix code owners will not be mentioned when a pull request come…
Browse files Browse the repository at this point in the history
…s from a forked repository (gitea#30476)

Fix go-gitea#30277
Caused by go-gitea#29783

---

- Resolves go-gitea#5842
- Regression from go-gitea#2855

(cherry picked from commit c63060b)
(cherry picked from commit 2efc1f5)
  • Loading branch information
lunny authored and forgejo-backport-action committed Nov 9, 2024
1 parent 9a7b0c3 commit 770fa89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions services/issue/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions tests/integration/pull_review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,18 @@ func TestPullView_CodeOwner(t *testing.T) {
require.NoError(t, err)

session := loginUser(t, "user5")
testPullCreate(t, session, "user5", "test_codeowner_fork", false, forkedRepo.DefaultBranch, "codeowner-basebranch-forked", "Test Pull Request2")

pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadBranch: "codeowner-basebranch-forked"})
// create a pull request on the forked repository, code reviewers should not be mentioned
testPullCreateDirectly(t, session, "user5", "test_codeowner_fork", 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})
})
})
}
Expand Down

0 comments on commit 770fa89

Please sign in to comment.