Last active
May 14, 2020 15:35
-
-
Save juergenpointinger/6c6fa147439a2db1608775c2bc37b6b2 to your computer and use it in GitHub Desktop.
Import GitLab Epics from Jira
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
# import_epics.py | |
import requests | |
from requests.auth import HTTPBasicAuth | |
import json | |
## Jira specifics | |
# Jira URL | |
JIRA_URL = 'https://your-jira-instance.com/' | |
# Jira user credentials (incl. API token) | |
JIRA_ACCOUNT = ('your-jira-username', 'your-jira-api-token') | |
# Jira project ID (short) | |
JIRA_PROJECT = 'PRJ' | |
# Jira Query (JQL) | |
JQL = 'project=%s+AND+issueType=Epic+AND+resolution=Unresolved+ORDER+BY+createdDate+ASC&maxResults=100' % JIRA_PROJECT | |
# *False* if Jira / GitLab is using self-signed certificates, otherwhise *True* | |
VERIFY_SSL_CERTIFICATE = True | |
## GitLab specifics | |
# GitLab URL | |
GITLAB_URL = 'https://gitlab.com/' | |
# GitLab token will be used whenever the API is invoked | |
GITLAB_TOKEN = 'your-private-gitlab-token' | |
# GitLab group that you are importing to | |
GITLAB_GROUP = 'your-group-name' | |
# GitLab group id. | |
GITLAB_GROUP_ID = 'your-group-id' | |
# Read Jira Epics | |
response = requests.get( | |
JIRA_URL + 'rest/api/latest/search?jql=' + JQL, | |
auth=HTTPBasicAuth(*JIRA_ACCOUNT), | |
verify=VERIFY_SSL_CERTIFICATE, | |
headers={'Content-Type': 'application/json'} | |
) | |
if response.status_code != 200: | |
raise Exception("Unable to read Epics from %s!" % JIRA_PROJECT) | |
jira_issues = response.json() | |
for issue in jira_issues['issues']: | |
print("Import Epic with Jira-Key " + issue['key']) | |
title = issue['fields']['summary'] | |
description = issue['fields']['description'] | |
data = { | |
'title': title, | |
'description': description | |
} | |
response = requests.post( | |
GITLAB_URL + 'api/v4/groups/%s/epics' % GITLAB_GROUP_ID, | |
headers={'PRIVATE-TOKEN': GITLAB_TOKEN}, | |
verify=VERIFY_SSL_CERTIFICATE, | |
data=data | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment