From f513f58d9ec2e9e56d00fde17c9b8e7bd3edaa7b Mon Sep 17 00:00:00 2001
From: Peter Benjamin
Date: Sat, 19 Mar 2022 19:39:03 -0700
Subject: [PATCH 1/5] feat: implement git-browse-ci
---
bin/git-browse-ci | 64 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
create mode 100755 bin/git-browse-ci
diff --git a/bin/git-browse-ci b/bin/git-browse-ci
new file mode 100755
index 0000000..3057373
--- /dev/null
+++ b/bin/git-browse-ci
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+
+if [[ $1 == "" ]]
+then
+ branch=$(git rev-parse --abbrev-ref HEAD 2&> /dev/null)
+ remote=$(git config branch."${branch}".remote || echo "origin")
+else
+ remote=$1
+fi
+
+if [[ $remote == "" ]]
+then
+ echo "Remote not found"
+ exit 1
+fi
+
+remote_url=$(git remote get-url "${remote}")
+
+if [[ $? -ne 0 ]]
+then
+ exit $?
+fi
+
+if [[ $remote_url = git@* ]]
+then
+ url=$(echo "${remote_url}" | sed -E -e 's/:/\//' -e 's/\.git$//' -e 's/.*@(.*)/http:\/\/\1/')
+elif [[ $remote_url = http* ]]
+then
+ url=${remote_url%.git}
+fi
+
+if [[ $url =~ github ]]
+then
+ ci_url=${url}/actions
+elif [[ $url =~ gitlab ]]
+then
+ ci_url=${url}/-/pipelines
+elif [[ $url =~ bitbucket ]]
+then
+ ci_url=${url}/addon/pipelines/home
+fi
+case "$OSTYPE" in
+ darwin*)
+ # MacOS
+ open "${ci_url}"
+ ;;
+ msys)
+ # Git-Bash on Windows
+ start "${ci_url}"
+ ;;
+ linux*)
+ # Handle WSL on Windows
+ if uname -a | grep -i -q Microsoft
+ then
+ powershell.exe -NoProfile start "${ci_url}"
+ else
+ xdg-open "${ci_url}"
+ fi
+ ;;
+ *)
+ # fall back to xdg-open for BSDs, etc.
+ xdg-open "${ci_url}"
+ ;;
+esac
From 02bbdba792ac45fa45ac96dc817f3524b6351439 Mon Sep 17 00:00:00 2001
From: Peter Benjamin
Date: Sat, 19 Mar 2022 20:00:57 -0700
Subject: [PATCH 2/5] chore: update docs & completions
---
Commands.md | 14 ++++
etc/bash_completion.sh | 4 ++
etc/git-extras-completion.zsh | 1 +
etc/git-extras.fish | 1 +
man/git-browse-ci.1 | 34 ++++++++++
man/git-browse-ci.html | 119 ++++++++++++++++++++++++++++++++++
man/git-browse-ci.md | 35 ++++++++++
man/git-extras.md | 1 +
man/index.txt | 1 +
9 files changed, 210 insertions(+)
create mode 100644 man/git-browse-ci.1
create mode 100644 man/git-browse-ci.html
create mode 100644 man/git-browse-ci.md
diff --git a/Commands.md b/Commands.md
index 269dde6..72e4522 100644
--- a/Commands.md
+++ b/Commands.md
@@ -4,6 +4,7 @@
- [`git archive-file`](#git-archive-file)
- [`git authors`](#git-authors)
- [`git browse`](#git-browse)
+ - [`git browse-ci`](#git-browse-ci)
- [`git bulk`](#git-bulk)
- [`git brv`](#git-brv)
- [`git changelog`](#git-changelog)
@@ -1502,6 +1503,19 @@ Opens the current git repository website in your default web browser.
```bash
$ git browse
+
+$ git browse upstream
+```
+
+## git browse-ci
+
+Opens the current git repository CI website (e.g. GitHub Actions, GitLab CI,
+Bitbucket Pipelines) in your default web browser.
+
+```bash
+$ git browse-ci
+
+$ git browse-ci upstream
```
## git utimes
diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh
index 1493fdd..0479ea2 100644
--- a/etc/bash_completion.sh
+++ b/etc/bash_completion.sh
@@ -154,3 +154,7 @@ _git_info(){
_git_browse(){
__git_complete_remote_or_refspec
}
+
+_git_browse_ci(){
+ __git_complete_remote_or_refspec
+}
diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh
index cbc536f..2cfa46e 100644
--- a/etc/git-extras-completion.zsh
+++ b/etc/git-extras-completion.zsh
@@ -346,6 +346,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
archive-file:'export the current head of the git repository to an archive' \
authors:'generate authors report' \
browse:'open repo website in browser' \
+ browse-ci:'open repo CI page in browser' \
bug:'create bug branch' \
bulk:'run bulk commands' \
brv:'list branches sorted by their last commit date'\
diff --git a/etc/git-extras.fish b/etc/git-extras.fish
index 931fc0a..17bcdfa 100644
--- a/etc/git-extras.fish
+++ b/etc/git-extras.fish
@@ -4,6 +4,7 @@ set __fish_git_extras_commands \
"archive-file:Export the current HEAD of the git repository to an archive" \
"authors:Generate authors report" \
"browse:View the web page for the current repository" \
+ "browse-ci:View the CI page for the current repository" \
"brv:List branches sorted by their last commit date" \
"bulk:Run git commands on multiple repositories" \
"changelog:Generate a changelog report" \
diff --git a/man/git-browse-ci.1 b/man/git-browse-ci.1
new file mode 100644
index 0000000..fb5cf3b
--- /dev/null
+++ b/man/git-browse-ci.1
@@ -0,0 +1,34 @@
+.\" generated with Ronn/v0.7.3
+.\" http://github.com/rtomayko/ronn/tree/0.7.3
+.
+.TH "GIT\-BROWSE\-CI" "1" "March 2022" "" "Git Extras"
+.
+.SH "NAME"
+\fBgit\-browse\-ci\fR \-
+.
+.SH "SYNOPSIS"
+\fBgit\-browse\fR [remote_name]
+.
+.SH "DESCRIPTION"
+Opens the current git repository website in your default web browser\.
+.
+.SH "OPTIONS"
+
+.
+.P
+The name of the remote you wish to browse to\. Defaults to the first remote if not specified\.
+.
+.SH "EXAMPLES"
+$ git browse
+.
+.P
+$ git browse upstream
+.
+.SH "AUTHOR"
+Written by Mark Pitman <\fIhttps://github\.com/mapitman\fR>
+.
+.SH "REPORTING BUGS"
+<\fIhttps://github\.com/tj/git\-extras/issues\fR>
+.
+.SH "SEE ALSO"
+<\fIhttps://github\.com/tj/git\-extras\fR>
diff --git a/man/git-browse-ci.html b/man/git-browse-ci.html
new file mode 100644
index 0000000..fb6197b
--- /dev/null
+++ b/man/git-browse-ci.html
@@ -0,0 +1,119 @@
+
+
+
+
+
+ git-browse-ci(1) - <View the web page for the current repository>
+
+
+
+
+
+
+
+
+
+ - git-browse-ci(1)
+ - Git Extras
+ - git-browse-ci(1)
+
+
+
NAME
+
+ git-browse-ci -
+
+
+
SYNOPSIS
+
+
git-browse [remote_name]
+
+
DESCRIPTION
+
+
Opens the current git repository website in your default web browser.
+
+
OPTIONS
+
+
<remote_name>
+
+
The name of the remote you wish to browse to. Defaults to
+the first remote if not specified.
+
+
EXAMPLES
+
+
$ git browse
+
+
$ git browse upstream
+
+
AUTHOR
+
+
Written by Mark Pitman <https://github.com/mapitman>
+
+
REPORTING BUGS
+
+
<https://github.com/tj/git-extras/issues>
+
+
SEE ALSO
+
+
<https://github.com/tj/git-extras>
+
+
+
+
+
+
+
diff --git a/man/git-browse-ci.md b/man/git-browse-ci.md
new file mode 100644
index 0000000..d9a6749
--- /dev/null
+++ b/man/git-browse-ci.md
@@ -0,0 +1,35 @@
+git-browse-ci(1) --
+================================
+
+## SYNOPSIS
+
+`git-browse` [remote_name]
+
+## DESCRIPTION
+
+Opens the current git repository website in your default web browser.
+
+## OPTIONS
+
+<remote_name>
+
+The name of the remote you wish to browse to. Defaults to
+the first remote if not specified.
+
+## EXAMPLES
+
+ $ git browse
+
+ $ git browse upstream
+
+## AUTHOR
+
+Written by Mark Pitman <>
+
+## REPORTING BUGS
+
+<>
+
+## SEE ALSO
+
+<>
diff --git a/man/git-extras.md b/man/git-extras.md
index a0d4e9e..aa77cfe 100644
--- a/man/git-extras.md
+++ b/man/git-extras.md
@@ -31,6 +31,7 @@ git-extras(1) -- Awesome GIT utilities
- **git-alias(1)** Define, search and show aliases
- **git-archive-file(1)** Export the current HEAD of the git repository to an archive
- **git-authors(1)** Generate authors report
+ - **git-browse-ci(1)**
- **git-browse(1)**
- **git-brv(1)** List branches sorted by their last commit date
- **git-bulk(1)** Run git commands on multiple repositories
diff --git a/man/index.txt b/man/index.txt
index d57a9c1..0e03816 100644
--- a/man/index.txt
+++ b/man/index.txt
@@ -3,6 +3,7 @@ git-abort(1) git-abort
git-alias(1) git-alias
git-archive-file(1) git-archive-file
git-authors(1) git-authors
+git-browse-ci(1) git-browse-ci
git-browse(1) git-browse
git-brv(1) git-brv
git-bulk(1) git-bulk
From d7565ee844f10d17163420e138f45451ad502cea Mon Sep 17 00:00:00 2001
From: Peter Benjamin
Date: Sat, 19 Mar 2022 20:03:44 -0700
Subject: [PATCH 3/5] docs: fix docs
---
man/git-browse-ci.1 | 10 +++++-----
man/git-browse-ci.html | 10 +++++-----
man/git-browse-ci.md | 10 +++++-----
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/man/git-browse-ci.1 b/man/git-browse-ci.1
index fb5cf3b..2316e79 100644
--- a/man/git-browse-ci.1
+++ b/man/git-browse-ci.1
@@ -7,10 +7,10 @@
\fBgit\-browse\-ci\fR \-
.
.SH "SYNOPSIS"
-\fBgit\-browse\fR [remote_name]
+\fBgit\-browse\-ci\fR [remote_name]
.
.SH "DESCRIPTION"
-Opens the current git repository website in your default web browser\.
+Opens the current git repository CI page in your default web browser\.
.
.SH "OPTIONS"
@@ -19,13 +19,13 @@ Opens the current git repository website in your default web browser\.
The name of the remote you wish to browse to\. Defaults to the first remote if not specified\.
.
.SH "EXAMPLES"
-$ git browse
+$ git browse\-ci
.
.P
-$ git browse upstream
+$ git browse\-ci upstream
.
.SH "AUTHOR"
-Written by Mark Pitman <\fIhttps://github\.com/mapitman\fR>
+Written by Peter Benjamin <\fIhttps://github\.com/pbnj\fR>
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
diff --git a/man/git-browse-ci.html b/man/git-browse-ci.html
index fb6197b..172b170 100644
--- a/man/git-browse-ci.html
+++ b/man/git-browse-ci.html
@@ -76,11 +76,11 @@
SYNOPSIS
-git-browse [remote_name]
+git-browse-ci [remote_name]
DESCRIPTION
-Opens the current git repository website in your default web browser.
+Opens the current git repository CI page in your default web browser.
OPTIONS
@@ -91,13 +91,13 @@ the first remote if not specified.
EXAMPLES
- $ git browse
+ $ git browse-ci
- $ git browse upstream
+ $ git browse-ci upstream
AUTHOR
-Written by Mark Pitman <https://github.com/mapitman>
+Written by Peter Benjamin <https://github.com/pbnj>
REPORTING BUGS
diff --git a/man/git-browse-ci.md b/man/git-browse-ci.md
index d9a6749..8c40d66 100644
--- a/man/git-browse-ci.md
+++ b/man/git-browse-ci.md
@@ -3,11 +3,11 @@ git-browse-ci(1) --
## SYNOPSIS
-`git-browse` [remote_name]
+`git-browse-ci` [remote_name]
## DESCRIPTION
-Opens the current git repository website in your default web browser.
+Opens the current git repository CI page in your default web browser.
## OPTIONS
@@ -18,13 +18,13 @@ the first remote if not specified.
## EXAMPLES
- $ git browse
+ $ git browse-ci
- $ git browse upstream
+ $ git browse-ci upstream
## AUTHOR
-Written by Mark Pitman <>
+Written by Peter Benjamin <>
## REPORTING BUGS
From 11a2801231fa59ca8580557e1ef177c965f15c72 Mon Sep 17 00:00:00 2001
From: Peter Benjamin
Date: Sun, 20 Mar 2022 18:53:05 -0700
Subject: [PATCH 4/5] fix(git-browse-ci): set pipefail
---
bin/git-browse-ci | 2 ++
1 file changed, 2 insertions(+)
diff --git a/bin/git-browse-ci b/bin/git-browse-ci
index 3057373..38be4aa 100755
--- a/bin/git-browse-ci
+++ b/bin/git-browse-ci
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
+set -e -o pipefail
+
if [[ $1 == "" ]]
then
branch=$(git rev-parse --abbrev-ref HEAD 2&> /dev/null)
From 9390d450aa631fd5706995b7d2b86be7bb9d0aec Mon Sep 17 00:00:00 2001
From: Peter Benjamin
Date: Mon, 11 Apr 2022 08:51:21 -0700
Subject: [PATCH 5/5] fix: fix stderr & stdout redirect
---
bin/git-browse-ci | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/bin/git-browse-ci b/bin/git-browse-ci
index 38be4aa..440c9ce 100755
--- a/bin/git-browse-ci
+++ b/bin/git-browse-ci
@@ -1,10 +1,9 @@
#!/usr/bin/env bash
set -e -o pipefail
-
if [[ $1 == "" ]]
then
- branch=$(git rev-parse --abbrev-ref HEAD 2&> /dev/null)
+ branch=$(git rev-parse --abbrev-ref HEAD &> /dev/null)
remote=$(git config branch."${branch}".remote || echo "origin")
else
remote=$1