[FLINK-40320][ci] Exclude author and co-author reviews from community review labeling - #28341
[FLINK-40320][ci] Exclude author and co-author reviews from community review labeling#28341spuru9 wants to merge 3 commits into
Conversation
…ew labeling The community review GitHub Action applies the `community-reviewed` label when a non-committer reviews a PR. It also counted the PR author's own reviews (for example, a self-comment on their own PR) as a community review, so a PR could be labeled `community-reviewed` purely because its author commented on it, with no actual community review having occurred. Fetch the PR author login in the open-PRs query, pass it into the review tally, and skip reviews authored by the PR author so that only reviews from other community members are counted.
|
@ferenc-csaky @snuyanzin Can you take a look. The situation I am trying to tackle in something like in #28895 |
| # $1 - GitHub API token for authentication | ||
| # $2 - PR number | ||
| # $3 - PR reviews | ||
| # $4 - PR author login (excluded from the review tally) |
There was a problem hiding this comment.
I can take a look at that. I didn't see a co-author case happening much in PRs.
There was a problem hiding this comment.
I didn't see a co-author case happening much in PRs.
!= 0%
and anyway you are touching this code
There was a problem hiding this comment.
Have added the co-author part as well. As this increases the number of call, have tried to optimise call.
Have intentionally kept separate commits for easy review, please squash and merge when final.
Have created a JIRA as the scope is a little bigger.
…w labeling A review left by someone who worked on the PR is no more a community review than one left by the PR author, but the tally counted it, so a PR could be labeled `community-reviewed` off the back of its own contributors. Co-authorship on its own is not enough to disqualify a reviewer, though. GitHub records a reviewer as co-author the moment the PR author commits one of their suggestions, so the two cases in the repo today (apache#28791, apache#28793) are reviewers who earned their co-authorship by reviewing. Excluding them would drop the label from exactly the reviews it is meant to showcase. Skip a reviewer only when they had already authored a commit on the PR before their first review. The co-authors are fetched per PR, and only once a review would otherwise be counted, so the extra query is paid only for PRs that have a community reviewer. A request for changes is now counted whoever it came from, since a co-author, unlike the author, can submit one. Generated-by: Claude Code (claude-opus-5)
| printf "%-15s | %-20s | %-20s - checking user permissions..." "$user" "$state" "$time" | ||
| push_permission=$(call_github_get_user_push_permission "$token" "$user") || exit | ||
| printf "%s\n" "$push_permission" | ||
|
|
||
| #see if the user has read role | ||
| if [[ "$push_permission" == "true" ]]; then | ||
| if [[ "$state" == "APPROVED" ]]; then | ||
| ((++committerApproves)) | ||
| fi | ||
| else | ||
| # only worth paying for the co-author lookup once a review would otherwise be counted | ||
| if [[ "$coauthor_lookup_needed" == "true" && -z "${pr_coauthors+set}" ]]; then | ||
| pr_coauthors="$(get_pr_coauthors "$token" "$pr_number")" || exit | ||
| fi | ||
| if is_coauthor_before_review "$user" "$first_review_time" "${pr_coauthors-}"; then | ||
| printf "%-15s | %-20s | %-20s - skipping PR co-author self-review\n" "$user" "$state" "$time" | ||
| else | ||
| ((++communityReviews)) | ||
| if [[ "$state" == "APPROVED" ]]; then | ||
| ((++communityApproves)) | ||
| fi | ||
| fi |
There was a problem hiding this comment.
what it is about and why do we need it?
There was a problem hiding this comment.
is_coauthor_before_review skips a reviewer who wrote part of the PR before reviewing it, since they aren't reviewing it as a community member.
This is to tackle the situation in which you provide suggestion, when the author accept the suggestion you get added as coauthor, but you were a review at that point.
There was a problem hiding this comment.
and what will change?
will it just drop the label or what?
Initially I had impression the PR is only about label handling
however it looks like it is getting a way more complicated
There was a problem hiding this comment.
It doesnt drop label. If X first add a review and then become a co-author it is community-reviewed else if he already is a co-author he cant be a reviewer. (This is specifically for the suggestion part)
Yup adding co-author adds a little complexity.
There was a problem hiding this comment.
it still doesn't answer why we need to look at permissions here.
My impression was: having a very dummy method: get all coathors + author, get all reviewers, find the diff, if diff == 0 then no label should be put.
Why are we looking at permissions, APPROVE and something else?
There was a problem hiding this comment.
I think there is some confusion here, If you are talking about this block
printf "%-15s | %-20s | %-20s - checking user permissions..." "$user" "$state" "$time"
push_permission=$(call_github_get_user_push_permission "$token" "$user") || exit
printf "%s\n" "$push_permission"
#see if the user has read role
if [[ "$push_permission" == "true" ]]; then
if [[ "$state" == "APPROVED" ]]; then
((++committerApproves))
fi
This is just being rearranged in this PR. Its already there in the original code. They are just being indented. (See 268-276 in main, FLIP-518)
The only part I have added in to check the coauthor_lookup_needed and is_coauthor_before_review.
25f1cf1 to
bbb283f
Compare
The script asked GitHub for a PR's existing labels over REST, once for every PR about to be labeled and again for every PR targeting a release branch. The open-PRs query it already pages through can carry them instead, at no extra cost. Read them there, pass them down, and retire `call_github_get_labels_api`. Against the 370 open PRs this takes the REST calls a run makes from ~507 down to ~143. Generated-by: Claude Code (claude-opus-5)
bbb283f to
0513e2c
Compare

What is the purpose of the change
community-review.shapplies thecommunity-reviewedlabel when a non-committer reviews a PR, but the tally also counted reviews written by the people who wrote the PR — the author, and any co-author. Neither is a community review. #28190 is a live example: its only reviews are twoCOMMENTEDreviews by its own author, and it carries the label.Co-authors need care, though. GitHub adds
Co-authored-by: <reviewer>as soon as the author presses Commit suggestion, so co-authorship is often produced by the review itself — both such cases in the repo today (#28791, #28793) are that. Excluding co-authors outright would drop the label from exactly the reviews it exists to showcase, so a reviewer is skipped only when they had already authored a commit before their first review.Known gap: squashing a suggestion commit into an earlier one rewinds the author date and defeats that check. Comparing
committedDateinstead would be worse, since rebasing rewrites it for genuine co-authors too.Brief change log
call_github_get_labels_apiVerifying this change
This change reworks the community review labeling script and has no production code impact.
Covered by running the script's functions with the GitHub calls mocked: author-only review, suggestion-generated co-author (still counted), co-author who contributed first (not counted), co-author's request for changes still blocking LGTM, committer approval still suppressing LGTM, and a GraphQL failure aborting rather than silently counting everyone.
Also run end to end against the live repository with only label mutations and the permission lookup stubbed. All 370 open PRs processed, decisions matching the labels currently on them, at ~180 GraphQL calls and 143 REST calls, against ~4 GraphQL and ~507 REST before this change.
Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code