1
- """Internal tool to update the changelog ."""
1
+ """Internal tool to update the CHANGELOG ."""
2
2
3
3
import json
4
4
import subprocess
9
9
10
10
from rich .prompt import Prompt
11
11
12
+ GH_ORG = "py-pdf"
13
+ GH_PROJECT = "pdfly"
14
+ VERSION_FILE_PATH = "pdfly/_version.py"
15
+ CHANGELOG_FILE_PATH = "CHANGELOG.md"
16
+
12
17
13
18
@dataclass (frozen = True )
14
19
class Change :
@@ -27,6 +32,7 @@ def main(changelog_path: str) -> None:
27
32
28
33
Args:
29
34
changelog_path: The location of the CHANGELOG file
35
+
30
36
"""
31
37
changelog = get_changelog (changelog_path )
32
38
git_tag = get_most_recent_git_tag ()
@@ -41,7 +47,7 @@ def main(changelog_path: str) -> None:
41
47
42
48
today = datetime .now (tz = timezone .utc )
43
49
header = f"## Version { new_version } , { today :%Y-%m-%d} \n "
44
- url = f"https://github.com/py-pdf/pdfly /compare/{ git_tag } ...{ new_version } "
50
+ url = f"https://github.com/{ GH_ORG } / { GH_PROJECT } /compare/{ git_tag } ...{ new_version } "
45
51
trailer = f"\n [Full Changelog]({ url } )\n \n "
46
52
new_entry = header + changes + trailer
47
53
print (new_entry )
@@ -61,9 +67,9 @@ def main(changelog_path: str) -> None:
61
67
def print_instructions (new_version : str ) -> None :
62
68
"""Print release instructions."""
63
69
print ("=" * 80 )
64
- print (f"☑ _version.py was adjusted to '{ new_version } '" )
65
- print ("☑ CHANGELOG.md was adjusted" )
66
- print ("" )
70
+ print (f"☑ { VERSION_FILE_PATH } was adjusted to '{ new_version } '" )
71
+ print (f "☑ { CHANGELOG_FILE_PATH } was adjusted" )
72
+ print ()
67
73
print ("Now run:" )
68
74
print (" git commit -eF RELEASE_COMMIT_MSG.md" )
69
75
print (f" git tag -s { new_version } -eF RELEASE_TAG_MSG.md" )
@@ -73,7 +79,7 @@ def print_instructions(new_version: str) -> None:
73
79
74
80
def adjust_version_py (version : str ) -> None :
75
81
"""Adjust the __version__ string."""
76
- with open ("pdfly/_version.py" , "w" ) as fp :
82
+ with open (VERSION_FILE_PATH , "w" ) as fp :
77
83
fp .write (f'__version__ = "{ version } "\n ' )
78
84
79
85
@@ -93,8 +99,7 @@ def get_version_interactive(new_version: str, changes: str) -> str:
93
99
94
100
def is_semantic_version (version : str ) -> bool :
95
101
"""Check if the given version is a semantic version."""
96
- # It's not so important to cover the edge-cases like pre-releases
97
- # This is meant for pdfly only and we don't make pre-releases
102
+ # This doesn't cover the edge-cases like pre-releases
98
103
if version .count ("." ) != 2 :
99
104
return False
100
105
try :
@@ -147,6 +152,7 @@ def version_bump(git_tag: str) -> str:
147
152
148
153
Returns:
149
154
The new version where the patch version is bumped.
155
+
150
156
"""
151
157
# just assume a patch version change
152
158
major , minor , patch = git_tag .split ("." )
@@ -162,6 +168,7 @@ def get_changelog(changelog_path: str) -> str:
162
168
163
169
Returns:
164
170
Data of the CHANGELOG
171
+
165
172
"""
166
173
with open (changelog_path ) as fh :
167
174
changelog = fh .read ()
@@ -175,6 +182,7 @@ def write_changelog(new_changelog: str, changelog_path: str) -> None:
175
182
Args:
176
183
new_changelog: Contents of the new CHANGELOG
177
184
changelog_path: Path where the CHANGELOG file is
185
+
178
186
"""
179
187
with open (changelog_path , "w" ) as fh :
180
188
fh .write (new_changelog )
@@ -189,6 +197,7 @@ def get_formatted_changes(git_tag: str) -> Tuple[str, str]:
189
197
190
198
Returns:
191
199
Changes done since git_tag
200
+
192
201
"""
193
202
commits = get_git_commits_since_tag (git_tag )
194
203
@@ -249,8 +258,11 @@ def get_formatted_changes(git_tag: str) -> Tuple[str, str]:
249
258
250
259
if grouped :
251
260
output += "\n ### Other\n "
261
+ output_with_user += "\n ### Other\n "
252
262
for prefix in grouped :
253
- output += f"- { prefix } : { grouped [prefix ]} \n "
263
+ for commit_dict in grouped [prefix ]:
264
+ output += f"- { prefix } : { commit_dict ['msg' ]} \n "
265
+ output_with_user += f"- { prefix } : { commit_dict ['msg' ]} by @{ commit_dict ['author' ]} \n "
254
266
255
267
return output , output_with_user
256
268
@@ -261,6 +273,7 @@ def get_most_recent_git_tag() -> str:
261
273
262
274
Returns:
263
275
Most recently created git tag.
276
+
264
277
"""
265
278
git_tag = str (
266
279
subprocess .check_output (
@@ -280,18 +293,18 @@ def get_author_mapping(line_count: int) -> Dict[str, str]:
280
293
281
294
Returns:
282
295
A mapping of long commit hashes to author login handles.
296
+
283
297
"""
284
298
per_page = min (line_count , 100 )
285
299
page = 1
286
300
mapping : Dict [str , str ] = {}
287
301
for _ in range (0 , line_count , per_page ):
288
- with urllib .request .urlopen ( # noqa: S310
289
- f"https://api.github.com/repos/py-pdf/pdfly /commits?per_page={ per_page } &page={ page } "
302
+ with urllib .request .urlopen (
303
+ f"https://api.github.com/repos/{ GH_ORG } / { GH_PROJECT } /commits?per_page={ per_page } &page={ page } "
290
304
) as response :
291
305
commits = json .loads (response .read ())
292
306
page += 1
293
307
for commit in commits :
294
- print (commit )
295
308
if commit ["author" ]:
296
309
gh_handle = commit ["author" ]["login" ]
297
310
else :
@@ -311,8 +324,9 @@ def get_git_commits_since_tag(git_tag: str) -> List[Change]:
311
324
312
325
Returns:
313
326
List of all changes since git_tag.
327
+
314
328
"""
315
- commits = str (
329
+ commits = (
316
330
subprocess .check_output (
317
331
[
318
332
"git" ,
@@ -323,8 +337,10 @@ def get_git_commits_since_tag(git_tag: str) -> List[Change]:
323
337
],
324
338
stderr = subprocess .STDOUT ,
325
339
)
326
- ).strip ("'b\\ n" )
327
- lines = commits .split ("\\ n" )
340
+ .decode ("UTF-8" )
341
+ .strip ()
342
+ )
343
+ lines = commits .splitlines ()
328
344
authors = get_author_mapping (len (lines ))
329
345
return [parse_commit_line (line , authors ) for line in lines if line != "" ]
330
346
@@ -341,13 +357,14 @@ def parse_commit_line(line: str, authors: Dict[str, str]) -> Change:
341
357
342
358
Raises:
343
359
ValueError: The commit line is not well-structured
360
+
344
361
"""
345
362
parts = line .split (":::" )
346
363
if len (parts ) != 3 :
347
364
raise ValueError (f"Invalid commit line: '{ line } '" )
348
365
commit_hash , rest , author = parts
349
366
if ":" in rest :
350
- prefix , message = rest .split (":" , 1 )
367
+ prefix , message = rest .split (": " , 1 )
351
368
else :
352
369
prefix = ""
353
370
message = rest
@@ -374,4 +391,4 @@ def parse_commit_line(line: str, authors: Dict[str, str]) -> Change:
374
391
375
392
376
393
if __name__ == "__main__" :
377
- main ("CHANGELOG.md" )
394
+ main (CHANGELOG_FILE_PATH )
0 commit comments