Created
November 9, 2023 19:10
-
-
Save raylu/f9881f9e92cf755bc43ef191f9c64b72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from pprint import pprint | |
import sys | |
import requests | |
TOKEN = '' # replace | |
OWNER = 'benchling' | |
REPO = 'aurelia' | |
def main(): | |
pr_number = sys.argv[1] | |
reviewers_url = f'https://api.github.com/repos/{OWNER}/{REPO}/pulls/{pr_number}/requested_reviewers' | |
headers = { | |
'Authorization': f'Bearer {TOKEN}', | |
'Accept': 'application/vnd.github.v3+json', | |
'X-GitHub-Api-Version': '2022-11-28', | |
} | |
response = requests.get(reviewers_url, headers=headers) | |
response.raise_for_status() | |
reviewers = response.json() | |
reviewers_to_unassign = [u['login'] for u in reviewers.get('users', [])] | |
teams_to_unassign = [t['slug'] for t in reviewers.get('teams', [])] | |
unassign_data = { | |
'reviewers': reviewers_to_unassign, | |
'team_reviewers': teams_to_unassign, | |
} | |
pprint(unassign_data) | |
if len(reviewers_to_unassign) + len(teams_to_unassign) == 0: | |
sys.exit('no reviewers to unassign') | |
response = requests.delete(reviewers_url, headers=headers, json=unassign_data) | |
response.raise_for_status() | |
print(f'all reviewers have been unassigned from PR #{pr_number}') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment