-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(extras): script to generate list of PRs that master is ahead of rc
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/env python | ||
|
||
import yaml | ||
import os | ||
import requests | ||
|
||
BASE_API_URL = 'https://api.github.com' | ||
REPO = 'HathorNetwork/hathor-core' | ||
|
||
|
||
def get_gh_token(): | ||
config_path = os.path.expanduser('~/.config/gh/hosts.yml') | ||
|
||
if not os.path.exists(config_path): | ||
print("GitHub CLI configuration not found. Please authenticate with 'gh auth login'.") | ||
exit(1) | ||
|
||
with open(config_path, 'r') as file: | ||
config = yaml.safe_load(file) | ||
|
||
token = config['github.com']['oauth_token'] | ||
return token | ||
|
||
|
||
def get_headers(token): | ||
return {'Authorization': f'token {token}'} | ||
|
||
|
||
def get_commits_ahead(base, compare, token): | ||
response = requests.get( | ||
f'{BASE_API_URL}/repos/{REPO}/compare/{base}...{compare}', | ||
headers=get_headers(token) | ||
) | ||
data = response.json() | ||
return [commit['sha'] for commit in data['commits']] | ||
|
||
|
||
def get_pr_for_commit(commit, token): | ||
response = requests.get( | ||
f'{BASE_API_URL}/repos/{REPO}/commits/{commit}/pulls', | ||
headers=get_headers(token), | ||
params={'state': 'all'} | ||
) | ||
data = response.json() | ||
if data: | ||
return data[0]['number'] | ||
return None | ||
|
||
|
||
def get_new_prs_in_master(token): | ||
commits = get_commits_ahead('release-candidate', 'master', token) | ||
prs = [] | ||
for commit in commits: | ||
pr = get_pr_for_commit(commit, token) | ||
if pr and pr not in prs: | ||
prs.append(pr) | ||
return prs | ||
|
||
|
||
if __name__ == '__main__': | ||
token = get_gh_token() | ||
prs = get_new_prs_in_master(token) | ||
for pr in prs: | ||
print(f'- #{pr}') |