mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-15 05:30:59 +00:00
fix(pull): re-evaluate review official flag on target branch change (#38319)
The `official` flag of a pull request review is computed against the target branch's protection rules at submit time and stored on the review record. `ChangeTargetBranch` updated the base branch but never re-evaluated it, so an `official` approval obtained against an unprotected branch could be retargeted onto a protected branch and satisfy its required approvals, bypassing the branch protection. This re-evaluates the `official` flag of the latest approve/reject reviews against the new base branch whenever the target branch changes.
This commit is contained in:
@@ -326,6 +326,14 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
||||
return fmt.Errorf("syncCommitDivergence: %w", err)
|
||||
}
|
||||
|
||||
// The "official" flag of existing reviews was computed against the previous
|
||||
// target branch's protection rules, so re-evaluate it against the new branch.
|
||||
// Otherwise a stale official approval could bypass the new branch's protection.
|
||||
pr.Issue.PullRequest = pr
|
||||
if err := issues_model.RecalculateReviewsOfficial(ctx, pr.Issue); err != nil {
|
||||
return fmt.Errorf("RecalculateReviewsOfficial: %w", err)
|
||||
}
|
||||
|
||||
// Create comment
|
||||
options := &issues_model.CreateCommentOptions{
|
||||
Type: issues_model.CommentTypeChangeTargetBranch,
|
||||
|
||||
Reference in New Issue
Block a user