获取BitBucket拉取请求,仅ID

时间:2019-07-03 11:22:04

标签: bitbucket-api

我有一个CI teamcity构建,我们将在其中使用Bitbucket API创建请求请求。构建链的设计方式是,对PR的“构建此”注释将触发构建链。目前,此过程(创建PR和添加评论)是手动完成的;我们正在尝试使它自动化。

我们能够通过PR成功创建PR;

curl -k -X POST -H "Content-Type: application/json" -u sysAccount:sysPasswd https://stash.org.com:1234/rest/api/1.0/projects/MyProjName/repos/MyRepoName/pull-requests -d '{ "title": "Pull Request Test", "description": "My PR", "state": "OPEN", "open": true, "closed": false, "fromRef": { "id": "refs/heads/myFeatureBranch", "repository": { "slug": "MyPrivateRepo", "name": "MyPrivateRepo", "project": { "key": "~SystemAccount" } } }, "toRef": { "id": "refs/heads/master", "repository": { "slug": "PublicRepoName", "name": "PublicRepoName", "project": { "key": "TeamPrjName" } } }, "locked": false, "reviewers": [] }'

另一个添加注释的API调用:

curl -k -X POST -H "Content-Type: application/json" -u sysAccount:sysPasswd https://stash.org.com:1234/rest/api/1.0/projects/MyProjName/repos/MyRepoName/pull-requests/12345/comments -d '{ "text": "build this" }'

但是,我们如何检索ID(在此示例中为12345)。我们可以获取此PR的完整JSON响应;但是我只需要pullRequestId

1 个答案:

答案 0 :(得分:0)

您可以使用Pull Request Notifier并构建如下网址:

https://stash.org.com:1234/rest/api/1.0/projects/MyProjName/repos/MyRepoName/pull-requests/${PULL_REQUEST_ID}/comments