Skip to content

Commit cccf4b2

Browse files
committed
display-changelog
Signed-off-by: Vaishnavi S <[email protected]>
1 parent e84ac0e commit cccf4b2

File tree

7 files changed

+101
-62641
lines changed

7 files changed

+101
-62641
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: update-changelog
5+
name: Update License Changelog
6+
entry: python changelog.py
7+
language: system
8+
pass_filenames: false

changelog.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
from git import Repo
3+
4+
def generate_license_changelog():
5+
# Setup paths
6+
repo_path = '..'
7+
output_path = 'docs/changelog.md'
8+
# We look in etc because that is where the license files live
9+
search_path = 'etc'
10+
11+
# Open the repository
12+
print("Opening repository...")
13+
repo = Repo(repo_path)
14+
15+
# Get the last 50 changes
16+
print("Fetching recent commits...")
17+
commits = list(repo.iter_commits(paths=search_path, max_count=50))
18+
19+
# Start building the Markdown table
20+
# We use a list called 'lines' to hold each row of our table
21+
lines = [
22+
"# License Changelog",
23+
"",
24+
"| Date | Action | License | Commit |",
25+
"| :--- | :--- | :--- | :--- |"
26+
]
27+
28+
# Loop through each commit to find what changed
29+
for commit in commits:
30+
# Get a readable date
31+
date_str = commit.authored_datetime.strftime("%Y-%m-%d")
32+
commit_hash = commit.hexsha[:7]
33+
34+
# Comparing this commit with the one before it
35+
if commit.parents:
36+
diffs = commit.diff(commit.parents[0])
37+
else:
38+
# This is the very first commit in the repo
39+
diffs = commit.diff(None)
40+
41+
for diff in diffs:
42+
# Look for the file name
43+
file_path = diff.b_path or diff.a_path
44+
45+
# Check if it is a license YAML file
46+
if file_path.endswith('.yml') and 'licenses' in file_path:
47+
# Get just the name (like 'mit') instead of 'etc/licenses/mit.yml'
48+
license_name = os.path.basename(file_path).replace('.yml', '')
49+
50+
# Decide if it was Added or Refined
51+
if diff.change_type == 'A':
52+
action = "Added"
53+
else:
54+
action = "Refined"
55+
56+
# Add the row to our list
57+
new_row = f"| {date_str} | {action} | {license_name} | `{commit_hash}` |"
58+
lines.append(new_row)
59+
60+
# Save the list to a file
61+
print(f"Saving changelog to {output_path}...")
62+
with open(output_path, 'w') as f:
63+
# Join all lines with a newline character
64+
f.write('\n'.join(lines))
65+
66+
print("Done!")
67+
68+
if __name__ == "__main__":
69+
generate_license_changelog()

changes.txt

Whitespace-only changes.

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# License Changelog
2+
3+
| Date | Action | License | Commit |
4+
| :--- | :--- | :--- | :--- |
5+
| 2025-03-19 | Refined | skype-eula.txt | `e01ac70` |
6+
| 2025-03-19 | Refined | wxwindows.txt | `e01ac70` |
7+
| 2025-03-19 | Refined | licenses_list.json | `e01ac70` |

0 commit comments

Comments
 (0)