Skip to content

Commit

Permalink
chore(extras): script to generate list of PRs that master is ahead of rc
Browse files Browse the repository at this point in the history
  • Loading branch information
jansegre committed Jul 12, 2023
1 parent 67e0848 commit f7f6787
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions extras/gen_release_candidate_changes.py
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}')

0 comments on commit f7f6787

Please sign in to comment.