Tech TLDR;

  • Archive
  • Top Posts
  • GitHub
  • LinkedIn
  • Contact

Generate Weekly Reports from Your Git Commits

August 13, 2016 by admin

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:

  1. Goes through every one of my git repos
  2. Checks if I’ve made any commits in the past week
  3. 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.

Sample Output

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

  1. Copy it to some folder in your PATH
  2. Change BASE path, to wherever all your git repos reside
  3. Change USERNAME to your name, as it is configured in git
  4. Optionally, you can change the time period from 1 week ago to whatever you would like.
#!/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)[1]
    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'
Code language: PHP (php)

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.

Filed Under: Git, Tools Tagged With: git

Copyright © 2025 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in