Skip to content

Instantly share code, notes, and snippets.

@viklund
Created October 16, 2017 13:49
Show Gist options
  • Save viklund/0636ee016015c6147e224e0b5a78427b to your computer and use it in GitHub Desktop.
Save viklund/0636ee016015c6147e224e0b5a78427b to your computer and use it in GitHub Desktop.
Number of commits per repo on the NBISweden github repo
#!/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