Skip to content

Commit 9fafe29

Browse files
committed
🚀 Update release doc generator to show changelog
1 parent 062d110 commit 9fafe29

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

.github/scripts/releases.py

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import re
22
from os import environ
33

4-
from github import Github, ContentFile
4+
from github import Github
55
from github.GitRelease import GitRelease
66

77
GITHUB_REPOSITORY = environ.get("GITHUB_REPOSITORY", "awtkns/fastapi-crudrouter")
88
GITHUB_TOKEN = environ.get("GH_TOKEN") or environ.get("GITHUB_TOKEN")
99
GITHUB_URL = "https://github.com"
10+
GITHUB_BRANCH = "master"
1011
FILE_PATH = "docs/en/docs/releases.md"
1112
COMMIT_MESSAGE = "🤖 auto update releases.md"
1213

1314

1415
gh = Github(GITHUB_TOKEN)
1516

1617

17-
def generate_header(r: GitRelease, separator: bool = False):
18-
header = ""
19-
if separator:
20-
header += "\n\n---\n"
18+
def generate_header(r: GitRelease, header_row: bool = False):
19+
if header_row:
20+
header = "Release Notes\n===\n"
21+
else:
22+
header = "\n\n---\n"
2123

2224
return (
2325
header
@@ -37,26 +39,36 @@ def commit_update(content: str):
3739
else:
3840
print("Uploading new release documentation")
3941

40-
repo.update_file(file.path, message=COMMIT_MESSAGE, content=content, sha=file.sha)
42+
repo.update_file(
43+
file.path,
44+
message=COMMIT_MESSAGE,
45+
content=content,
46+
sha=file.sha,
47+
branch=GITHUB_BRANCH,
48+
)
4149

4250

4351
def insert_links(content: str):
4452
"""Replaces both #pull and @author with correct links"""
45-
url = repo.html_url + "/pull"
46-
content = re.sub(r"#(\d+)", rf"[#\1]({url}/\1)", content)
53+
pull_url = repo.html_url + "/pull"
54+
content = re.sub(r"#(\d+)", rf"[#\1]({pull_url}/\1)", content)
55+
56+
compare_url = repo.html_url + "/compare"
57+
content = re.sub(rf"{compare_url}/([^\s]+)", rf"[`\1`]({compare_url}/\1)", content)
58+
4759
return re.sub(r"@(\S+)", rf"[@\1]({GITHUB_URL}/\1)", content)
4860

4961

5062
if __name__ == "__main__":
5163
repo = gh.get_repo(GITHUB_REPOSITORY)
5264

5365
new_content = ""
54-
first = False
55-
for r in repo.get_releases():
56-
if not r.draft:
57-
new_content += generate_header(r, first)
58-
new_content += r.body
59-
first = True
66+
show_header = True
67+
for release in repo.get_releases():
68+
if not release.draft:
69+
new_content += generate_header(release, header_row=show_header)
70+
new_content += release.body
71+
show_header = False
6072

6173
new_content = insert_links(new_content)
6274
commit_update(new_content)

0 commit comments

Comments
 (0)