module GitHubCSV

Public Class Methods

initialize(curr_username, curr_password, from_username, from_project, timezone) click to toggle source
# File lib/githubcsv/githubcsv.rb, line 16
def self.initialize(curr_username, curr_password, from_username, from_project, timezone) 
  @USERID = curr_username
  @PASSWORD = curr_password
  
  @USER = from_username
  @PROJECT = from_project
  @TIMEZONE_OFFSET = timezone
end
run(directory, is_verbose) click to toggle source
# File lib/githubcsv/githubcsv.rb, line 25
def self.run(directory, is_verbose) 
  Octokit.configure do |c|
    c.connection_options = { ssl: { verify: false } }
  end
  @VERBOSE = is_verbose
  
  client = Octokit::Client.new(:login => @USERID, :password => @PASSWORD)
  if directory.end_with? "/"
    csv = CSV.new(File.open(directory + "issues.csv", 'w'))
  else 
    csv = CSV.new(File.open(directory + "/issues.csv", 'w'))
  end
  
  if @VERBOSE == 1 
    puts "Initializing CSV file..."
  end
  
  #CSV Headers
  header = [
    "Summary",
    "Description",
    "Date created",
    "Date modified",
    "Issue type",
    "Milestone",
    "Priority",
    "Status",
    "Reporter"
  ]

csv << header
 
if @VERBOSE == 1
  puts "Downloading GitHub issues..."
end

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?
 
if @VERBOSE == 1
  puts "Processing #{issues.size} issues..."
end

issues.each do |issue|

  if @VERBOSE == 1
    puts "Processing issue #{issue['number']}..."
  end
  
  #type matching
  case
    when issue['labels'].to_s =~ /Bug/i
      type = "Bug"
    when issue['labels'].to_s =~ /Feature/i
      type = "Feature"
    when issue['labels'].to_s =~ /Task/i
      type = "Task"
  end
 
  #priority matching
  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
 
  #get time and parse it for each issue
  row = [
    issue['title'],
    issue['body'],     
    DateTime.parse(issue['created_at'].to_s).new_offset(@TIMEZONE_OFFSET).strftime("%d/%b/%y %l:%M %p"),
    DateTime.parse(issue['updated_at'].to_s).new_offset(@TIMEZONE_OFFSET).strftime("%d/%b/%y %l:%M %p"),
    type,
    milestone,
    priority,
    issue['state'],
    issue['user']['login']
  ]
  csv << row
  end
end