|
|
@@ -0,0 +1,65 @@ |
|
|
#!/usr/bin/env python |
|
|
|
|
|
import gitlab |
|
|
from jira import JIRA |
|
|
import urllib3 |
|
|
|
|
|
## Disable urllib3 ssl checks warnings |
|
|
urllib3.disable_warnings( urllib3.exceptions.InsecureRequestWarning ) |
|
|
|
|
|
## GitLab config |
|
|
GITLAB_PROJECT = '' |
|
|
GITLAB_TOKEN = '' |
|
|
GITLAB_URL = 'https://gitlab.example.com' |
|
|
|
|
|
## JIRA config |
|
|
JIRA_URL = 'https://jira.example.com/' |
|
|
JIRA_PROJECT = '' |
|
|
JIRA_USER = '' |
|
|
JIRA_PASSWORD = '' |
|
|
JIRA_LABELS = [] |
|
|
|
|
|
## Connect onto GitLab |
|
|
gitlab = gitlab.Gitlab( GITLAB_URL, GITLAB_TOKEN, api_version=4 ) |
|
|
|
|
|
## Connect onto JIRA |
|
|
jira = JIRA( JIRA_URL, basic_auth=( JIRA_USER, JIRA_PASSWORD ), options={ 'verify': False } ) |
|
|
|
|
|
## Get GitLab project |
|
|
gl_project = gitlab.projects.get( GITLAB_PROJECT ) |
|
|
|
|
|
## Lookup available transitions for an issue |
|
|
#print jira.transitions( jira.issue( 'PROJECT-ISSUEID' ) ) |
|
|
|
|
|
## List project issues |
|
|
for issue in gl_project.issues.list( all=True ): |
|
|
found_issues = jira.search_issues( 'project='+JIRA_PROJECT+' AND summary ~ \''+ issue.title.replace( "'", "\\'" ) +'\'') |
|
|
if len( found_issues ) == 0: |
|
|
print '-> Creating issue : %s' % issue.title |
|
|
issue_dict = { |
|
|
'project': JIRA_PROJECT, |
|
|
'summary': issue.title, |
|
|
'description': "Created by " + issue.author.name + " at " + issue.created_at + " :\n" + str(issue.description), |
|
|
'issuetype': { 'name': 'Task' } |
|
|
} |
|
|
|
|
|
if len(issue.assignees) > 0: |
|
|
if 'username' in issue.assignees[0]: |
|
|
issue_dict['assignee'] = { 'name': issue.assignees[0]['username'] } |
|
|
|
|
|
jira_issue = jira.issue( jira.create_issue( fields = issue_dict ) ) |
|
|
jira_issue.update( fields = { "labels": JIRA_LABELS } ) |
|
|
|
|
|
print '--> Created issue in Jira : %s' % str(jira_issue) |
|
|
|
|
|
if issue.state != 'opened': |
|
|
print '--> Closing issue in Jira' |
|
|
jira.transition_issue( jira_issue, '31' ) |
|
|
|
|
|
for note in issue.notes.list( all=True ): |
|
|
if not note.system: |
|
|
comment = jira.add_comment( jira_issue, "Comment from " + note.author.name + " at " + note.created_at + " :\n" + note.body ) |
|
|
print '--> Added comment from %s on issue' % note.author.name |
|
|
|
|
|
else: |
|
|
print '--> Found JIRA issue ' + str(found_issues[0]) + ' for GL issue : ' + issue.title |