Created
July 20, 2015 20:37
-
-
Save biswanaths/23b13af64ef8b93af562 to your computer and use it in GitHub Desktop.
Issue migration from JIRA to github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib, urllib2, json | |
from bs4 import BeautifulSoup | |
import base64 | |
token="<github access token>" | |
base_jira = "https://issues.scala-lang.org/browse/SI-" | |
base_jira_api = "https://issues.scala-lang.org/rest/api/2/issue/SI-%s/comment" | |
def add_jira_comment(issue,url): | |
base64string = base64.encodestring('<user>:<password>').replace('\n','') | |
jira_api_url= base_jira_api % str(issue) | |
params = dict([ ('body', "Getting tracked here : " + str(url)) ]) | |
data = json.dumps(params) | |
#remove the next line, when everything is ready | |
jira_api_url="https://issues.scala-lang.org/rest/api/2/issue/TEST-14/comment" | |
request = urllib2.Request(jira_api_url) | |
request.add_header("Content-Type","Application/json") | |
request.add_header("Authorization", "Basic %s" % base64string) | |
response = urllib2.urlopen(request,data) | |
if(response.getcode()!=201): | |
print("could not add comment to jira with github link") | |
print("JIRA : " + jira_api_url) | |
print("GitHub : " + str(url)) | |
def read_jira_issue(issue): | |
url = base_jira + str(issue) | |
res=urllib2.urlopen(urllib2.Request(url, | |
headers={'Authorization': ''})).read() | |
soup = BeautifulSoup(res) | |
title = soup.find(id='summary-val').contents[0] | |
description = soup.find(id='description-val').contents[1] | |
new_tag = soup.new_tag("a",href=url) | |
new_tag.string = "Imported from : SI-" + str(issue) | |
description.append(new_tag) | |
for img in description.findAll('img'): | |
if(img["src"][0]=="/"): | |
#removing the img seems to be fine | |
img.decompose() | |
#img["src"] = "https://issues.scala-lang.org" + img["src"] | |
for a in description.findAll('a'): | |
if(a["href"][0]=="/"): | |
#removing the link seems to be fine | |
a.decompose() | |
#a["href"] = "https://issues.scala-lang.org" + a["href"] | |
return title, description | |
def create_gh_issue(title, body): | |
url = "https://api.github.com/repos/biswanaths/scala_jira_gh/issues" | |
params = dict([ ('title', title) , ('body', str(body)) ]) | |
data = json.dumps(params) | |
request = urllib2.Request(url) | |
request.add_header("Content-Type","Application/json") | |
request.add_header("Authorization","token %s" % token) | |
response = urllib2.urlopen(request,data) | |
gh_issue = json.loads(response.read(200000)) | |
gh_issue_url = gh_issue["url"].replace("api.","").replace("repos/","") | |
print("Created issue " + gh_issue_url) | |
return gh_issue_url | |
def main(): | |
issues = [ 9047, 8834, 7796, 7726, 7395, 7311, 7282, 6800, 6741, 6341, 5775, 5133, 5132, 5131, 5101, 4865, 4836, 4543, 4529, 4528, 4520, 4303, 4296, 4286, 4267, 4050, 3881, 3689, 3573, 3527, 3336, 3334, 3286, 3246, 3062, 2725, 1787, 1654] | |
for issue in issues: | |
title, body = read_jira_issue(issue) | |
print("Creating Issue") | |
gh_url = create_gh_issue(title, body) | |
add_jira_comment(issue,gh_url) | |
print("Done with %s !!" % str(issue)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment