2017-07-31 63 views
1

我想用python和python請求包使用GitLab Merge Request API來創建一個合併請求。這是我的代碼如何使用GitLab API創建MR?

import requests, json 

MR = 'http://www.gitlab.com/api/v4/projects/317/merge_requests' 

id = '317' 
gitlabAccessToken = 'MySecretAccessToken' 
sourceBranch = 'issue110' 
targetBranch = 'master' 
title = 'title' 
description = 'description' 

header = { 'PRIVATE-TOKEN' : gitlabAccessToken, 
      'id'   : id,  
      'title'   : title, 
      'source_branch' : sourceBranch, 
      'target_branch' : targetBranch 
     } 

reply = requests.post(MR, headers = header) 
status = json.loads(reply.text) 

一個片段,但我一直在回覆

{'error': 'title is missing, source_branch is missing, target_branch is missing'} 

我應該在我的請求更改,使其工作得到以下信息?

回答

2

除了PRIVATE-TOKEN,所有的參數應該表單編碼的參數傳遞,這意味着:

header = {'PRIVATE-TOKEN' : gitlabAccessToken} 
params = { 
      'id'   : id,  
      'title'   : title, 
      'source_branch' : sourceBranch, 
      'target_branch' : targetBranch 
     } 

reply = requests.post(MR, data=params, headers=header) 
+0

謝謝,原來如此! – Ali