Debian Codegraph @

tools/changelog.py

raw symbols SCIP
1 # ruff: noqa: T201 (Allow print statements)
2 # Simple script to generate a rough changelog from git log.
3 # This changelog is manually edited before it goes into CHANGELOG.md
4
5 import re
6 import subprocess
7 import sys
8 from collections import defaultdict
9
10 if len(sys.argv) != 2:
11 print("Usage: python changelog.py <tag>")
12 sys.exit(1)
13
14 tag = sys.argv[1]
15 # Get all commits since the last release
16 cmd = ["git", "log", "--pretty=%s|%aN", f"{tag}..HEAD"]
17 log_lines = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read().decode("UTF-8")
18 log_lines = log_lines.split("\n")[:-1]
19
20 # Group commits by type
21 commit_groups = defaultdict(list)
22 for log_line in log_lines:
23 message, author = log_line.split("|")
24 # skip dependabot commits
25 if author == "dependabot[bot]":
26 group = "dependabot"
27 else:
28 type_parts = message.split(":")
29 if len(type_parts) == 1:
30 group = "other"
31 else:
32 group = type_parts[0]
33
34 commit_groups[group].append((message, author))
35
36 # Print the changelog
37 for group, commits in commit_groups.items():
38 print(group)
39 for message, author in commits:
40 # Thank authors other than maintainer
41 author_thanks = ""
42 if author != "Joris Roovers":
43 author_thanks = f" - Thanks {author}"
44
45 # Find the issue number in message using regex, format: (#1234)
46 issue_number = re.search(r"\(#(\d+)\)", message)
47 if issue_number:
48 issue_url = f"https://github.com/jorisroovers/gitlint/issues/{issue_number.group(1)}"
49 message = message.replace(issue_number.group(0), f"([#{issue_number.group(1)}]({issue_url}))")
50
51 print(f" - {message}{author_thanks}")