From c5ec7264a8b5acb201064cdd5403b507eb2ba6bc Mon Sep 17 00:00:00 2001 From: kangaroo5383 Date: Fri, 5 Aug 2016 15:38:03 -0700 Subject: [PATCH] Easily track and open the relevant github issue via branch naming convention (#46) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Open issue using ‘git open issue’ * Update doc to reflect new functionality --- README.md | 8 ++++++++ git-open | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cbf6b59..1a218db 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ browser. ## Usage git open [remote-name] [branch-name] + git open issue + +(only implemented github support, feel free to fix the other ones.) ### Examples @@ -18,6 +21,10 @@ browser. $ git open upstream master > open https://github.com/REMOTE_UPSTREAM_USER/CURRENT_REPO/tree/master + On a branch with the naming convention of issues/#123 + $ git open issue + > open https://github.com/REMOTE_UPSTREAM_USER/CURRENT_REPO/issues/123 + ![git open2015-01-24 13_51_18](https://cloud.githubusercontent.com/assets/39191/5889192/244a0b72-a3d0-11e4-8ab9-55fc64228aaa.gif) ### Installation @@ -32,6 +39,7 @@ You can use also `npm` to install this package: npm install --global git-open + #### Using Windows Powershell Save git-open anywhere, say as ~/Documents/Scripts/git-open.sh and define diff --git a/git-open b/git-open index c286db8..ee2fe82 100755 --- a/git-open +++ b/git-open @@ -20,7 +20,18 @@ fi # fallback to upstream if neither is present. remote="origin" if [ -n "$1" ]; then - remote="$1" + if [ "$1" == "issue" ]; then + currentBranch=$(git symbolic-ref -q --short HEAD) + regex='^issue' + if [[ $currentBranch =~ $regex ]]; then + issue=${currentBranch#*#} + else + echo "'git open issue' expect branch naming to be issues/#123" + exit 0 + fi + else + remote="$1" + fi fi remote_url="remote.${remote}.url" @@ -94,7 +105,9 @@ else fi giturl=${giturl%\.git} -if [ -n "$branch" ]; then +if [ -n "$issue" ]; then + giturl="${giturl}/issues/${issue}" +elif [ -n "$branch" ]; then giturl="${giturl}/${providerUrlDifference}/${branch}" fi