[英]How to create a pull request via the Bitbucket API?
TL;DR :我在哪里可以找到关于为了创建拉取请求而传递给 POST 请求的内容的文档? (在 JSON 中放什么)
使用 Groovy 脚本,我试图自动化一些任务,包括在多个项目上提交/推送 tmp 分支。 我想在脚本末尾自动创建所有这些项目的 tmp 分支和 prod 分支之间的拉取请求。 为此,我尝试使用 BitBucket REST API。
我找到了这个文档,它为我提供了以下端点以用于 POST 请求: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests
。 这个端点需要以下 JSON :
{
"title": "Talking Nerdy",
"description": "It’s a kludge, but put the tuple from the database in the cache.",
"state": "OPEN",
"open": true,
"closed": false,
"fromRef": {
"id": "refs/heads/feature-ABC-123",
"repository": {
"slug": "my-repo",
"name": null,
"project": {
"key": "PRJ"
}
}
},
"toRef": {
"id": "refs/heads/master",
"repository": {
"slug": "my-repo",
"name": null,
"project": {
"key": "PRJ"
}
}
},
"locked": false,
"reviewers": [
{
"user": {
"name": "charlie"
}
}
]
}
但是,我找不到有关如何构建此 JSON 的任何信息……我可以猜测title
和description
是什么,但是state
、 open
、 closed
等是什么? 如何构建正确的fromRef.id
? 为什么 repo 名称设置为null
? 哪些属性是可选的? 如果我将我的 BitBucket 登录名放在reviewers[0].user.name
,它会起作用吗? 等等。
我在这个主题上找到的每个答案都只是一个副本/过去这个相同的 JSON,每个人似乎都明白它是如何工作的,没有任何解释......我错过了什么吗?
无论如何,这是我真正的问题:在哪里可以找到有关此 Pull Request JSON Object 的一些文档?
谢谢。
编辑:这不是这篇文章的副本,因为这不是同一个问题。 我对许可/身份验证没有问题,我什至设法通过摆弄它来使请求有效。 我只是要求提供文档,因为我想了解我在做什么以便最好地定制请求。 虽然在另一篇文章的答案中有一些(非常简单的)解释,但它实际上根本没有回答我的问题(见评论)。
使用此处找到的文档,我能够从PowerShell
脚本成功创建具有最少属性的拉取请求(因此推断出哪些是可选属性)。
我的示例使用master
作为要合并到的分支,使用foo
作为要合并的分支,分别使用Project1
和Repository1
作为BitBucket
项目和存储库。 uri
如下(替换root、project和repository): https://bitbucket.example.com/rest/api/1.0/projects/Project1/repos/Repository1/pull-requests
: https://bitbucket.example.com/rest/api/1.0/projects/Project1/repos/Repository1/pull-requests
。
发送以下JSON
(使用正确的Content-Type
和Authorization
标头)会创建一个拉取请求:
{
"title" : "This is the title of my pull request",
"description" : "This is the description of my pull request",
"fromRef" : {
"id" : "refs/heads/foo",
"repository" : "Repository1",
"project" : {
"key" : "Project1"
}
},
"toRef" : {
"id" : "refs/heads/master",
"repository" : "Repository1",
"project" : {
"key" : "Project1"
}
}
}
state
和reviewers
是可选的,在这个例子中被省略了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.