Skip to content

Instantly share code, notes, and snippets.

@yatemmma
Last active June 13, 2017 06:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yatemmma/9855856 to your computer and use it in GitHub Desktop.
Save yatemmma/9855856 to your computer and use it in GitHub Desktop.
gh2csv - GitHub issues export to csv.
user:
name: yatemmma
pass: hogehoge
repo:
user: yatemmma
project: hogehoge
source 'https://rubygems.org'
gem 'octokit'
require 'octokit'
require 'csv'
require 'yaml'
config = YAML.load_file("config.yaml")
USERNAME = config["user"]["name"]
PASSWORD = config["user"]["pass"]
USER = config["repo"]["user"]
PROJECT = config["repo"]["project"]
repogitory = "#{USER}/#{PROJECT}"
csv_filename = "#{USER}.#{PROJECT}.#{Time.new.strftime('%Y%m%d%H%M%S')}.csv"
puts "Export github issues. #{repogitory}"
Octokit.configure do |configure|
configure.connection_options = { ssl: { verify: false } }
end
client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD)
issues = client.list_issues(repogitory, :state => "open")
issues += client.list_issues(repogitory, :state => "closed")
puts "Found #{issues.size} issues."
return if issues.size == 0
csv_header = [
"no",
"number",
"type",
"title",
"user",
"body",
"html_url",
"labels",
"state",
"assignee",
"milestone",
"comments",
"created_at",
"updated_at",
"closed_at",
]
puts "Output csv file. #{csv_filename}"
csv = CSV.new(File.open(File.dirname(__FILE__) + "/" + csv_filename, 'w'))
csv << csv_header
no = 0
issues.each do |issue|
print "."
csv << [
no += 1,
issue[:number],
(issue[:pull_request]) ? "pull request" : "issue",
issue[:title],
issue[:user][:login],
issue[:body],
issue[:html_url],
issue[:labels].map{|label| label.name}.join(","),
issue[:state],
issue[:assignee],
issue[:milestone],
issue[:comments],
issue[:created_at],
issue[:updated_at],
issue[:closed_at],
]
if issue[:comments] > 0
comments = client.issue_comments(repogitory, issue[:number])
comments.each do |comment|
csv << [
no += 1,
issue[:number],
"comment",
"",
comment[:user][:login],
comment[:body],
comment[:html_url],
"",
"",
"",
"",
"",
issue[:created_at],
issue[:updated_at],
"",
]
end
end
if issue[:pull_request]
comments = client.pull_request_comments(repogitory, issue[:number])
comments.each do |comment|
csv << [
no += 1,
issue[:number],
"file comment",
"",
comment[:user][:login],
# diff_hunk is under limit of character number that cell can have.
comment[:diff_hunk] + "\n" + comment[:body],
"",
"",
"",
"",
"",
"",
issue[:created_at],
issue[:updated_at],
"",
]
end
end
end
puts "finished."
puts client.rate_limit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment