如何使用GitLab API创建MR?

2024-03-29 14:58:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用GitLab Merge Request API和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)

但我一直在回复中收到以下信息

^{pr2}$

我应该在我的请求中做些什么改变才能使它生效?在


Tags: branchidjsontitlerequestgitlabdescriptionmerge
1条回答
网友
1楼 · 发布于 2024-03-29 14:58:21

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

相关问题 更多 >