Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@opennomad
Last active October 1, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opennomad/2db251ac94d49e3530f9 to your computer and use it in GitHub Desktop.
Save opennomad/2db251ac94d49e3530f9 to your computer and use it in GitHub Desktop.
Simple way to export all issues from a github repo using token authentication
#!/usr/bin/env ruby
# Simple script to pull all issues from a github repo.
# Simply create an authentication token in github
# Then set the environment variable GITHUB_TOKEN to that
# then run the script passing the <owner>/<repo> as the one and only parameter
# output will be in JSON form. From there you can use jq - https://stedolan.github.io/jq/
# For example: cat file.json| jq '.[] | .user.login, .title, .body' etc.
# requires octokit and json module
require "octokit"
require "json"
repo = ARGV[0]
if not repo
puts "error: must provide the owner/repo as argument"
exit 1
end
client = Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"])
# some of the Sawyer objects don't resolve completely. This is a poor mans way to converting
# the necessary ones
def convert_to_object(o)
if o.user then
o.user = o.user.to_hash
end
if o.assignee then
o.assignee = o.assignee.to_hash
end
if o.labels then
o.labels.each_with_index do |val,index|
o.labels[index] = val.to_hash
end
end
if o.pull_request then
o.pull_request = o.pull_request.to_hash
end
return o.to_hash
end
user = client.user
user.login
client.auto_paginate = true
issues = client.issues repo, { :state => 'all' }
puts "["
issues.each_with_index { |issue,index|
issue.comments = []
client.issue_comments(repo, issue.number).each do |comment|
comment = (comment)
issue.comments.push convert_to_object(comment)
end
issue.user = issue.user.to_hash
puts convert_to_object(issue).to_json
if index != issues.size - 1
puts ","
end
}
puts "]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment