Created
October 1, 2017 23:43
-
-
Save arunpersaud/9e052987bc13572d24468a83d6d0bcc2 to your computer and use it in GitHub Desktop.
move issues from redmine 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
# Used this script to transfer issues from my old redmine installation to github | |
# just used two existing codes to export and import and just had to adapt this a tiny bit | |
from redminelib import Redmine # from https://python-redmine.com/resources/index.html | |
import urllib.request | |
import urllib.error | |
import urllib.parse | |
import json | |
import base64 | |
import sys | |
import os | |
import time | |
import datetime | |
def send_request(post_data=None): | |
"""Adapted from https://github.com/IQAndreas/github-issues-import """ | |
if post_data is not None: | |
post_data = json.dumps(post_data).encode("utf-8") | |
full_url = 'https://api.github.com/repos/<username>/<project>/issues' | |
req = urllib.request.Request(full_url, post_data) | |
req.add_header("Authorization", b"token <Oauth token>") | |
req.add_header("Content-Type", "application/json") | |
req.add_header("Accept", "application/json") | |
req.add_header("User-Agent", "issueimporter") | |
try: | |
response = urllib.request.urlopen(req) | |
json_data = response.read() | |
except urllib.error.HTTPError as error: | |
error_details = error.read() | |
error_details = json.loads(error_details.decode("utf-8")) | |
error_message = "ERROR: There was a problem importing the issues.\n%s %s" % ( | |
error.code, error.reason) | |
if 'message' in error_details: | |
error_message += "\nDETAILS: " + error_details['message'] | |
sys.exit(error_message) | |
return json.loads(json_data.decode("utf-8")) | |
redmine = Redmine('https://<base redmine url>', version='2.6.5', username='<username>', password='<password>') | |
a = redmine.issue.filter(status_id='*') | |
for i in sorted(a, key=lambda i: i.id): | |
if i.project.name == "photo-tags": | |
continue | |
newissue = {} | |
print("-"*30) | |
print("id: ", i.id) | |
print("project: ", i.project) | |
print("tracker: ", i.tracker) | |
print("title: ", i.subject) | |
print("descr: ", i.description) | |
print("created: ", i.created_on) | |
print("status: ", i.status) | |
print("author: ", i.author) | |
print("done: ", i.done_ratio) | |
print("commit: ", i.changesets) | |
print("changed: ", i.updated_on) | |
# create issue | |
newissue['title'] = i.subject | |
if str(i.status) in ['Closed', 'Rejected']: | |
newissue['title'] = "[Closed] "+newissue['title'] | |
if i.description: | |
newissue['body'] = "{}\n\n".format(i.description) | |
else: | |
newissue['body'] = "" | |
newissue['body'] += "Original creation date in redmine: {} by {}\n".format(i.created_on, i.author) | |
if i.changesets: | |
newissue['body'] += "mentioned in commit {}".format(i.changesets[0]['revision']) | |
if str(i.tracker) == 'Feature': | |
newissue['labels'] = ['enhancement'] | |
elif str(i.tracker) == 'Rejected': | |
newissue['labels'] = ['wontfix'] | |
elif str(i.tracker) == 'Support': | |
newissue['labels'] = [] | |
else: | |
newissue['labels'] = [str(i.tracker)] | |
if i.subject.startswith("GAME"): | |
newissue['labels'].append("gameplay") | |
if i.subject.startswith("STATISTICS"): | |
newissue['labels'].append("stats") | |
if i.subject.startswith("LAYOUT"): | |
newissue['labels'].append("layout") | |
print(newissue) | |
send_request(newissue) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
need to set your github name, project name and the redmine login and password to use the above file