Last active
May 16, 2016 18:15
-
-
Save ricard33/2feee518c5744e7d24bd to your computer and use it in GitHub Desktop.
Import Redmine issues to Gitlab
This file contains hidden or 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
__author__ = 'ricard' | |
from redmine import Redmine | |
from gitlab import Gitlab | |
from ConfigParser import ConfigParser | |
config = ConfigParser() | |
config.readfp(open('defaults.cfg')) | |
redmine = Redmine(config.get('redmine', 'url'), key=config.get('redmine', 'key') ) | |
red_project = redmine.project.get(config.get('redmine', 'project')) | |
gl = Gitlab(config.get('gitlab', 'url'), config.get('gitlab', 'key')) | |
gl.auth() | |
look_for = config.get('gitlab', 'project') | |
for p in gl.Project(per_page=1000): | |
# print p.path_with_namespace | |
if p.path_with_namespace == look_for: | |
gl_project_id = p.id | |
gl_project = p | |
break | |
print gl_project.id | |
labels = gl_project.Label(per_page=1000) | |
for cat in red_project.issue_categories: | |
found = False | |
for label in labels: | |
if label.name == cat.name: | |
found = True | |
break | |
if not found: | |
print "Creating label %s" % cat.name | |
label = gl_project.Label({'name': cat.name, 'color': '#5cb85c'}) | |
# label.save() | |
versionDict = {} | |
milestones = gl_project.Milestone(per_page=1000) | |
for version in red_project.versions: | |
found = False | |
for ms in milestones: | |
if version.name == ms.title: | |
found = True | |
break | |
if not found: | |
print "Creating milestone %s" % version.name | |
ms = gl_project.Milestone({'title': version.name, 'description': version.description, 'due_date': getattr(version, 'due_date', None)}) | |
ms.save() | |
# label.save() | |
versionDict[version.id] = ms.id | |
#gl_issues = gl_project.Issue() | |
for issue in red_project.issues: | |
issue = redmine.issue.get(issue.id, include='journals') | |
#print type(issue.fixed_version), issue.fixed_version.id, issue.fixed_version | |
# print issue.id, issue.subject, issue.tracker | |
category = None | |
if hasattr(issue, 'category'): | |
category = issue.category.name | |
print issue.id, issue.status, category, issue.subject | |
milestone_id = None | |
if hasattr(issue, 'fixed_version'): | |
milestone_id = versionDict.get(issue.fixed_version.id) | |
gl_issue = gl_project.Issue({'title': issue.subject, 'description': issue.description, | |
'labels': category, 'milestone_id': milestone_id}) | |
gl_issue.save() | |
if hasattr(issue, 'journals'): | |
for j in issue.journals: | |
print " ", j.id, j.created_on, j.user, j.details, getattr(j, 'notes', None) | |
notes = getattr(j, 'notes', None) | |
if notes: | |
note = gl_issue.Note({'body': notes}) | |
note.save() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment