diff options
author | Gusted <postmaster@gusted.xyz> | 2024-02-27 22:12:20 +0100 |
---|---|---|
committer | Gusted <postmaster@gusted.xyz> | 2024-02-27 23:16:00 +0100 |
commit | fb2795b5bb3a119f022b59a7b46af47eff94270f (patch) | |
tree | d95bd99ca3325ee97549567df41392652ef60b81 /models | |
parent | Merge pull request 'Fix the Fork button in repo headers' (#2495) from algerno... (diff) | |
download | forgejo-fb2795b5bb3a119f022b59a7b46af47eff94270f.tar.xz forgejo-fb2795b5bb3a119f022b59a7b46af47eff94270f.zip |
[BUG] Correct changed files for codeowners
- The CODEOWNER feature relies on the changed files to determine which
reviewers should be added according to the `CODEOWNER` file.
- The current approach was to 'diff' between the base and head branch,
which seems logical but fail in practice when the pull request is out of
date with the base branch. Therefore it should instead diff between the
head branch and the merge base of the head and base branch, so only the
actual affected files by the pull requests are used, the same approach
is used by the diff of an unmerged pull request.
- Add integration testing (for the feature as well).
- Resolves #2458
Diffstat (limited to 'models')
-rw-r--r-- | models/issues/pull.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/models/issues/pull.go b/models/issues/pull.go index 7d299eac27..98d1617380 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -922,7 +922,14 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *Issue, pr *PullReque } rules, _ := GetCodeOwnersFromContent(ctx, data) - changedFiles, err := repo.GetFilesChangedBetween(git.BranchPrefix+pr.BaseBranch, pr.GetGitRefName()) + + prInfo, err := repo.GetCompareInfo(repo.Path, git.BranchPrefix+pr.BaseBranch, pr.GetGitRefName(), false, false) + if err != nil { + return err + } + // Use the merge base as the base instead of the main branch to avoid problems + // if the pull request is out of date with the base branch. + changedFiles, err := repo.GetFilesChangedBetween(prInfo.MergeBase, pr.HeadCommitID) if err != nil { return err } |