简体   繁体   English

如何通过 Bitbucket API 创建拉取请求?

[英]How to create a pull request via the Bitbucket API?

TL;DR : Where can I find the documentation on what to pass to the POST request in order to create a Pull Request ? TL;DR :我在哪里可以找到关于为了创建拉取请求而传递给 POST 请求的内容的文档? (What to put in the JSON) (在 JSON 中放什么)


Using a Groovy script, I'm trying to automatize some tasks that include a commit/push of a tmp branch on multiple projects.使用 Groovy 脚本,我试图自动化一些任务,包括在多个项目上提交/推送 tmp 分支。 I want to automatically create pull request between the tmp branch and the prod branch of all those projects at the end of my script.我想在脚本末尾自动创建所有这些项目的 tmp 分支和 prod 分支之间的拉取请求。 In order to do so, I tried using the BitBucket REST API.为此,我尝试使用 BitBucket REST API。

I found this documentation which gave me the following endpoint to use with a POST request : /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests .我找到了这个文档,它为我提供了以下端点以用于 POST 请求: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests This enpoint need the following JSON :这个端点需要以下 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"
            }
        }
    ]
}

However, I can't find any information on how to build this JSON ... I can guess what title and description are, but what are state , open , closed , etc. for ?但是,我找不到有关如何构建此 JSON 的任何信息……我可以猜测titledescription是什么,但是stateopenclosed等是什么? How do I build a correct fromRef.id ?如何构建正确的fromRef.id Why the repo name is set to null ?为什么 repo 名称设置为null which attribute are optinal ?哪些属性是可选的? If I put my BitBucket login in reviewers[0].user.name , will it work ?如果我将我的 BitBucket 登录名放在reviewers[0].user.name ,它会起作用吗? etc.等等。

Every answers I've found on this subject is just a copy/past this same JSON, and everybody seems to understand how it works without any explanations... Did I miss something ?我在这个主题上找到的每个答案都只是一个副本/过去这个相同的 JSON,每个人似乎都明白它是如何工作的,没有任何解释......我错过了什么吗?

Anyway, here is my real question : where can I find some documentation on this Pull Request JSON Object ?无论如何,这是我真正的问题:在哪里可以找到有关此 Pull Request JSON Object 的一些文档?

Thanks.谢谢。


EDIT : This is not a duplicate of this post since this is not the same problem.编辑:这不是这篇文章的副本,因为这不是同一个问题。 I have no problem with the permission/authentication, and I even managed to make the request works by fiddling with it.我对许可/身份验证没有问题,我什至设法通过摆弄它来使请求有效。 I am only asking for documentation because I want to understand what I am doing in order to best customize the request.我只是要求提供文档,因为我想了解我在做什么以便最好地定制请求。 While there is some (very light) explanations in the answers of the other post , it doesn't actually answers my question at all (see comments).虽然在另一篇文章的答案中有一些(非常简单的)解释,但它实际上根本没有回答我的问题(见评论)。

Using the documentation found here I was able to successfully created a pull request with minimal properties (inferring what, therefore, are optional properties) from a PowerShell script.使用此处找到的文档我能够从PowerShell脚本成功创建具有最少属性的拉取请求(因此推断出哪些是可选属性)。

My example uses master as the branch to merge to , foo as the branch to merge from , Project1 and Repository1 as the BitBucket project and repository, respectively.我的示例使用master作为要合并到的分支,使用foo作为要合并的分支,分别使用Project1Repository1作为BitBucket项目和存储库。 The uri is as follows (replace the root, project and repository): https://bitbucket.example.com/rest/api/1.0/projects/Project1/repos/Repository1/pull-requests . 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

Sending the following JSON (using the correct Content-Type and Authorization headers) creates a pull request:发送以下JSON (使用正确的Content-TypeAuthorization标头)会创建一个拉取请求:

{
            "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"
                }
            }
        }

The state and reviewers are optional and are left out in this example. statereviewers是可选的,在这个例子中被省略了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM