kevinjalbert
5/1/2014 - 8:24 PM

Show all of your git commits that happened since the last work day

Show all of your git commits that happened since the last work day

#!/usr/bin/env ruby
require 'date'

COMMITTER = 'kevin.j.jalbert'

def last_work_day(date)
  if date.monday?
    (date.to_date - 3).httpdate
  else
    (date.to_date - 1).httpdate
  end
end

def print_standup_results(dir)
  results = `git --no-pager --git-dir #{dir}/.git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(green)<%an>%Creset' --abbrev-commit --date=relative --committer='#{COMMITTER}' --all --since="#{last_work_day(Date.today)}"`

  if !results.empty?
    puts "\n::#{dir}::"
    puts results
  end
end

puts "----------------------"
puts "::Git Standup Report::"
puts "----------------------"

if File.exist? "#{Dir.pwd}/.git"
  print_standup_results(Dir.pwd)
else
  Dir.glob('*').select do |dir|
    if File.directory? dir
      git_dir = "#{dir}/.git"

      if File.exist? git_dir
        print_standup_results(dir)
      end
    end
  end
end