Skip to content

Allow RemoveReviewers to remove only teams - #3337

Merged
gmlewis merged 3 commits into
google:masterfrom
nagl-resourcely:allow-removing-only-teams
Oct 27, 2024
Merged

Allow RemoveReviewers to remove only teams#3337
gmlewis merged 3 commits into
google:masterfrom
nagl-resourcely:allow-removing-only-teams

Conversation

@nagl-resourcely

@nagl-resourcelynagl-resourcely commented Oct 26, 2024

Copy link
Copy Markdown
Contributor

What?

Fixes a JSON marshaling problem that causes spurious 422s when calling RemoveReviewrs with TeamReviewers but no Reviewers.

Background

The github API requires "reviewers". It permits "reviewers": [] but not "reviewers": null. Try it:

echo "Show the problem"
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${PAT}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${OWNER}/${REPO}/pulls/${NUMBER}/requested_reviewers \
-d '{"team_reviewers":["the_senate"]}' {
"message": "Invalid request.\n\n\"reviewers\" wasn't supplied.",
"documentation_url": "https://docs.github.com/rest/pulls/review-requests#remove-requested-reviewers-from-a-pull-request",
"status": "422"
}
echo "What if we just removed omitempty?"
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${PAT}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${OWNER}/${REPO}/pulls/${NUMBER}/requested_reviewers \
-d '{"reviewers": null, "team_reviewers":["the_senate"]}'
{
"message": "Invalid request.\n\nFor 'properties/reviewers', nil is not an array.",
"documentation_url": "https://docs.github.com/rest/pulls/review-requests#remove-requested-reviewers-from-a-pull-request",
"status": "422"
}
echo "Does the empty list work?"
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${PAT}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${OWNER}/${REPO}/pulls/${NUMBER}/requested_reviewers \
-d '{"reviewers": [], "team_reviewers":["the_senate"]}'
{
"url": ...<spam>,

Testing?

There's a new unit test. Without the 2nd commit, it fails with:

 pulls_reviewers_test.go:181: request Body is {"team_reviewers":["justice-league"]}
, want {"reviewers":[],"team_reviewers":["justice-league"]}

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @nagl-resourcely!
One nit, otherwise LGTM.

Then we will be ready for a second LGTM+Approval from any other contributor to this repo before merging.

Comment threadgithub/pulls_reviewers.go Outdated
@gmlewisgmlewis added the NeedsReview PR is awaiting a review before merging. label Oct 26, 2024
Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
@nagl-resourcely

Copy link
Copy Markdown
ContributorAuthor

Ty for expressing the nit as a diff =)

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @nagl-resourcely !
LGTM.

Awaiting second LGTM+Approval from any other contributor to this repo before merging.

@codecov

codecovBot commented Oct 26, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.02%. Comparing base (2b8c7fa) to head (651c746).
Report is 163 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #3337 +/- ##
==========================================
- Coverage 97.72% 93.02% -4.71% 
==========================================
Files 153 172 +19 Lines 13390 14860 +1470 ==========================================
+ Hits 13085 13823 +738 - Misses 215 944 +729 - Partials 90 93 +3 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tomfeigintomfeigin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gmlewisgmlewis removed the NeedsReview PR is awaiting a review before merging. label Oct 27, 2024
@gmlewis

Copy link
Copy Markdown
Collaborator

Thank you, @tomfeigin !
Merging.

@gmlewis
gmlewis merged commit 9e5757d into google:masterOct 27, 2024
@nagl-resourcely
nagl-resourcely deleted the allow-removing-only-teams branch October 28, 2024 15:18
jlaportebot added a commit to jlaportebot/go-github that referenced this pull request Jun 28, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@nagl-resourcely@gmlewis@tomfeigin