My current work requires me to submit weekly reports and so did some other jobs that I’ve had in the past.
To help with that task, I wrote the following script that:
- Goes through every one of my git repos
- Checks if I’ve made any commits in the past week
- If I did, prints the repo name and the commits that I’ve made
After that, I can just copy paste my commits and use them to put together my report.
alexkras.com - Fix typo in git tips - Updated README - Update to published version - Wrote explanation for nested scope debuggin some-other-repo - Some other commit - Yet some other commit
All you have to do to run this script
- Copy it to some folder in your PATH
BASEpath, to wherever all your git repos reside
USERNAMEto your name, as it is configured in git
- Optionally, you can change the time period from
1 week agoto whatever you would like.
Code language: PHP (php)
#!/usr/bin/env python import commands import os BASE = '/Users/alex/projects' USERNAME = 'Alex Kras' repos = os.listdir(BASE) repos = [os.path.join(BASE, repo) for repo in repos] commits = "" for dir in repos: command = 'cd ' + dir + ' && git log --branches=* ' + \ '--author="' + USERNAME + '" --after="1 week ago" --oneline --reverse' commits = commands.getstatusoutput(command) if( len(commits) > 0 and "Not a directory" not in commits and "Not a git repository" not in commits ): print os.path.relpath(dir, BASE) # Remove hash commits = [' '.join(['-'] + commit.split(' ')[1:]) for commit in commits.split('\n')] print '\n'.join(commits) + '\n'
How does it work?
I’ve explained underling git command in detail in 19 Git Tips for Everyday Use. In summary it uses python to walk all of the directories. For every directory the script runs
git log command, restricted to specific user name (me) and time period (1 week).
I am sure it can be improved, but it works for me in this simple form.