如何使用GitLab API创建MR?

问题描述:

我想用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'} 

我应该在我的请求更改,使其工作得到以下信息?

除了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