sin-tanaka
9/28/2018 - 5:28 AM

Gitlab上で特定のリポジトリ以下のissueを別リポジトリのissueへ移行するスクリプト

Gitlab上で特定のリポジトリ以下のissueを別リポジトリのissueへ移行するスクリプト

import requests
import json
import time

GITLAB_PRIVATE_TOKEN = 'token_hogehoge_token'
export_pj_id = 'numxxxx'
import_pj_id = 'numxxxx'

export_pj_url = f"https://gitlab.com/api/v4/projects/{export_pj_id}/issues?state=opened&private_token={GITLAB_PRIVATE_TOKEN}"
import_pj_url = f"https://gitlab.com/api/v4/projects/{import_pj_id}/issues?private_token={GITLAB_PRIVATE_TOKEN}"

headers = {'content-type': 'application/json'}

resp = requests.get(export_pj_url)

for issue in (json.loads(resp.content)):
    payload = {
        'id': issue['id'],
        'iid': issue['iid'],
        'title': issue['title'],
        'description': issue['description'],
        'created_at': issue['created_at'],
        'assignee_ids': [i['id'] for i in issue['assignees']],
        'created_at': issue['created_at'],
        'due_date': issue['due_date'],
        'labels': '',
    }
    r = requests.post(import_pj_url, data=json.dumps(payload), headers=headers)
    print(r.text)
    time.sleep(2)