Skip to content

Instantly share code, notes, and snippets.

@chee
Created August 7, 2012 15:49
Show Gist options
  • Save chee/3286537 to your computer and use it in GitHub Desktop.
Save chee/3286537 to your computer and use it in GitHub Desktop.
Exports Github issues to CSV (API v3)
#!/usr/bin/env ruby
require 'octokit'
require 'csv'
require 'date'
# Github credentials to access your private project
USERNAME="___USERNAME___"
PASSWORD="___PASSWORD___"
# Project you want to export issues from
USER="IRISInc"
PROJECT="Metro"
# Your local timezone offset to convert times
TIMEZONE_OFFSET="-6"
client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD)
csv = CSV.new(File.open(File.dirname(__FILE__) + "/#{USER}-#{PROJECT}-issues.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 "Got #{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 =~ /Enhancement/i
type = "Enhancement"
end
# Work out the priority based on our existing labels
case
when issue['labels'].to_s =~ /^6/
priority = "HF Blocker"
when issue['labels'].to_s =~ /^5/
priority = "Critical"
when issue['labels'].to_s =~ /^4/
priority = "Major"
when issue['labels'].to_s =~ /^3/
priority = "Medium"
when issue['labels'].to_s =~ /^2/
priority = "Minor"
when issue['labels'].to_s =~ /^1/
priority = "would be nice"
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment