Skip to content

Commit 7565204

Browse files
authored
Replace get_changes in dev with custom solution for automating changelog updates (#2659)
* Replaces get_changes in dev with custom solution. Signed-off-by: Michael Robinson <[email protected]> * Updates .gitignore with changelog temp file. Signed-off-by: Michael Robinson <[email protected]> * Improves describe_changes method. Signed-off-by: Michael Robinson <[email protected]> * Removes default path to changelog and changes readme file format. Signed-off-by: Michael Robinson <[email protected]> --------- Signed-off-by: Michael Robinson <[email protected]>
1 parent 5c42dfd commit 7565204

File tree

6 files changed

+184
-35
lines changed

6 files changed

+184
-35
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ metadata.json
3939

4040
# Dependent Helm charts
4141
chart/charts/
42+
43+
# Dev
44+
changes.txt

dev/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

dev/README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
### Using `get_changes`
22

3-
The `get_changes.sh` script uses a fork of saadmk11/changelog-ci to get all
4-
merged changes between two specified releases. To get all changes since the latest
5-
release, set `END_RELEASE_VERSION` to the planned next release.
6-
7-
The changes will appear at the top of CHANGELOG.md.
3+
The changes will appear in ../CHANGELOG.md.
84

95
#### Requirements
106

11-
Python 3.10 or newer is required.
12-
See the requirements.txt file for required dependencies.
13-
14-
The script also requires that the following environment variables be set:
15-
16-
`END_RELEASE_VERSION`\
17-
`START_RELEASE_VERSION`\
18-
`INPUT_GITHUB_TOKEN`
7+
Install the required dependencies in requirements.txt.
198

20-
For example: `export END_RELEASE_VERSION=0.21.0`.
21-
22-
Use the planned next release for the end release version.
9+
The script also requires a GitHub token.
2310

2411
For instructions on creating a GitHub personal access token to use the GitHub API,
2512
see: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token.
2613

2714
#### Running the script
2815

29-
Make the script executable (the first time), then run it with `./get_changes.sh`.
16+
Run the script from the root directory:
17+
18+
```sh
19+
python3 dev/get_changes.py --github_token token --previous 0.42.0 --current 0.43.0 --path /local/path/to/CHANGELOG.md
20+
```
21+
22+
If you get a `command not found` or similar error, make sure you have made the
23+
script an executable (e.g., `chmod u+x ./dev/get_changes.py`).

dev/get_changes.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2018-2023 contributors to the Marquez project
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
from github import Github
7+
import rich_click as click
8+
from datetime import date
9+
from typing import TYPE_CHECKING
10+
if TYPE_CHECKING:
11+
from github.PullRequest import PullRequest
12+
13+
class GetChanges:
14+
15+
def __init__(self, github_token: str, previous: str, current: str, path: str):
16+
self.github_token = github_token
17+
self.previous = previous
18+
self.current = current
19+
self.path = path
20+
self.pulls: list[PullRequest] = []
21+
self.rel_title_str: str = ''
22+
self.text: list[str] = []
23+
self.new_contributors: dict[str:str] = {}
24+
25+
def get_pulls(self):
26+
print('Working on it...')
27+
g = Github(self.github_token)
28+
repo = g.get_repo("MarquezProject/marquez")
29+
prev_date = repo.get_release(self.previous).created_at
30+
commits = repo.get_commits(since=prev_date)
31+
self.pulls = [pull for commit in commits for pull in commit.get_pulls()]
32+
33+
def write_title(self):
34+
self.rel_title_str = f'## [{self.current}](https://github.com/MarquezProject/marquez/compare/{self.previous}...{self.current}) - {date.today()}'
35+
36+
def describe_changes(self):
37+
for pull in self.pulls:
38+
39+
""" Assembles change description with PR and user URLs """
40+
entry = []
41+
if pull.user.login != 'dependabot[bot]':
42+
labels = []
43+
for label in pull.labels:
44+
if label.name != 'documentation':
45+
labels.append(label.name)
46+
change_str = f'* **{labels[0]}: {pull.title}** [`#{pull.number}`]({pull.html_url}) [@{pull.user.login}]({pull.user.html_url}) '
47+
48+
""" Extracts one-line description if present """
49+
beg = pull.body.find('One-line summary:') + 18
50+
if beg == 17:
51+
change_descrip_str = ' **'
52+
else:
53+
test = pull.body.find('### Checklist')
54+
if test == -1:
55+
end = beg + 75
56+
else:
57+
end = test - 1
58+
descrip = pull.body[beg:end].split()
59+
descrip_str = ' '.join(descrip)
60+
change_descrip_str = f' *{descrip_str}*'
61+
62+
entry.append(change_str + '\n')
63+
entry.append(change_descrip_str + '\n')
64+
self.text.append(entry)
65+
66+
def get_new_contributors(self):
67+
for pull in self.pulls:
68+
comments = pull.get_issue_comments()
69+
for comment in comments:
70+
if 'Thanks for opening your' in comment.body:
71+
self.new_contributors[pull.user.login] = pull.user.url
72+
if self.new_contributors:
73+
print('New contributors:')
74+
for k, v in self.new_contributors.items():
75+
print(f'@{k}: {v}')
76+
else:
77+
print('Note: no new contributors were found.')
78+
79+
def update_changelog(self):
80+
f = open('changes.txt', 'w+')
81+
f = open('changes.txt', 'a')
82+
f.write(self.rel_title_str + '\n')
83+
for entry in self.text:
84+
for line in entry:
85+
f.write(line)
86+
f.close()
87+
88+
with open('changes.txt', 'r+') as f:
89+
new_changes = f.read()
90+
with open(self.path, 'r') as contents:
91+
save = contents.read()
92+
with open(self.path, 'w') as contents:
93+
contents.write(new_changes)
94+
with open(self.path, 'a') as contents:
95+
contents.write(save)
96+
97+
@click.command()
98+
@click.option(
99+
'--github_token', type=str, default=''
100+
)
101+
@click.option(
102+
"--previous", type=str, default=''
103+
)
104+
@click.option(
105+
"--current", type=str, default=''
106+
)
107+
@click.option(
108+
"--path",
109+
type=str,
110+
default='',
111+
help='absolute path to changelog',
112+
)
113+
114+
def main(
115+
github_token: str,
116+
previous: str,
117+
current: str,
118+
path: str,
119+
):
120+
c = GetChanges(
121+
github_token=github_token,
122+
previous=previous,
123+
current=current,
124+
path=path
125+
)
126+
c.get_pulls()
127+
c.describe_changes()
128+
c.write_title()
129+
c.update_changelog()
130+
c.get_new_contributors()
131+
print('...done!')
132+
133+
if __name__ == "__main__":
134+
main()
135+

dev/get_changes.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

dev/requirements.txt

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1-
PyYAML~=5.4.1
2-
requests~=2.25.1
3-
github-action-utils~=1.1.0
1+
aiohttp==3.8.1
2+
aiosignal==1.3.1
3+
async-timeout==4.0.2
4+
attrs==22.2.0
5+
bump2version==1.0.1
6+
certifi==2022.12.7
7+
cffi==1.15.1
8+
chardet==4.0.0
9+
charset-normalizer==2.1.1
10+
click==8.1.3
11+
Deprecated==1.2.13
12+
frozenlist==1.3.3
13+
github==1.2.7
14+
github-action-utils==1.1.0
15+
idna==2.10
16+
markdown-it-py==2.1.0
17+
mdurl==0.1.2
18+
multidict==6.0.4
19+
pendulum==2.1.2
20+
pycparser==2.21
21+
PyGithub==1.57
22+
Pygments==2.14.0
23+
PyJWT==2.6.0
24+
PyNaCl==1.5.0
25+
python-dateutil==2.8.2
26+
pytzdata==2020.1
27+
PyYAML==5.4.1
28+
requests==2.25.1
29+
rich==13.3.1
30+
rich-click==1.6.1
31+
six==1.16.0
32+
typing_extensions==4.4.0
33+
urllib3==1.26.14
34+
wrapt==1.14.1
35+
yarl==1.8.2

0 commit comments

Comments
 (0)