Skip to content

Instantly share code, notes, and snippets.

@patrickmj
Forked from kevinpschaaf/github_issues_to_csv_v3.rb
Last active December 24, 2015 12:49
Show Gist options
  • Save patrickmj/6800429 to your computer and use it in GitHub Desktop.
Save patrickmj/6800429 to your computer and use it in GitHub Desktop.
require 'octokit'
require 'csv'
require 'date'
# Description:
# Exports Github issues from one or more repos into CSV file formatted for import into JIRA
# Note: By default, all Github comments will be assigned to the JIRA admin, appended with
# a note indicating the Github user who added the comment (since you may not have JIRA users
# created for all your Github users, especially if it is a public/open-source project:
#
# Administrator added a comment - 13/Jun/12 5:13 PM
# Imported from Github issue xyz-123, originally reported by ubercoder42
#
# Administrator added a comment - 12/Jun/12 10:00 AM
# Github comment from ubercoder42: [Text from first comment here...]
# Usage:
# > ruby github_issues_to_csv_v3.rb <JIRA admin username> <Github username> <Github password> <Github project/user> <repo 1> .. <repo n>
# Your local timezone offset to convert times -- CHANGE THESE TO MATCH YOUR SETTINGS
TIMEZONE_OFFSET="-8"
COMMENT_DATE_FORMAT="%m/%d/%Y %T"
OTHER_DATE_FORMAT="%-m/%-d/%y %H:%M" # Don't change this; Comments must be in this format
COMMENT_NOW = DateTime.now.new_offset(TIMEZONE_OFFSET).strftime(COMMENT_DATE_FORMAT)
# Grab command line args
JIRA_ADMIN=ARGV.shift
USERNAME=ARGV.shift
PASSWORD=ARGV.shift
USER=ARGV.shift
client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD)
csv = CSV.new(File.open(File.dirname(__FILE__) + "/issues_#{USER}.csv", 'w'), :force_quotes=>true)
puts "Initialising CSV file..."
#CSV Headers
header = [
"Summary",
"Description",
"Issue type",
"Status",
"Reporter",
"Github repo",
"Github number"
]
# We need to add a column for each comment, so this dictates how many comments for each issue you want to support
csv << header
ARGV.each do |project|
puts "Getting issues from #{project}..."
temp_issues = []
issues = []
page = 0
begin
page = page +1
page = page.to_i
temp_issues = client.list_issues("omeka/Omeka3", :state => "closed", :page => page, :label => "User Story")
issues = issues + temp_issues;
end while not temp_issues.empty?
temp_issues = []
page = 0
begin
page = page +1
temp_issues = client.list_issues("omeka/Omeka3", :state => "open", :page => page, :label => "User Story")
issues = issues + temp_issues;
end while not temp_issues.empty?
puts "Processing #{issues.size} issues..."
issues.each do |issue|
puts "Processing issue #{project}-#{issue['number']}..."
type = "User Story"
# Needs to match the header order above
row = [
issue['title'],
issue['body'],
type,
issue['state'],
issue['user']['login'],
project,
"#{project}-#{issue['number']}"
]
row << "#{COMMENT_NOW}; #{JIRA_ADMIN}; Imported from Github issue #{project}-#{issue['number']}, originally reported by #{issue['user']['login']}"
csv << row
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment