Description
Problem
codeowners-plus is meant to judge each reviewer by their most recent review. If a reviewer approves a pull request and later requests changes, it still counts the approval, and the codeowners check passes.
Seen with v1.1.0. A code owner approved a pull request, then submitted a "Request changes" review on the same commit. The re-run check logged:
Current Approvals: [{GHLogin:<reviewer> ReviewID:<the earlier approval> … }]
Remaining Required Owners: []
Codeowners reviews satisfied
The reviewer's latest review was CHANGES_REQUESTED, so their approval should no longer have counted, and the check should have failed.
Cause
approvals() in internal/github/gh.go walks the reviews newest first and keeps each reviewer's most recent review, but it only marks a reviewer as seen when that review is APPROVED:
if _, ok := seen[userName]; ok {
// we only care about the most recent reviews for each user
return false
} else if approval.GetState() == "APPROVED" {
seen[userName] = true
}
return approval.GetState() == "APPROVED"A newer review in any other state is skipped without marking the reviewer as seen. The walk then reaches the reviewer's older approval and counts it. Two cases are affected:
CHANGES_REQUESTEDafter an approval: the approval counts.DISMISSEDafter an approval: if the reviewer approved more than once, dismissing the newest approval leaves an older one counted. The dismissed review's state isDISMISSED, notAPPROVED, so it is skipped the same way.
Expected
A reviewer's approval counts only if it is their most recent review, ignoring COMMENTED reviews. A comment doesn't withdraw an approval on GitHub either. A later CHANGES_REQUESTED or DISMISSED review means they have no current approval.
Suggested fix
Mark the reviewer as seen on any review that isn't COMMENTED:
state := approval.GetState()
if _, ok := seen[userName]; ok {
return false
}
if state != "COMMENTED" {
seen[userName] = true
}
return state == "APPROVED"Tests to add to TestApprovals (or a new table test):
- approved, then changes requested: no approval;
- approved twice, newest dismissed: no approval;
- approved, then commented: the approval counts;
- changes requested, then approved: the approval counts.
One related detail: setupReviews uses the state REQUEST_CHANGES. That's the event name used when submitting a review; the API returns CHANGES_REQUESTED as the review's state, so the fixture should use that.
Impact
The codeowners check reports success while a code owner has requested changes. Branch protection or a ruleset that requires approvals still blocks the merge, because GitHub uses each reviewer's latest review. So the effect is a misleading green check, unless the codeowners check is the only approval gate.
Activity