Skip to content

Instantly share code, notes, and snippets.

@ringvold
Created August 15, 2016 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ringvold/b2925b79f7210738aba2f8f537f066a4 to your computer and use it in GitHub Desktop.
Save ringvold/b2925b79f7210738aba2f8f537f066a4 to your computer and use it in GitHub Desktop.
require "date"
require "json"
def log_to_hash
commits = []
res = %x(git log --date=iso --pretty=format:'{\"short_hash\":\"%h\",\"name\":\"%an\",\"email\":\"%ae\",\"date\":\"%ad\",\"subject\":\"%s\"}')
res.each_line do |line|
commits << JSON.parse(line, {symbolize_names: true})
end
return commits
end
def get_commits_in_work_hours(commits)
work_commits = []
return commits.select do |com|
date = com[:date]
day = DateTime.parse(date)
start_hour = DateTime.new(day.year, day.month, day.day, 8, 0, 0, 0)
end_hour = DateTime.new(day.year, day.month, day.day, 17, 0, 0, 0)
(start_hour.to_time.to_i..end_hour.to_time.to_i) === day.to_time.to_i
end
end
def output(all, work)
puts "Commit in business hours: "
work.each do |c|
puts "#{c[:name]} #{c[:date]} #{c[:short_hash]} #{c[:subject]}"
end
3.times {puts}
puts '###############'
puts "# Commits at work: #{work.size}"
puts "# Commits at home: #{all.size-work.size}"
puts '###############'
end
def print_work_hashes(commits)
commits.each {|c| puts c[:short_hash]}
end
res = log_to_hash()
work_commits = get_commits_in_work_hours(res)
# output(res,work_commits)
print_work_hashes(work_commits)
@ringvold
Copy link
Author

print_work_hashes() can be used with xargs and git show to see the changes in the commits: ruby get_work_hours_commits.rb | xargs git show

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment