如何在命令行中从Bitbucket创建Pull Request

3

在 Bitbucket 中创建新拉取请求的命令是什么。

我正在自动化将代码提交到 Bitbucket 并创建拉取请求。

我参考了许多文档并找到了 curl 命令。但它也无法正常工作,并且我不知道该命令中每个模块的用途。

请查看我尝试过的以下命令。

curl -u username:Password -H "Content-Type: application/jso https://bitbucket.server.com/rest/api/1.0/projects/myProject/repos/myRepo/pull-requests -X POST --data @req.json

创建了req.json文件,将内容复制到文件中。请参阅下面我复制的内容。

{"title":"test","description":"test","fromRef":{"id":"refs/heads/del","repository":{"slug":"BB_repo","name":null}},"toRef":{"id":"refs/heads/master","repository":{"slug":"BB_repo","name":null}}}

有没有人能建议我更好的创建拉取请求的方法?由于我是Bitbucket的新手,所以需要一些解释。


您的 Content-Type 标头有一个拼写错误:应该是 application/json。同时也没有闭合引号。 - Jim Redmond
1个回答

1
使用Bitbucket个人访问令牌,您可以创建别名或将其调整为脚本。
全局配置
[bitbucket]
        url = https://bitbucket.<domain>/rest/api/latest/projects/<proj>/repos/<repo>/pull-requests
        token = <Enter PAT Here>
[alias "pr"]
        m = "!f() { B=$(git branch-name);D=$(git pr.data $B master);U=$(git config --get bitbucket.url);J=$(git pr.json);T=$(git pr.token);C=$(echo curl -X POST $U -H $T -H $J -d $D;); eval $C; }; f"
        d = "!f() { B=$(git branch-name);D=$(git pr.data $B develop);U=$(git config --get bitbucket.url);J=$(git pr.json);T=$(git pr.token);C=$(echo curl -X POST $U -H $T -H $J -d $D;); eval $C; }; f"
        json = "!echo '\"Content-Type: application/json\"'"
        token = "!echo '\"Authorization: Bearer '$(git config --get bitbucket.token)'\"'"
        data = !sh -c 'echo -e \"\\x27{\\\"title\\\":\\\"$1 - $2\\\",\\\"fromRef\\\":{\\\"id\\\":\\\"refs/heads/$1\\\"},\\\"toRef\\\":{\\\"id\\\":\\\"refs/heads/$2\\\"""}}\\x27\"' -
[alias]
        branch-name = !git rev-parse --abbrev-ref HEAD

使用方法:

git pr.m
git pr.d

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接