Last active
October 14, 2022 04:24
-
-
Save andrew/4702837 to your computer and use it in GitHub Desktop.
Who's done more work on your repo, you or your community?
This file contains hidden or 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
require 'json' | |
require 'open-uri' | |
repo = ENV['REPO'] | |
owner = ENV['OWNER'] || repo.match(/(.+)\//)[1] | |
url = "https://github.com/#{repo}/graphs/contributors-data" | |
doc = open(url).read | |
if doc == ' ' # retry if data not loaded | |
sleep 2 | |
doc = open(url).read | |
end | |
json =JSON.parse(doc) | |
community_adds = 0 | |
community_deletes = 0 | |
owner_adds = 0 | |
owner_deletes = 0 | |
json.each do |person| | |
additions = person['weeks'].map{|w| w['a']}.inject(:+) | |
deletions = person['weeks'].map{|w| w['d']}.inject(:+) | |
if person['author']['login'] == owner | |
owner_adds += additions | |
owner_deletes += deletions | |
else | |
community_adds += additions | |
community_deletes += deletions | |
end | |
end | |
puts "Owner contributions" | |
puts " #{owner_adds} ++" | |
puts " #{owner_deletes} --" | |
puts "\n" | |
puts "Community contributions" | |
puts " #{community_adds} ++" | |
puts " #{community_deletes} --" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment