|
| 1 | +from github import Github |
| 2 | +from pprint import pprint |
| 3 | +import os |
| 4 | +import re |
| 5 | +import requests |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | + |
| 9 | +g = Github(os.getenv('GITHUB_TOKEN')) |
| 10 | +repo = g.get_repo('yourlabs/django-autocomplete-light') |
| 11 | +tag = sys.argv[1] |
| 12 | + |
| 13 | + |
| 14 | +with open('CHANGELOG', 'r') as f: |
| 15 | + CHANGELOG = f.read() |
| 16 | + |
| 17 | +last_release = None |
| 18 | +for line in CHANGELOG.split('\n'): |
| 19 | + if match := re.match('^(.+)', line): |
| 20 | + last_release = match.group(0) |
| 21 | + break |
| 22 | + |
| 23 | +git_log = subprocess.check_output( |
| 24 | + f"git log --pretty=format:'%h %D' {last_release}..", |
| 25 | + shell=True, |
| 26 | +).decode('utf8').split('\n') |
| 27 | + |
| 28 | +tags = {} |
| 29 | +tag_commits = [] |
| 30 | +for line in git_log: |
| 31 | + parts = line.split() |
| 32 | + if len(parts) == 1: |
| 33 | + tag_commits.append(parts[0]) |
| 34 | + elif len(parts) > 1 and parts[1] == 'tag:': |
| 35 | + tags[tag] = tag_commits |
| 36 | + tag = parts[2] |
| 37 | + tag_commits = [parts[0]] |
| 38 | + |
| 39 | +lines = [] |
| 40 | +for tag, shas in tags.items(): |
| 41 | + lines.append(tag) |
| 42 | + lines.append('') |
| 43 | + |
| 44 | + for sha in shas: |
| 45 | + line = [] |
| 46 | + commit = repo.get_commit(sha) |
| 47 | + author, description = subprocess.check_output( |
| 48 | + f"git log --format='%an--sep--%B' -n1 {sha}", |
| 49 | + shell=True, |
| 50 | + ).decode('utf8').split('\n')[0].split('--sep--') |
| 51 | + pulls = [*commit.get_pulls()] |
| 52 | + numbers = [] |
| 53 | + users = [] |
| 54 | + for pull in pulls: |
| 55 | + numbers.append(pull.number) |
| 56 | + users.append(pull.user.login) |
| 57 | + for number in numbers: |
| 58 | + line.append(f'#{number}'.ljust(7)) |
| 59 | + if not numbers: |
| 60 | + line.append(sha) |
| 61 | + |
| 62 | + line.append(description) |
| 63 | + line.append('by') |
| 64 | + for user in users: |
| 65 | + line.append(f'@{user}') |
| 66 | + if not users: |
| 67 | + line.append(author) |
| 68 | + lines.append(' ' + ' '.join(line)) |
| 69 | + |
| 70 | + lines.append('') |
| 71 | + |
| 72 | + |
| 73 | +print('\n'.join(lines)) |
0 commit comments