Skip to content

Instantly share code, notes, and snippets.

@akm
Created August 31, 2015 09:46
Show Gist options
  • Save akm/c239183e57ef82464dcf to your computer and use it in GitHub Desktop.
Save akm/c239183e57ef82464dcf to your computer and use it in GitHub Desktop.
require 'logger'
require 'github_api'
require 'active_support/core_ext/object'
class IssueApi
attr_accessor :org, :repo
attr_reader :logger
def initialize
@org = ENV["GITHUB_DEFAULT_ORGANIZATION"]
@repo = ENV["GITHUB_DEFAULT_REPOGITORY"]
@logger = Logger.new($stdout)
end
def impl
@impl ||= Github::Client::Issues.new(:oauth_token => ENV['GITHUB_OAUTH_TOKEN'])
end
def issues(options = {})
impl.list({state: "all", filter: "all", org: org}.update(options))
end
def each_issue(options = {}, &block)
options[:page] = 1
begin
results = issues(options)
results.each(&block)
options[:page] += 1
logger.debug(" results.length: #{results.length}")
end until results.length == 0
end
end
api = IssueApi.new
result = {}
api.each_issue(labels: "bug") do |i|
ms = i.milestone.try(:title) || "none"
result[ms] ||= {}
i.labels.each do |label|
result[ms][label.name] ||= 0
result[ms][label.name] += 1
end
end; nil
result
milestones = %w[beta6 trdb-riak beta7 GA]
labels = milestones.map{|ms| result[ms].keys}.flatten.uniq.sort - ["bug"]
labels.unshift("bug")
fmt = "%#{labels.map(&:length).max}s " << milestones.map{|ms| "%#{ms.length}s" }.join(" ")
lines = []
lines << fmt % (["label"] + milestones)
labels.each do |label|
values = [label]
milestones.each{|ms| values << (result[ms][label] || '-').to_s}
lines << (fmt % values)
end
puts lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment