如何使用 GitLab API 创建 MR?
How to create a MR using GitLab API?
我正在尝试使用 GitLab Merge Request API 和 python 以及 python 请求包创建合并请求。这是我的代码片段
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)
我正在尝试使用 GitLab Merge Request API 和 python 以及 python 请求包创建合并请求。这是我的代码片段
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)