-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimport_issues_from_bugzilla.rb
102 lines (84 loc) · 2.78 KB
/
import_issues_from_bugzilla.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/ruby -w
# This script imports bugzilla bug reports from an xml file
# to github issues.
# HOW TO RUN:
# gem install octokit xmlsimple
# ruby import_issues_from_bugzilla.rb
require 'octokit'
require 'xmlsimple'
# Provide authentication credentials
# GitHub username
username = ''
# GitHub password or access token
password = ''
# GitHub projects full name: (like 'mrkara/gtranslator')"
repo = ""
# Location of the xml input file on your disk
xmlFile = '.xml'
# Main URL of the bugzilla without the trailing slash (/)
bgzUrl = "https://"
# Bugzilla acronym (like 'bgo' for 'bugzilla.gnome.org')
acro = "bgo"
# Anti-abuse delays (in seconds)
shortDelay = 2
longDelay = 15
################################################################################
# Read the input file
print "Reading the XML file...... "
xmlDoc = XmlSimple.xml_in(xmlFile)
if xmlDoc.nil?
print "Failed!\n"
puts "Please check the content and the location of the input file."
end
print "Success!\n"
# Connect to GitHub
print "Connecting to GitHub...... "
client = Octokit::Client.new(:login => username, :password => password)
print "Success!\n"
puts "Total number of bugs to be imported: " + xmlDoc["bug"].count.to_s
# Create issues
total_issues = 0
total_comments = 0
xmlDoc["bug"].each do |bug|
print "\rCreating the next issue....."
### Prepare the issue
title = "[" + acro + "#" + bug["bug_id"][0] + "] " + bug["short_desc"][0]
body = bug["long_desc"][0]["thetext"][0]
body += "\n\nOriginally reported by "
unless bug["reporter"][0]["name"].nil?
body += bug["reporter"][0]["name"]
end
body += " at " + bgzUrl + "/show_bug.cgi?id=" + bug["bug_id"][0]
label = "bug"
label = "enhancement" if bug["bug_severity"][0] == "enhancement"
### Create the issue
issue = client.create_issue(repo, title, body, {:labels => label})
issueNum = issue.to_hash[:number]
sleep(shortDelay)
### Post the comments
commentCount = 0
bug["long_desc"].each do |comment|
# Skip the bug description
if comment["comment_count"][0] == "0"
next
end
commentMsg = comment["thetext"][0]
commentMsg += "\n\nOriginally posted by " + comment["who"][0]["name"]
# Add attachment if any
unless comment["attachid"].nil?
attachUrl = bgzUrl + "/attachment.cgi?id=" + comment["attachid"][0]
commentMsg += "\n\n Attachment: " + attachUrl
end
client.add_comment(repo, issueNum, commentMsg)
commentCount += 1
total_comments += 1
sleep(shortDelay)
end
puts "\rIssue#" + issueNum.to_s + " has been created successfully with " + commentCount.to_s + " comments."
total_issues += 1
# Sleep longDelay seconds to avoid GitHub's API abuse detection
print "Cooling the GitHub API......"
sleep(longDelay)
end
puts total_issues.to_s + " issues have been created successfully."
puts total_comments.to_s + " comments have been posted in total."