Add a script to generate release log

This commit is contained in:
Yury Selivanov 2018-06-25 13:33:23 -04:00
parent cb0a65aea0
commit b996e0f7dd
1 changed files with 48 additions and 0 deletions

48
.github/release_log.py vendored Normal file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env python3
import argparse
import json
import requests
import re
BASE_URL = 'https://api.github.com/repos/magicstack/uvloop/compare'
def main():
parser = argparse.ArgumentParser(
description='Generate release log.')
parser.add_argument('--to', dest='to_hash', default='master', type=str)
parser.add_argument('--from', dest='from_hash', type=str)
args = parser.parse_args()
r = requests.get(f'{BASE_URL}/{args.from_hash}...{args.to_hash}')
data = json.loads(r.text)
for commit in data['commits']:
message = commit['commit']['message']
first_line = message.partition('\n\n')[0]
if commit.get('author'):
username = '@{}'.format(commit['author']['login'])
else:
username = commit['commit']['author']['name']
sha = commit["sha"][:8]
m = re.search(r'\#(?P<num>\d+)\b', message)
if m:
issue_num = m.group('num')
else:
issue_num = None
print(f'* {first_line}')
print(f' (by {username} in {sha}', end='')
if issue_num:
print(f' for #{issue_num})')
else:
print(')')
print()
if __name__ == '__main__':
main()