-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace release label validation script (#235)
* Replace release label validation script * Enchance logging * Enchance logging
- Loading branch information
1 parent
be5d6ae
commit 6b50da7
Showing
3 changed files
with
66 additions
and
2 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
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,52 @@ | ||
import requests | ||
import os | ||
import yaml | ||
import sys | ||
|
||
with open('.github/release.yml', 'r') as file: | ||
try: | ||
release_yaml = yaml.safe_load(file) | ||
label_pool = [] | ||
for category in release_yaml['changelog']['categories']: | ||
label_pool.extend(category['labels']) | ||
except yaml.YAMLError as exc: | ||
print(exc) | ||
|
||
print(f"One of these labels is required on PR: {label_pool}") | ||
token = os.getenv('GITHUB_TOKEN') | ||
repo = os.getenv('REPOSITORY') | ||
|
||
response = requests.get(f'https://api.github.com/repos/{repo}/releases/latest', headers={'Authorization': f'token {token}'}) | ||
response.raise_for_status() | ||
latest_release = response.json() | ||
latest_release_date = latest_release['created_at'] | ||
|
||
response = requests.get(f'https://api.github.com/repos/{repo}/pulls?state=closed&sort=updated&direction=desc', headers={'Authorization': f'token {token}'}) | ||
response.raise_for_status() | ||
all_closed_prs = response.json() | ||
|
||
prs_since_last_release = [ | ||
pr for pr in all_closed_prs | ||
if pr['merged_at'] is not None and pr['merged_at'] > latest_release_date | ||
] | ||
|
||
valid_prs = [] | ||
invalid_prs = [] | ||
for pr in prs_since_last_release: | ||
labels = [label['name'] for label in pr['labels']] | ||
common_labels = set(labels).intersection(label_pool) | ||
if len(common_labels) != 1: | ||
invalid_prs.append(pr['html_url']) | ||
else: | ||
valid_prs.append(pr['html_url']) | ||
|
||
print("\nThese PRs have exactly one required label:") | ||
print('\n'.join([f"PR: {pr}" for pr in valid_prs])) | ||
|
||
|
||
if invalid_prs: | ||
print("\nThese PRs don't have exactly one required label:") | ||
print('\n'.join([f"PR: {pr}" for pr in invalid_prs])) | ||
sys.exit(1) | ||
|
||
print("\nAll PRs have exactly one required label") |
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,2 @@ | ||
pyyaml | ||
requests |