|
#!/usr/bin/env ruby |
|
|
|
# |
|
# A quick script to dump an overview of all the open issues in all my github projects |
|
# |
|
|
|
require 'fileutils' |
|
require 'octokit' |
|
require 'awesome_print' |
|
require 'rainbow' |
|
|
|
repos = $* |
|
|
|
options = { |
|
:login => "username", |
|
:password => "*********" |
|
} |
|
|
|
client = Octokit::Client.new( options ) |
|
key_width = 15 |
|
label_color = Hash.new( :cyan ) |
|
|
|
label_color['p0'] = :red |
|
label_color['p1'] = :yellow |
|
label_color['p2'] = :black |
|
label_color['feature'] = :green |
|
label_color['todo'] = :blue |
|
|
|
client.list_repos.each do |repo| |
|
next if repo.fork |
|
next unless repo.open_issues > 0 |
|
next if repos.size > 0 && !repos.include?(repo.name) |
|
|
|
print "Repository : ".rjust( key_width ).foreground( :green ).bright |
|
puts repo.name |
|
FileUtils.mkdir_p("issues/#{repo.name}") unless File.exist? "issues/#{repo.name}" |
|
|
|
print "Issue Count : ".rjust( key_width ).foreground( :yellow ).bright |
|
puts repo.open_issues |
|
|
|
issues = []; |
|
i = 1; |
|
|
|
# why is the github api paged? Did i miss something? |
|
while issues.length < repo.open_issues do |
|
issues.concat client.issues(repo.full_name, :page => i) |
|
i += 1 |
|
end |
|
|
|
issues.each do |issue| |
|
print ("%3d : " % issue.number).rjust( key_width).foreground( :white ).bright |
|
labels = [] |
|
if not issue.labels.empty? then |
|
issue.labels.each do |l| |
|
labels << l.name.foreground( label_color[l.name] ).bright |
|
end |
|
end |
|
print labels.collect { |n| n.is_a?(String) ? n : n.name } .join(' ') + " " |
|
puts issue.title |
|
path = "issues/#{repo.name}/issue-#{issue.number}.txt" |
|
unless File.exist? path |
|
File.open(path, "w") do |f| |
|
comments = client.issue_comments(repo.full_name, issue.number) |
|
f.puts "\##{issue.number} #{issue.title}" |
|
f.puts "By #{issue.user} on #{issue.created_at}" |
|
f.puts "Labels: #{issue.labels.join(" ")}" unless issue.labels.empty? |
|
f.puts |
|
f.puts issue.body |
|
f.puts |
|
f.puts "Comments: #{comments.size}" |
|
comments.each do |comment| |
|
f.puts "--------" |
|
f.puts "From #{comment.user} on #{comment.created_at}" |
|
f.puts |
|
f.puts comment.body |
|
f.puts |
|
end |
|
end |
|
end |
|
end |
|
puts |
|
end |