-
-
Save tkarpinski/2369729 to your computer and use it in GitHub Desktop.
Exports Github issues to CSV (API v3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'octokit' | |
require 'csv' | |
require 'date' | |
# Github credentials to access your private project | |
USERNAME="USER_NAME" | |
PASSWORD="SEKRIT" | |
# Project you want to export issues from | |
USER="REPO_OWNER" | |
PROJECT="REPO_NAME" | |
# Your local timezone offset to convert times | |
TIMEZONE_OFFSET="-4" | |
client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD) | |
csv = CSV.new(File.open(File.dirname(__FILE__) + "/issues3.csv", 'w')) | |
puts "Initialising CSV file..." | |
#CSV Headers | |
header = [ | |
"Summary", | |
"Description", | |
"Date created", | |
"Date modified", | |
"Issue type", | |
"Milestone", | |
"Priority", | |
"Status", | |
"Reporter" | |
] | |
# We need to add a column for each comment, so this dictates how many comments for each issue you want to support | |
#20.times { header << "Comments" } | |
csv << header | |
puts "Getting issues from Github..." | |
temp_issues = [] | |
issues = [] | |
page = 0 | |
begin | |
page = page +1 | |
temp_issues = client.list_issues("#{USER}/#{PROJECT}", :state => "closed", :page => page) | |
issues = issues + temp_issues; | |
end while not temp_issues.empty? | |
temp_issues = [] | |
page = 0 | |
begin | |
page = page +1 | |
temp_issues = client.list_issues("#{USER}/#{PROJECT}", :state => "open", :page => page) | |
issues = issues + temp_issues; | |
end while not temp_issues.empty? | |
puts "Processing #{issues.size} issues..." | |
issues.each do |issue| | |
puts "Processing issue #{issue['number']}..." | |
# Work out the type based on our existing labels | |
case | |
when issue['labels'].to_s =~ /Bug/i | |
type = "Bug" | |
when issue['labels'].to_s =~ /Feature/i | |
type = "New feature" | |
when issue['labels'].to_s =~ /Task/i | |
type = "Task" | |
end | |
# Work out the priority based on our existing labels | |
case | |
when issue['labels'].to_s =~ /HIGH/i | |
priority = "Critical" | |
when issue['labels'].to_s =~ /MEDIUM/i | |
priority = "Major" | |
when issue['labels'].to_s =~ /LOW/i | |
priority = "Minor" | |
end | |
milestone = issue['milestone'] || "None" | |
if (milestone != "None") | |
milestone = milestone['title'] | |
end | |
# Needs to match the header order above, date format are based on Jira default | |
row = [ | |
issue['title'], | |
issue['body'], | |
DateTime.parse(issue['created_at']).new_offset(TIMEZONE_OFFSET).strftime("%d/%b/%y %l:%M %p"), | |
DateTime.parse(issue['updated_at']).new_offset(TIMEZONE_OFFSET).strftime("%d/%b/%y %l:%M %p"), | |
type, | |
milestone, | |
priority, | |
issue['state'], | |
issue['user']['login'] | |
] | |
csv << row | |
end |
@laurencesmithever probably too late, but you add this line: (note that introduces a security problem)
Octokit.configure do |c|
c.connection_options = { ssl: { verify: false } }
end
I get this error:
Initialising CSV file...
Getting issues from Github...
Processing 570 issues...
Processing issue 564...
./github_issues_to_csv.rb:85:in `parse': no implicit conversion of Time into String (TypeError)
from ./github_issues_to_csv.rb:85:in `block in <main>'
from ./github_issues_to_csv.rb:55:in `each'
from ./github_issues_to_csv.rb:55:in `<main>'
i get the same as @dylanjw
It can be fixed by updating the two lines that parse the date time to this
issue['created_at'],
issue['updated_at'],
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Having a little problem. When I run github_issues_to_csv.rb I get the following:
C:\Ruby193>ruby github_issues_to_csv.rb
'Initialising CSV file...
Getting issues from Github...
C:/Ruby193/lib/ruby/1.9.1/net/http.rb:799:in
connect': SSL_connect returned=1 e rrno=0 state=SSLv3 read server certificate B: certificate verify failed (Faraday ::Error::ConnectionFailed) from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:799:in
block in connect'from C:/Ruby193/lib/ruby/1.9.1/timeout.rb:54:in
timeout' from C:/Ruby193/lib/ruby/1.9.1/timeout.rb:99:in
timeout'from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:799:in
connect' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:755:in
do_start'from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:744:in
start' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1284:in
request'from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1026:in
get' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday-0.8.4/lib/faraday/adapt er/net_http.rb:72:in
perform_request'from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday-0.8.4/lib/faraday/adapt
er/net_http.rb:37:in
call' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/fa raday_middleware/response_middleware.rb:30:in
call'from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday-0.8.4/lib/faraday/respo
nse.rb:8:in
call' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/fa raday_middleware/response/follow_redirects.rb:79:in
perform_with_redirection'from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/fa
raday_middleware/response/follow_redirects.rb:65:in
call' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday-0.8.4/lib/faraday/respo nse.rb:8:in
call'from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/fa
raday_middleware/request/encode_json.rb:23:in
call' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday-0.8.4/lib/faraday/conne ction.rb:226:in
run_request'from C:/Ruby193/lib/ruby/gems/1.9.1/gems/faraday-0.8.4/lib/faraday/conne
ction.rb:87:in
get' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/octokit-1.22.0/lib/octokit/requ est.rb:61:in
request'from C:/Ruby193/lib/ruby/gems/1.9.1/gems/octokit-1.22.0/lib/octokit/requ
est.rb:11:in
get' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/octokit-1.22.0/lib/octokit/clie nt/issues.rb:42:in
list_issues'from github_issues_to_csv.rb:42:in `
Can you help?
Thanks.