Created
November 7, 2015 05:07
-
-
Save tam7t/8521b1c386472607549a to your computer and use it in GitHub Desktop.
Github statistics
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
# plusminus.rb by @tam7t | |
# | |
# Prereqs: | |
# gem install octokit time_diff colorize | |
# | |
# Usage: | |
# API_TOKEN=<GITHUB API TOKEN> ruby plusminus.rb | |
# | |
# Optional Params: | |
# ENDPOINT=<ghe endpoint> | |
# VERBOSE=true | |
require 'octokit' | |
require 'time_diff' | |
require 'colorize' | |
api_endpoint = ENV['ENDPOINT'] || "https://github.com/api/v3/" | |
verbose = ENV['VERBOSE'] || false | |
Octokit.configure do |c| | |
c.api_endpoint = api_endpoint | |
end | |
client = Octokit::Client.new(:access_token => ENV['API_TOKEN']) | |
events = client.user_events(client.user[:login]) | |
while client.last_response.rels[:next] | |
more = client.get(client.last_response.rels[:next].href) | |
events.concat(more) | |
end | |
merged = events.select {|e| e[:type] =='PullRequestEvent' and e[:payload][:pull_request][:merged] } | |
merged = merged.uniq{|m| m[:id]} | |
additions = 0 | |
deletions = 0 | |
merged.each do |m| | |
add = m[:payload][:pull_request][:additions] | |
del = m[:payload][:pull_request][:deletions] | |
puts "+#{add}\t-#{del}\t#{m[:payload][:pull_request][:merged_at]}\t- #{m[:payload][:pull_request][:html_url]}" if verbose | |
additions += add | |
deletions += del | |
end | |
plus = "+#{additions}".green | |
minus = "-#{deletions}".red | |
time = Time.diff(Time.now, merged.map { |a| a[:payload][:pull_request][:merged_at] }.min)[:diff] | |
puts "#{plus} #{minus} in the past #{time}" |
Author
tam7t
commented
Nov 7, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment