Created
June 20, 2019 11:26
-
-
Save utisam/1abd2ca30c6b98ae8ad0b2211458985c to your computer and use it in GitHub Desktop.
github-tricks
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
import getpass | |
import json | |
import sys | |
import requests | |
def main(): | |
username = input('Basic Auth Username: ') | |
password = getpass.getpass('Basic Auth Password: ') | |
owner = sys.argv[1] | |
repository = sys.argv[2] | |
r = requests.get( | |
f'https://api.github.com/repos/{owner}/{repository}/pulls', | |
headers={'Accept': 'application/vnd.github.shadow-cat-preview+json'}, | |
auth=(username, password), | |
) | |
assert r.status_code == 200 | |
pulls = r.json() | |
for pull in pulls: | |
number = pull['number'] | |
title = pull['title'] | |
if pull['draft'] and 'WIP' not in title: | |
print(f'Pull Request#{number} ({title}) will be renamed') | |
r = requests.patch( | |
f'https://api.github.com/repos/{owner}/{repository}/pulls/{number}', | |
headers = {'content-type': 'application/json'}, | |
auth=(username, password), | |
data=json.dumps({'title': '[WIP] ' + title}), | |
) | |
assert r.status_code == 200 | |
return 0 | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment