Created
October 16, 2017 13:49
-
-
Save viklund/0636ee016015c6147e224e0b5a78427b to your computer and use it in GitHub Desktop.
Number of commits per repo on the NBISweden github repo
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 'octokit' | |
require 'set' | |
def repo_name(repo) | |
return ORG + "/" + repo[:name] | |
end | |
ORG = "NBISweden" | |
begin | |
token = File.read('token').chomp! | |
rescue | |
puts "Can't find file 'token' with github token" | |
exit | |
end | |
Octokit.configure do |c| | |
c.access_token = token | |
c.auto_paginate = true | |
end | |
repos = Octokit.organization_repositories(ORG) | |
# When checking all branches, we get the same commit multiple times at diverge | |
# and merge points | |
seen_commits = Set.new | |
start_date = "2017-08-01" | |
repos.each do |r| | |
commits = 0 | |
name = repo_name(r) | |
print name | |
Octokit.branches(name).each do |b| | |
branch_commits = Octokit.commits_since(name, start_date, b[:name]) | |
branch_commits = Set.new branch_commits.map { |c| c[:sha] } | |
new_commits = branch_commits - seen_commits | |
commits += new_commits.count | |
seen_commits += new_commits | |
end | |
printf " %d\n", commits | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment