Skip to content

Instantly share code, notes, and snippets.

@Happy-Ferret
Forked from badboy/README.md
Created November 7, 2018 12:41
Show Gist options
  • Save Happy-Ferret/3e65a5d3c809cbdce41a7dcaeda310b5 to your computer and use it in GitHub Desktop.
Save Happy-Ferret/3e65a5d3c809cbdce41a7dcaeda310b5 to your computer and use it in GitHub Desktop.
Save github issues offline.

First install the required gems:

gem install octokit awesomeprint rainbow

Then run it to extract all of your open GitHub issues into files (with comments).

ruby my-gh-issues.rb

Take a look at the issue directory for all issues. Pass specific repositories to only pull those issues.

ruby my-gh-issues.rb cancan railscasts

Note, you may get a 403 error if you have a lot of issues. I'm guessing this is because GitHub is throttling how many requests you can send. Just run the script again and it will skip over the already pulled issues.

Special thanks to the creator of this original gist and the authors of the gems.

#!/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 => %x[ git config --get github.user ].strip,
:oauth_token => %x[ git config --get github.token ].strip
}
client = Octokit::Client.new( options )
key_width = 15
label_color = Hash.new( :cyan )
label_color['bug'] = :red
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
client.issues( repo.full_name ).each do |issue|
print ("%3d : " % issue.number).rjust( key_width).foreground( :white ).bright
labels = []
unless issue.labels.empty?
issue.labels.each do |l|
labels << l.name.foreground( label_color[l] ).bright
end
end
print labels.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.login} 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.login} on #{comment.created_at}"
f.puts
f.puts comment.body
f.puts
end
end
end
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment