notamitgamer

It's my profile man, there is ...
Log | Files | Refs | README

commit 166f95dc8b032a01fb5bb717783a904734e80193
parent dd58b715bb84a6c1f3dbac747ac5252a029f67b7
Author: Amit Dutta <amitdutta4255@gmail.com>
Date:   Mon,  4 May 2026 21:01:26 +0530

Add script to update README with recent GitHub commits

This script fetches recent commits from a GitHub user and updates the README.md file with the latest commit messages formatted as a markdown list.
Diffstat:
A.github/scripts/update_commits.py | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+), 0 deletions(-)

diff --git a/.github/scripts/update_commits.py b/.github/scripts/update_commits.py @@ -0,0 +1,69 @@ +import urllib.request +import json +import re + +USERNAME = "notamitgamer" +API_URL = f"https://api.github.com/users/{USERNAME}/events/public" + +def fetch_recent_commits(): + try: + # Create a request object with a User-Agent (GitHub API requires it) + req = urllib.request.Request(API_URL) + req.add_header('User-Agent', f'{USERNAME}-readme-updater') + + with urllib.request.urlopen(req) as response: + data = json.loads(response.read().decode()) + + commits = [] + for event in data: + # We only care about events where you pushed code + if event['type'] == 'PushEvent': + repo_name = event['repo']['name'] + for commit in event['payload']['commits']: + # Extract the first line of the commit message (removes long descriptions) + msg = commit['message'].split('\n')[0] + + # The API returns an api.github.com URL, we need to convert it to a standard web URL + url = commit['url'].replace('api.github.com/repos', 'github.com').replace('/commits/', '/commit/') + + # Format as a markdown list item + commits.append(f"- [{msg}]({url}) in [{repo_name}](https://github.com/{repo_name})") + + # Stop once we have 5 commits + if len(commits) >= 5: + return commits + + return commits + + except Exception as e: + print(f"Error fetching commits: {e}") + return [] + +def update_readme(commits): + if not commits: + print("No commits found to update.") + return + + commit_list_md = "\n".join(commits) + + # Read the current README.md + with open('README.md', 'r', encoding='utf-8') as f: + readme = f.read() + + # Use regex to replace everything between the HTML comments + updated_readme = re.sub( + r"(?<=<!-- START_RECENT_COMMITS -->\n).*?(?=\n<!-- END_RECENT_COMMITS -->)", + commit_list_md, + readme, + flags=re.DOTALL + ) + + # Write the updated content back to README.md + with open('README.md', 'w', encoding='utf-8') as f: + f.write(updated_readme) + + print("README.md successfully updated!") + +if __name__ == "__main__": + recent_commits = fetch_recent_commits() + update_readme(recent_commits)
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror