Skip to content

Instantly share code, notes, and snippets.

@fopina
Created April 1, 2015 18:28
Show Gist options
  • Save fopina/f40306c84a021bb6f834 to your computer and use it in GitHub Desktop.
Save fopina/f40306c84a021bb6f834 to your computer and use it in GitHub Desktop.
Python script to copy redmine issues to gitlab
'''
Requires python-redmine and gitlab3 (both available with pip)
Copy all issues from a Redmine server to Gitlab for the projects specified in a text mapping the projects such as:
redmine_project_identifier:gitlab_project_identifier_with_namespace
rmproject:fopina/glproject
'''
from redmine import Redmine
# annoying warnings
import requests
requests.packages.urllib3.disable_warnings()
import gitlab3, sys
# CONFIGURATION BEGIN #
RM_URL = 'http://rm.mydomain.com/'
RM_UID = 'rmadmin'
RM_PWD = 'rmadminpassword'
GL_TOKEN = '1xxxXX11xXxxxXX'
GL_URL = 'https://gitlab.com/'
# redmine status that represent closed issue
CLOSED_STATUS_MAP = [
'Closed',
'Rejected',
'Released',
]
# CONFIGURATION END #
def main():
if len(sys.argv) < 2:
print 'Missing arguments'
print 'Usage: %s REPO_FILE' % sys.argv[0]
sys.exit(1)
f = open(sys.argv[1], 'r')
pjs = []
for l in f:
pjs.append(l.strip().split(':'))
redmine = Redmine(RM_URL, username=RM_UID, password=RM_PWD)
gl = gitlab3.GitLab(GL_URL, GL_TOKEN)
for pj in pjs:
rp = redmine.project.get(pj[0])
gp = gl.project(pj[1].replace('/','%2F')) # I guess gitlab3 should support this..
# TODO - project update not implemented gitlab3
'''
gp.description = rp.description + '\n\nHomepage: ' + rp.homepage
gp.name = rp.name
'''
for issue in redmine.issue.filter(project_id=pj[0],status_id='*'):
#dir(issue) - changesets', u'created_on', u'description', u'id', 'journals', u'status', u'subject', u'tracker', u'updated_on'
description = issue.description
description += '''
---
**Migrated from redmine**
| RM field | RM value |
| --- | --- |
| ID | #%d |
|Created on | %s |
|Updated on | %s |
|Status | %s |
''' % (issue.id, issue.created_on, issue.updated_on, issue.status.name)
# TODO - map notes to comments
'''
for note in issue.journals:
#[u'created_on', u'details', u'id', u'notes', u'user']
print note.details
print note.id
print note.user
print note.created_on
'''
gi = gp.add_issue(issue.subject, description = description, labels = issue.tracker)
for change in issue.changesets:
gi.add_note('''
**Revision** %s
**Committed on** %s
%s
''' % (change['revision'], change['committed_on'], change['comments']))
if issue.status.name in CLOSED_STATUS_MAP:
gi.close()
if __name__ == '__main__':
main()
@maxxer
Copy link

maxxer commented Jun 11, 2015

hi. do you think it's possible to import also all redmine's issue comments, along with issue description? thakns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment