Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 以编程方式在Bitbucket上创建拉取请求?_Git_Bitbucket_Pull Request_Programmatically - Fatal编程技术网

Git 以编程方式在Bitbucket上创建拉取请求?

Git 以编程方式在Bitbucket上创建拉取请求?,git,bitbucket,pull-request,programmatically,Git,Bitbucket,Pull Request,Programmatically,更新:我在Bash脚本中运行这个,但是我想看看我得到了什么错误代码,现在我可以看到我得到了一个401个未经授权的。我正在使用我的用户名,我用adminaccessBitBucket创建了个人访问令牌,所以我应该能够创建一个PR,对吗?我可以在同一回购协议上通过web UI实现这一点 我正在运行一个bash脚本,以在Bitbucket上创建一个pull请求。我已经在以编程方式克隆repo、编辑文件、执行git添加/提交,现在我只需要使用CURL来创建PR。bitbucket API似乎公开了一个端

更新:我在Bash脚本中运行这个,但是我想看看我得到了什么错误代码,现在我可以看到我得到了一个
401个未经授权的
。我正在使用我的用户名,我用
admin
accessBitBucket创建了个人访问令牌,所以我应该能够创建一个PR,对吗?我可以在同一回购协议上通过web UI实现这一点

我正在运行一个bash脚本,以在Bitbucket上创建一个pull请求。我已经在以编程方式克隆repo、编辑文件、执行git添加/提交,现在我只需要使用CURL来创建PR。bitbucket API似乎公开了一个端点,以便使用POST请求来执行此操作:

Creates a new pull request where the destination repository is this repository and the author is the authenticated user.

The minimum required fields to create a pull request are title and source, specified by a branch name.

curl https://api.bitbucket.org/2.0/repositories/my-username/my-repository/pullrequests \
    -u my-username:my-password \
    --request POST \
    --header 'Content-Type: application/json' \
    --data '{
        "title": "My Title",
        "source": {
            "branch": {
                "name": "staging"
            }
        }
    }'

下面是我的repo在Bitbucket上的外观,我排除了实名,但左边的格式相同(第一个名称是项目名称,
REACTOR2.0
,而我相信第二个名称是存储库名称,
dat repo
):

我正在尝试许多不同的变体,并且正在检查远程bitbucket服务器是否有新的拉取请求,但我什么也看不到

我确信我的“头衔”和“分支机构”是正确的。我唯一的问题是关于URL;我正在从bitbucket输入我的用户名,如果你转到“管理帐户”然后是“名称”,这是我用于URL的
我的用户名
部分的字段,我正在为
我的存储库
部分添加存储库名称。但是,我需要注意的是,这是一个嵌套在名为“REACTOR2.0”的项目中的bitbucket上的存储库,因此我不确定是否需要在URL中的某个位置指定项目名称


有人成功地使用了这个API吗?我查看了google,但很多问题都是使用旧的1.0 API,不适用,或者人们正在执行GET-request操作,只是获取一个pull请求列表……

我使用了错误的API。有一个BitBucket云API,用于托管在BitBucket上的存储库,URL类似于BitBucket.com/,还有一个BitBucket服务器API,URL类似于,这是我需要使用的API

最后,URL应该是这样的(您需要填写
YourCompanyName
YourProjectKey
yourepositoryName
参数):

和要发布的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": "reviewersName1"    
            }
        },
         {
            "user": {
                "name": "reviewerName2" 
            }
        }
    ]
}
如果您选择通过CURL访问API,您可以使用以下内容来表述该请求:

curl -H "Authorization: Basic EncryptedBase64UsernamePasswordHere" \
  -H "Content-Type: application/json" \
  "https://bitbucket.YourCompanyName.com/rest/api/1.0/projects/YourProjectKey/repos/YourRepositoryName/pull-requests" \
  -d JsonDataFromAboveHere
"{\"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\": \"reviewerName1\" 
            }
        },
         {
            \"user\": {
                \"name\": \"reviewerName2\" 
            }
        }
    ]
}"
您可以在下面阅读有关身份验证的更多信息,但您可以在CURL请求中使用
-u username:password
进行身份验证,也可以将username:password字符串和base64编码,然后使用
-H“authentication:Basic BASE64ENCODEDUSERNAMEPASSWORDHERE”
,具体取决于您。您可能需要使用下面的内容对JSON双引号进行转义,具体取决于您发出此请求的机器类型,如下所示:

curl -H "Authorization: Basic EncryptedBase64UsernamePasswordHere" \
  -H "Content-Type: application/json" \
  "https://bitbucket.YourCompanyName.com/rest/api/1.0/projects/YourProjectKey/repos/YourRepositoryName/pull-requests" \
  -d JsonDataFromAboveHere
"{\"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\": \"reviewerName1\" 
            }
        },
         {
            \"user\": {
                \"name\": \"reviewerName2\" 
            }
        }
    ]
}"
如果您想添加审阅者,但不知道他们的姓名,您可以向上面相同的URL发出一个GET请求,它将给出一个用户列表,然后可以将他们的姓名添加到审阅者数组中,这样在创建PR时,他们就已经作为审阅者添加了

身份验证:

Rest API:

请求:

这可以通过git request pull来实现吗??呃,这看起来不像我想做的。他们已经有了一个用于创建PR的公共API;我在上面发布了它。虽然我使用的一些参数或参数一定是错误的,但正如我上面所说的,我现在几乎每一个请求都会得到401-Unauthorized,即使是我的comp完全将URL弄错…使用双引号包装URL。存储库名称或用户名中是否有任何特殊字符,如
/