Skip to content

🐛 Code-Review: don't treat a Prow label as approval for self-merged PRs - #5239

Open
askalf wants to merge 3 commits into
ossf:mainfrom
sprayberry-code:fix/code-review-prow-label-self-merge
Open

askalf wants to merge 3 commits into
ossf:mainfrom
sprayberry-code:fix/code-review-prow-label-self-merge

Conversation

@askalf

@askalf askalf commented Sep 14, 2026 •

Copy link
Copy Markdown

Fixes #5206

Summary

  • detectCommitRevisionInfo tests for Prow before GitHub, so any merged pull request carrying a label named lgtm or approved is classified ReviewPlatformProw. Two independent places then discard the GitHub review data that is already in hand.
  • getChangesets (checks/raw/code_review.go:164) only populated Reviews and Author when rev.Platform == checker.ReviewPlatformGitHub, so a Prow-classified changeset carried Reviews: nil, Author: {Login: ""}.
  • codeApproved.approved() (probes/codeApproved/impl.go:119) returned true for ReviewPlatformProw unconditionally, before the review.State == "APPROVED" && review.Author.Login != c.Author.Login loop ever ran.
  • Net effect: a PR opened, labelled approved/lgtm and merged by the same account with zero reviews scores as reviewed; the identical PR without the label is correctly caught by the self-merge comparison. The label removes a check instead of adding information.
  • Fix is 6 source lines: populate Reviews/Author for Prow the same way as for GitHub, and drop ReviewPlatformProw from the short-circuit in approved(). Prow detection and changeset grouping are unchanged; Gerrit/Phabricator/Piper are unchanged.

Tests

One case in Test_getChangesets (a self-merged PR labelled lgtm keeps its author and reviews) and one in TestProbeCodeApproved (a self-merged Prow changeset is not approved). Both fail on main and pass with the fix. gofmt, go vet and go test on the touched packages are clean.

Genuine Prow projects keep their scores. In a Tide merge the merger is the Prow bot, not the author, so the implicit merge approval still counts. Only author == merger with no other approving review changes.

AI assistance: this bug was found and the fix and tests were drafted with AI tooling in my workflow; the tests and checks above were run as described. I'm responsible for the change and will handle review feedback.

@askalf
askalf requested a review from a team as a code owner September 14, 2026 19:59
@askalf
askalf requested review from justaugustus and spencerschrock and removed request for a team September 14, 2026 19:59
@github-actions

Copy link
Copy Markdown

This pull request has been marked stale because it has been open for 10 days with no activity

@github-actions github-actions Bot added the Stale label Sep 25, 2026
@askalf

askalf commented Sep 26, 2026

Copy link
Copy Markdown
Author

Still relevant. The branch is current with main with no conflicts, and DCO and CI are green at the current head. Ready for review whenever a maintainer has a moment.

@github-actions github-actions Bot removed the Stale label Sep 26, 2026
@askalf
askalf force-pushed the fix/code-review-prow-label-self-merge branch from e78ccd9 to ee8b468 Compare September 29, 2026 11:47
detectCommitRevisionInfo checks for Prow before GitHub, so any merged pull
request carrying an "lgtm" or "approved" label is classified as
ReviewPlatformProw. getChangesets then only copied Reviews and Author for
GitHub changesets, and codeApproved.approved() returned true for Prow before
the review loop ran. A pull request opened, labelled and merged by the same
account with no reviews therefore scored as reviewed, while the same pull
request without the label was correctly caught by the reviewer != author
comparison.

Prow changesets are detected from the labels of a merged GitHub pull request,
so the review data is already in hand. Populate Reviews and Author for them the
same way as for GitHub, and let approved() run the existing comparison. Tide
merges keep passing through the implicit MergedBy review when the merger is not
the author. Gerrit, Phabricator and Piper are detected from commit messages with
no review data attached and keep their existing behaviour.

Fixes ossf#5206

Signed-off-by: askalf <263217947+askalf@users.noreply.github.com>
Adversarial verification of the prow self-merge fix rebuilt the boundary
ledger from the diff and found reachable rows with no test behind them.

checks/raw: the approved label (the second prow trigger alongside lgtm),
an unsquashed prow merge and the reverse commit order for it, a prow
changeset carrying an explicit review next to the implicit MergedBy one,
a mixed prow + GitHub commit list, and an unknown-platform commit.

probes/codeApproved: a prow changeset with no review data, one reviewed
without an approval, and a bot-authored one, plus the gerrit, phabricator
and piper arms of the switch the fix left in place.

Two cases pass on the base commit by construction and are named controls:
the piper changeset, which never reaches the changed predicate, and a
labelled but unmerged pull request, which is not classified as prow.

Signed-off-by: askalf <263217947+askalf@users.noreply.github.com>
One case pins that a self-merged Prow changeset keeps its author and reviews, and one that it is not approved. Both fail without the fix.

Signed-off-by: askalf <263217947+askalf@users.noreply.github.com>
@askalf
askalf force-pushed the fix/code-review-prow-label-self-merge branch from 90c0686 to 9f4c627 Compare October 19, 2026 13:03

This branch had an error being deployed

2 failed deployments
integration-test — 9f4c627c Deployed Oct 19, 2026 by askalf via integration-trusted #12818
gitlab — 9f4c627c Deployed Oct 19, 2026 by askalf via gitlab-integration-trusted #5494
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

BUG: Code-Review treats any merged PR with an approved/lgtm label as reviewed, ignoring the PR's actual reviews

1 participant