|
| 1 | +""" |
| 2 | +script to automate updation of changelog as I add features. |
| 3 | +""" |
| 4 | + |
| 5 | +import subprocess |
| 6 | +import datetime |
| 7 | + |
| 8 | +CHANGELOG_FILE = "CHANGELOG.md" |
| 9 | +CHECK_INTERVAL = "weekly" |
| 10 | + |
| 11 | + |
| 12 | +def get_latest_commits(since="1 week ago"): |
| 13 | + """ |
| 14 | + Get the latest commits in the repository since the specified time. |
| 15 | + """ |
| 16 | + try: |
| 17 | + result = subprocess.run( |
| 18 | + ["git", "log", "--pretty=format:%h %s", f"--since={since}"], |
| 19 | + stdout=subprocess.PIPE, |
| 20 | + ) |
| 21 | + return result.stdout.decode("utf-8") |
| 22 | + except Exception as e: |
| 23 | + print(f"Error: {e}") |
| 24 | + return None |
| 25 | + |
| 26 | + |
| 27 | +def update_changelog(commits): |
| 28 | + """ |
| 29 | + Update the changelog.md file with the latest commits. |
| 30 | + """ |
| 31 | + if not commits: |
| 32 | + print("No new commits to add to changelog.") |
| 33 | + return |
| 34 | + |
| 35 | + changelog_path = "changelog.md" |
| 36 | + current_date = datetime.datetime.now().strftime("%Y-%m-%d") |
| 37 | + |
| 38 | + with open(changelog_path, "a") as changelog_file: |
| 39 | + changelog_file.write(f"\n## {current_date}\n") |
| 40 | + changelog_file.write(commits) |
| 41 | + changelog_file.write("\n") |
| 42 | + |
| 43 | + print(f"Changelog updated with {len(commits.splitlines())} new commits.") |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + # Get the latest commits from the past week |
| 48 | + latest_commits = get_latest_commits() |
| 49 | + |
| 50 | + # Update the changelog with the latest commits |
| 51 | + update_changelog(latest_commits) |
0 commit comments