Kiran
Kiran

Reputation: 1531

How to post issues to gitlab using python?

I have two repositories(for same project) one in github and another one in gitlab.I am extracting issues from github in json format. Now I want to post all these issues to gitlab repo. I am not getting any error but issues are not being posted to gitlab

import requests
import getpass

GITHUB_USER = raw_input("Enter github Username: ")
GITHUB_PASSWORD = getpass.getpass("Enter github Password: ")
REPO = raw_input("Enter Repository name: ")
STATE = raw_input("Enter State(all,open,closed): ")
Assignee = raw_input("Enter assignee name: ")
GITHUB_URL = 'https://api.github.com/repos/%s/issues?state=%s' % (REPO, STATE)
AUTH = (GITHUB_USER, GITHUB_PASSWORD)
github_issues = requests.get(GITHUB_URL , auth=AUTH)

GITLAB_URL = 'https://gitlab.com'
GITLAB_TOKEN = 'xxxx'
GITLAB_PROJECT = 'my_project'
GITLAB_USER = raw_input("Enter gitlab Username: ") 
GITLAB_PASSWORD = getpass.getpass("Enter gitlab Password: ") 
AUTH = (GITLAB_USER, GITLAB_PASSWORD)
for issue in github_issues.json():

    gl_issue = requests.post(
        GITLAB_URL + '/myproject/issues',
        headers={'PRIVATE-TOKEN': GITLAB_TOKEN},
        auth=AUTH,
        data={
            'title': issue['title'],
            'description': issue['body']
        }
    )

Upvotes: 3

Views: 2223

Answers (1)

Kiran
Kiran

Reputation: 1531

for issue in github_issues.json():
    url='https://gitlab.com/api/v3/projects/%s/issues?title=%s&description=%s' %(PROJECT_ID,issue['title'],issue['body'])
    response = requests.post(url, headers={"PRIVATE-TOKEN": "xxxxxxxx"})

Upvotes: 1

Related Questions