Skip to content

Instantly share code, notes, and snippets.

@lucaong
Forked from AndrewRadev/git-standup
Last active January 15, 2021 16:30
Show Gist options
  • Save lucaong/5568500 to your computer and use it in GitHub Desktop.
Save lucaong/5568500 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require 'date'
require 'fileutils'
require 'optparse'
def parse_cli_options
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: git standup [--since=<date>] [--author=<name>]"
opts.on("--since [OPTIONAL]", "Show commits more recent that a specific date (defaults to a weekend-aware guess of last working day)") do |since|
options[:since] = since
end
opts.on("--author [OPTIONAL]", "Show only commits from a particular author (defaults to the user defined in .gitconfig)") do |author|
options[:author] = author
end
opts.on("-v", "--verbose", "Show more commit info, like author and timestamp") do |verbose|
options[:verbose] = verbose
end
end.parse!
options
end
def output_log(options={})
# TODO (2013-05-13) Branch info would be nice
log_format = "%Cred%h%Creset -%Creset %s#{ '%Cgreen(%cD) %C(bold blue)<%an>' if options[:verbose] }%Creset"
author = options[:author] || %x[git config user.email].strip
today = Time.now.to_date
week_day = Date::DAYNAMES[today.wday]
if week_day == 'Monday'
last_working_day = today - 3
else
last_working_day = today - 1
end
%x<git log --pretty=format:"#{log_format}" --since="#{options[:since] || last_working_day.to_s}" --author="#{author}">
end
options = parse_cli_options
if File.directory?('.git')
puts output_log(options)
end
Dir['*/.git'].each do |git_dir|
project_dir = File.dirname(git_dir)
project_log = nil
FileUtils.cd(project_dir) do
project_log = output_log(options).strip
end
if project_log != ''
header = ">> Project: #{project_dir}"
puts "=" * header.size
puts header
puts "=" * header.size
puts project_log
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment