Skip to content

Commit b463af0

Browse files
committed
Fix yourlabs#1295: Automate CHANGELOG
1 parent 1984202 commit b463af0

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

changelog.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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))

release.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ sed -i "s/release = [^,]*,/release = '$1'/" docs/conf.py
3131
short=$(echo $1 | grep -Eo '[^.]+\.[^.]+')
3232
sed -i "s/version = [^,]*,/version = '$short'/" docs/conf.py
3333

34-
git add setup.py docs/conf.py
34+
source ~/.github
35+
echo -e "$(python changelog.py $1)\n$(cat CHANGELOG)" > CHANGELOG
36+
git add setup.py docs/conf.py CHANGELOG
3537
git commit -m "Release $1"
3638
git tag $1
3739
python setup.py sdist

0 commit comments

Comments
 (0)