【发布时间】:2012-01-04 03:37:24
【问题描述】:
我必须发送很多拉取请求,所以我宁愿使用 bash 命令行而不是 bitbucket 的 Web 界面。
使用示例:$ git-req username
这是 Github 的这样一个脚本:http://pastebin.com/F9n3nPuu
Bitbucket 有吗?
【问题讨论】:
标签: command-line bitbucket pull-request
我必须发送很多拉取请求,所以我宁愿使用 bash 命令行而不是 bitbucket 的 Web 界面。
使用示例:$ git-req username
这是 Github 的这样一个脚本:http://pastebin.com/F9n3nPuu
Bitbucket 有吗?
【问题讨论】:
标签: command-line bitbucket pull-request
带有 RESTful API 2.0 的 Bitbucket 支持在没有接口的情况下管理 pull requests。在 CLI 中,您可以使用 CURL 请求它。这个older version of the documentation有更好的界面细节。
要获取有关特定拉取请求的完整数据:
$ curl --user s3m3n:bbpassword https://bitbucket.org/api/2.0/repositories/s3m3n/reponame/pullrequests/4
作为回报,我会得到 JSON 以及关于我的拉取请求 #4 的完整信息(在命令中输入两次用户名、密码和 reponame)。
要创建新的拉取请求,我们需要使用 POST 命令提供大量数据,如下所示:
触发 Bitbucket 后立即显示拉取请求:
您仍然可以使用一个衬垫创建相同的拉取请求:
$ curl -X POST -H "Content-Type: application/json" -u s3m3n:bbpassword https://bitbucket.org/api/2.0/repositories/s3m3n/reponame/pullrequests -d '{ "title": "Merge some branches", "description": "stackoverflow example", "source": { "branch": { "name": "choose branch to merge with" }, "repository": { "full_name": "s3m3n/reponame" } }, "destination": { "branch": { "name": "choose branch that is getting changes" } }, "reviewers": [ { "username": "some other user needed to review changes" } ], "close_source_branch": false }'
如果你想测试所有可能的 API 方法跳到 Bitbucket 的REST browser tool。它会在返回您的真实 repo 数据时向您显示所有可能的请求。
【讨论】:
git-req username 创建一个别名。
久经考验:
点击here生成个人访问令牌
保存唯一令牌 ID,将其附加在“Bearer in header”之后。
例如:“授权:承载 MDg4MzA4NTcfhtrhthyt/Thyythyh”
完整的 JSON 示例here:
Step 1 to enter the details and necessary headers
尝试运行它 Step 2
BitBucket 上的输出,您将能够看到拉取请求 Final output
命令行语法:
curl -i -X POST -H "Authorization:Bearer MDg4MzA4NTk/TlMSS6Ea" -H "X-Atlassian-Token:no-check" -H "Content-Type:application/json" -d '{"description":"1. Changes made 2. Changes made 3. Hello hanges","closed":false,"fromRef":{"id":"refs\/heads\/branch","repository":{"name":"From Repository ","project":{"key":"ProjectName"},"slug":"From Repository "}},"state":"OPEN","title":"Merge changes from branch to master","locked":false,"reviewers":[],"open":true,"toRef":{"id":"refs\/heads\/master","repository":{"name":"RepoName","project":{"key":"ProjectName"},"slug":"RepoName"}}}' 'https://bitbucket.agile.com/rest/api/1.0/projects/projectName/repos/repoName/pull-requests'
【讨论】:
bitbucket 上有 2 个 repos 可以提供帮助:
Attlassian 团队有 stash (ruby):https://bitbucket.org/atlassian/bitbucket-server-cli
哲猫有bitbucket-cli(python):https://bitbucket.org/zhemao/bitbucket-cli
两者都有来自命令行的拉取请求功能。
【讨论】:
pull_request 命令,但自述文件中没有记录。
我对这个帖子的答案不太满意,所以我为它创建了一个包:
https://www.npmjs.com/package/bitbucket-pr
说明:
npm i -g bitbucket-pr
...转到您要创建拉取请求的文件夹...
bitbucket-pr
【讨论】:
我创建了一个拉取请求 cli 实用程序来简化我的任务。
目前,
我已经用 bitbucket enterprise 6.10.10 测试过了
【讨论】: