Skip to content

Instantly share code, notes, and snippets.

@hcrub
Created November 6, 2013 19:56
Show Gist options
  • Save hcrub/7343064 to your computer and use it in GitHub Desktop.
Save hcrub/7343064 to your computer and use it in GitHub Desktop.
Imports and Sorts Github issues into CSV File
###################################################
# Neil Burchfield
# Nov 6, 2013
# Imports and Sorts Github issues into CSV File
###################################################
require 'octokit'
require 'csv'
require 'date'
###################################################
# Enter Your Github Credentials
###################################################
USERNAME="----"
PASSWORD="----"
###################################################
# Enter The Repository Owner's Name
###################################################
OWNER="----"
###################################################
# Enter The Repository Name
###################################################
PROJECT="----"
###################################################
# Enter The Desired CSV Filename
###################################################
FILENAME="----"
###################################################
# TimeZone Offset (e.g. Central -> Chicago)
# Find yours @ http://upload.wikimedia.org/wikipedia/commons/8/88/World_Time_Zones_Map.png
###################################################
TIMEZONE_OFFSET="-6"
###################################################
# Initilize Client With Credentials
###################################################
client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD)
###################################################
# Initilize CSV File With Write Capability
###################################################
csv = CSV.new(File.open(File.dirname(__FILE__) + "/${FILENAME}.csv", 'w'))
###################################################
# CSV File Header Schema
###################################################
header = [
"Title",
"Description",
"Date created",
"Date modified",
"Issue type",
"Milestone",
"Priority",
"Status",
"Owner"
]
###################################################
# Output Header into CSV
###################################################
csv << header
###################################################
# Initilize Empty Buffers
###################################################
temp_issues = []
issues = []
page = 0
puts "Fetching GHub Issues"
###################################################
# Begin Iterating Through Pages
###################################################
begin
###################################################
# Increment Page Num, Store Open Issues, and Add
###################################################
page = page +1
temp_issues = client.list_issues("#{OWNER}/#{PROJECT}", :state => "closed", :page => page)
issues = issues + temp_issues;
end while not temp_issues.empty?
###################################################
# Initilize Empty Buffers
###################################################
temp_issues = []
page = 0
begin
###################################################
# Increment Page Num, Store Open Issues, and Add
###################################################
page = page + 1
temp_issues = client.list_issues("#{OWNER}/#{PROJECT}", :state => "open", :page => page)
issues = issues + temp_issues;
end while not temp_issues.empty?
###################################################
# Begin Iterating Through Issues
###################################################
issues.each do |issue|
puts "Adding issue #{issue['title']}..."
###################################################
# Sort Issues Based on Bugs, Features, Tasks
###################################################
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
###################################################
# Modify based on your custom 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
###################################################
# Create row hash
###################################################
row = [
issue['title'],
issue['body'],
issue['created_at'],
issue['modified_at'],
type,
milestone,
priority,
issue['state'],
issue['user']['login']
]
###################################################
# Insert Row Into CSV
###################################################
csv << row
end
@chrisvanfossen
Copy link

@hcrub Woo, worked as expected (after trying a few other failed scripts). Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment