Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(extras): script to generate list of PRs that master is ahead of rc #701

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions extras/gen_release_candidate_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need a way for people doing releases to know that this exists (in case someone else needs to do them)

I think we should guide them to use this in our release guide.
What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be great.

"""
This script finds all PRs that have been merged into the `master` branch but not into the `release-candidate` branch in a given GitHub repository.

Usage:

./extras/gen_release_candidate_changes.py

Example output:

```
- #701
- #697
- #686
```
"""

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}')