Last active
July 31, 2018 10:19
-
-
Save fbacall/ef30e2fdff317ba2a1b6b41a9768624a to your computer and use it in GitHub Desktop.
List all commits pushed to github this week
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'json' | |
USER = 'YOUR-GITHUB-USERNAME' | |
# Generate a token with "repo" scope enabled: https://github.com/settings/tokens/new | |
TOKEN = 'YOUR-PERSONAL-ACCESS-TOKEN' | |
today = Date.today | |
sunday = today - today.wday | |
monday = today - (today.wday - 1) % 7 | |
start_time = monday.to_time # Midnight on Monday | |
events = [] | |
page = 1 | |
# Get all events from this week | |
loop do | |
json = open("https://api.github.com/users/#{USER}/events?access_token=#{TOKEN}&page=#{page}").read | |
events += JSON.parse(json) | |
break if Time.parse(events.last['created_at']) < start_time | |
page += 1 | |
sleep 1 | |
end | |
# Parse time | |
events.each do |event| | |
event['time'] = Time.parse(event['created_at']) | |
end | |
# Select this week's PushEvents | |
events.select! do |event| | |
event['type'] == 'PushEvent' && | |
event['time'] >= start_time | |
end | |
# Group by day of week | |
grouped = events.group_by do |event| | |
"#{event['time'].iso8601[0..9]} (#{event['time'].strftime('%A')})" | |
end | |
grouped.each do |day, events| | |
puts day | |
events.each do |event| | |
repo = event['repo']['name'] | |
event['payload']['commits'].each do |commit| | |
puts " #{repo} - #{commit['message']}" | |
end | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment