Git钩子在Bitbucket中产生Github“Create Pull Request”链接吗
问题描述:
我觉得Bitbucket非常方便的一件事情是当你将一个新的分支推到一个托管在Bitbucket中的repo时,它会打印出终端屏幕)一个URL,您可以点击该URL来创建您刚刚推送的分支中的PR。例如:Git钩子在Bitbucket中产生Github“Create Pull Request”链接吗
$ git push origin someBranch
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 313 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote:
remote: Create pull request for someBranch:
remote: https://bitbucket.mydomain.com/projects/PRO/repos/someRepo/compare/commits?sourceBranch=refs/heads/someBranch
remote:
To ssh://bitbucket.mydomain.com:7999/pro/somerepo.git
f6718d4..410cbcb someBranch -> someBranch
我觉得这是一个巨大的节省时间过要到位桶,导航到回购,找到“创建拉请求”按钮等。因此,我想类似的东西当我使用Github上托管的回购协议时 - 在推出新分支后,请将它打印到终端上,我可以打开一个URL以访问Github上的创建公关屏幕。任何人都知道这样的事情?
我知道这里有一个CLI命令Github,它有一个pull-request
命令,但是每次都会提示你输入密码,这很烦人,而TBH我喜欢在实际创建PR前查看UI中的差异。
答
创建我自己的本地钩子,可以满足我的需求。为pre-push
钩加入这一个回购本地克隆:
#!/bin/sh
branch=$(git rev-parse --abbrev-ref HEAD)
userRepo=$(git remote -v | grep fetch | awk '{print $2}' | grep "github.com" | cut -d':' -f2 | rev | cut -c5- | rev)
if [ -n "$userRepo" ]
then
echo ""
echo "Create PR at: https://github.com/$userRepo/compare/$branch?expand=1"
echo ""
fi
输出示例:
$ git push origin testouthooks
Create PR at: https://github.com/pzelnip/dotfiles/compare/testouthooks?expand=1
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 284 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:pzelnip/dotfiles.git
f7c29b8..f6f9347 testouthooks -> testouthooks
我可以那么打的网址发出的创建拉出请求页面上降落在Github上与分支我刚推出作为源分支。
这与Bitbucket并不完全相同,因为它在本地运行(Bitbucket在远程运行),所以它不像智能型那样(例如:即使推送没有导致对其进行更改,它仍然会发出URL远程等)。但它符合我的需求:“当我推送到Github repo时,我可以单击终端窗口中的链接进入Github中的创建PR页面”。