Guest User

Untitled

a guest
Dec 26th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. require 'octokit'
  2. require 'csv'
  3. require 'date'
  4. # Github credentials to access your private project
  5. USERNAME="USER_NAME"
  6. PASSWORD="SEKRIT"
  7.  
  8. # Project you want to export issues from
  9. USER="REPO_OWNER"
  10. PROJECT="REPO_NAME"
  11.  
  12. # Your local timezone offset to convert times
  13. TIMEZONE_OFFSET="-4"
  14.  
  15. client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD)
  16.  
  17. csv = CSV.new(File.open(File.dirname(__FILE__) + "/issues3.csv", 'w'))
  18.  
  19. puts "Initialising CSV file..."
  20. #CSV Headers
  21. header = [
  22. "Summary",
  23. "Description",
  24. "Date created",
  25. "Date modified",
  26. "Issue type",
  27. "Milestone",
  28. "Priority",
  29. "Status",
  30. "Reporter"
  31. ]
  32. # We need to add a column for each comment, so this dictates how many comments for each issue you want to support
  33. #20.times { header << "Comments" }
  34. csv << header
  35.  
  36. puts "Getting issues from Github..."
  37. temp_issues = []
  38. issues = []
  39. page = 0
  40. begin
  41. page = page +1
  42. temp_issues = client.list_issues("#{USER}/#{PROJECT}", :state => "closed", :page => page)
  43. issues = issues + temp_issues;
  44. end while not temp_issues.empty?
  45. temp_issues = []
  46. page = 0
  47. begin
  48. page = page +1
  49. temp_issues = client.list_issues("#{USER}/#{PROJECT}", :state => "open", :page => page)
  50. issues = issues + temp_issues;
  51. end while not temp_issues.empty?
  52.  
  53.  
  54. puts "Processing #{issues.size} issues..."
  55. issues.each do |issue|
  56. puts "Processing issue #{issue['number']}..."
  57. # Work out the type based on our existing labels
  58. case
  59. when issue['labels'].to_s =~ /Bug/i
  60. type = "Bug"
  61. when issue['labels'].to_s =~ /Feature/i
  62. type = "New feature"
  63. when issue['labels'].to_s =~ /Task/i
  64. type = "Task"
  65. end
  66.  
  67. # Work out the priority based on our existing labels
  68. case
  69. when issue['labels'].to_s =~ /HIGH/i
  70. priority = "Critical"
  71. when issue['labels'].to_s =~ /MEDIUM/i
  72. priority = "Major"
  73. when issue['labels'].to_s =~ /LOW/i
  74. priority = "Minor"
  75. end
  76. milestone = issue['milestone'] || "None"
  77. if (milestone != "None")
  78. milestone = milestone['title']
  79. end
  80.  
  81. # Needs to match the header order above, date format are based on Jira default
  82. row = [
  83. issue['title'],
  84. issue['body'],
  85. DateTime.parse(issue['created_at']).new_offset(TIMEZONE_OFFSET).strftime("%d/%b/%y %l:%M %p"),
  86. DateTime.parse(issue['updated_at']).new_offset(TIMEZONE_OFFSET).strftime("%d/%b/%y %l:%M %p"),
  87. type,
  88. milestone,
  89. priority,
  90. issue['state'],
  91. issue['user']['login']
  92. ]
  93. csv << row
  94. end
Add Comment
Please, Sign In to add comment