Skip to content

Commit f556430

Browse files
authored
Merge pull request #959 from pbnj/feat/git-browse-ci
feat: implement git-browse-ci
2 parents 3d6f945 + 9390d45 commit f556430

File tree

10 files changed

+275
-0
lines changed

10 files changed

+275
-0
lines changed

Commands.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [`git archive-file`](#git-archive-file)
55
- [`git authors`](#git-authors)
66
- [`git browse`](#git-browse)
7+
- [`git browse-ci`](#git-browse-ci)
78
- [`git bulk`](#git-bulk)
89
- [`git brv`](#git-brv)
910
- [`git changelog`](#git-changelog)
@@ -1502,6 +1503,19 @@ Opens the current git repository website in your default web browser.
15021503
15031504
```bash
15041505
$ git browse
1506+
1507+
$ git browse upstream
1508+
```
1509+
1510+
## git browse-ci
1511+
1512+
Opens the current git repository CI website (e.g. GitHub Actions, GitLab CI,
1513+
Bitbucket Pipelines) in your default web browser.
1514+
1515+
```bash
1516+
$ git browse-ci
1517+
1518+
$ git browse-ci upstream
15051519
```
15061520
15071521
## git utimes

bin/git-browse-ci

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
if [[ $1 == "" ]]
5+
then
6+
branch=$(git rev-parse --abbrev-ref HEAD &> /dev/null)
7+
remote=$(git config branch."${branch}".remote || echo "origin")
8+
else
9+
remote=$1
10+
fi
11+
12+
if [[ $remote == "" ]]
13+
then
14+
echo "Remote not found"
15+
exit 1
16+
fi
17+
18+
remote_url=$(git remote get-url "${remote}")
19+
20+
if [[ $? -ne 0 ]]
21+
then
22+
exit $?
23+
fi
24+
25+
if [[ $remote_url = git@* ]]
26+
then
27+
url=$(echo "${remote_url}" | sed -E -e 's/:/\//' -e 's/\.git$//' -e 's/.*@(.*)/http:\/\/\1/')
28+
elif [[ $remote_url = http* ]]
29+
then
30+
url=${remote_url%.git}
31+
fi
32+
33+
if [[ $url =~ github ]]
34+
then
35+
ci_url=${url}/actions
36+
elif [[ $url =~ gitlab ]]
37+
then
38+
ci_url=${url}/-/pipelines
39+
elif [[ $url =~ bitbucket ]]
40+
then
41+
ci_url=${url}/addon/pipelines/home
42+
fi
43+
case "$OSTYPE" in
44+
darwin*)
45+
# MacOS
46+
open "${ci_url}"
47+
;;
48+
msys)
49+
# Git-Bash on Windows
50+
start "${ci_url}"
51+
;;
52+
linux*)
53+
# Handle WSL on Windows
54+
if uname -a | grep -i -q Microsoft
55+
then
56+
powershell.exe -NoProfile start "${ci_url}"
57+
else
58+
xdg-open "${ci_url}"
59+
fi
60+
;;
61+
*)
62+
# fall back to xdg-open for BSDs, etc.
63+
xdg-open "${ci_url}"
64+
;;
65+
esac

etc/bash_completion.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,7 @@ _git_info(){
154154
_git_browse(){
155155
__git_complete_remote_or_refspec
156156
}
157+
158+
_git_browse_ci(){
159+
__git_complete_remote_or_refspec
160+
}

etc/git-extras-completion.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
346346
archive-file:'export the current head of the git repository to an archive' \
347347
authors:'generate authors report' \
348348
browse:'open repo website in browser' \
349+
browse-ci:'open repo CI page in browser' \
349350
bug:'create bug branch' \
350351
bulk:'run bulk commands' \
351352
brv:'list branches sorted by their last commit date'\

etc/git-extras.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set __fish_git_extras_commands \
44
"archive-file:Export the current HEAD of the git repository to an archive" \
55
"authors:Generate authors report" \
66
"browse:View the web page for the current repository" \
7+
"browse-ci:View the CI page for the current repository" \
78
"brv:List branches sorted by their last commit date" \
89
"bulk:Run git commands on multiple repositories" \
910
"changelog:Generate a changelog report" \

man/git-browse-ci.1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.\" generated with Ronn/v0.7.3
2+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
3+
.
4+
.TH "GIT\-BROWSE\-CI" "1" "March 2022" "" "Git Extras"
5+
.
6+
.SH "NAME"
7+
\fBgit\-browse\-ci\fR \-
8+
.
9+
.SH "SYNOPSIS"
10+
\fBgit\-browse\-ci\fR [remote_name]
11+
.
12+
.SH "DESCRIPTION"
13+
Opens the current git repository CI page in your default web browser\.
14+
.
15+
.SH "OPTIONS"
16+
<remote_name>
17+
.
18+
.P
19+
The name of the remote you wish to browse to\. Defaults to the first remote if not specified\.
20+
.
21+
.SH "EXAMPLES"
22+
$ git browse\-ci
23+
.
24+
.P
25+
$ git browse\-ci upstream
26+
.
27+
.SH "AUTHOR"
28+
Written by Peter Benjamin <\fIhttps://github\.com/pbnj\fR>
29+
.
30+
.SH "REPORTING BUGS"
31+
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
32+
.
33+
.SH "SEE ALSO"
34+
<\fIhttps://github\.com/tj/git\-extras\fR>

man/git-browse-ci.html

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-browse-ci.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
git-browse-ci(1) -- <View the web page for the current repository>
2+
================================
3+
4+
## SYNOPSIS
5+
6+
`git-browse-ci` [remote_name]
7+
8+
## DESCRIPTION
9+
10+
Opens the current git repository CI page in your default web browser.
11+
12+
## OPTIONS
13+
14+
&lt;remote_name&gt;
15+
16+
The name of the remote you wish to browse to. Defaults to
17+
the first remote if not specified.
18+
19+
## EXAMPLES
20+
21+
$ git browse-ci
22+
23+
$ git browse-ci upstream
24+
25+
## AUTHOR
26+
27+
Written by Peter Benjamin &lt;<https://github.com/pbnj>&gt;
28+
29+
## REPORTING BUGS
30+
31+
&lt;<https://github.com/tj/git-extras/issues>&gt;
32+
33+
## SEE ALSO
34+
35+
&lt;<https://github.com/tj/git-extras>&gt;

man/git-extras.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ git-extras(1) -- Awesome GIT utilities
3131
- **git-alias(1)** Define, search and show aliases
3232
- **git-archive-file(1)** Export the current HEAD of the git repository to an archive
3333
- **git-authors(1)** Generate authors report
34+
- **git-browse-ci(1)** <View the web page for the current repository>
3435
- **git-browse(1)** <View the web page for the current repository>
3536
- **git-brv(1)** List branches sorted by their last commit date
3637
- **git-bulk(1)** Run git commands on multiple repositories

man/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ git-abort(1) git-abort
33
git-alias(1) git-alias
44
git-archive-file(1) git-archive-file
55
git-authors(1) git-authors
6+
git-browse-ci(1) git-browse-ci
67
git-browse(1) git-browse
78
git-brv(1) git-brv
89
git-bulk(1) git-bulk

0 commit comments

Comments
 (0)