-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangelog_generator.py
More file actions
38 lines (28 loc) · 866 Bytes
/
changelog_generator.py
File metadata and controls
38 lines (28 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import subprocess
from shutil import which
GIT_DIR = str(which("git"))
def last_tag():
subprocess.run(["git", "fetch", "--tags"], check=True)
result = subprocess.run(
[GIT_DIR, "describe", "--tags", "--abbrev=0"],
text=True,
capture_output=True,
check=True,
)
return result.stdout.strip()
def generate_changelog():
to_tag = "HEAD"
try:
from_tag = last_tag()
except subprocess.CalledProcessError:
from_tag = None
cmd = [GIT_DIR, "log", "--pretty=format:%h %s"]
if from_tag:
cmd.append(f"{from_tag}..{to_tag}")
try:
result = subprocess.run(cmd, text=True, capture_output=True, check=True)
print(result.stdout)
except subprocess.CalledProcessError as e:
print(f"❌ Git error: {e}")
if __name__ == "__main__":
generate_changelog()