2017-10-17 93 views
2

我覺得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中的差異。

回答

2

創建我自己的本地鉤子,可以滿足我的需求。爲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頁面」。