Skip to content

Commit

Permalink
Merge pull request #959 from pbnj/feat/git-browse-ci
Browse files Browse the repository at this point in the history
feat: implement git-browse-ci
  • Loading branch information
spacewander authored Apr 13, 2022
2 parents 3d6f945 + 9390d45 commit f556430
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions bin/git-browse-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

set -e -o pipefail
if [[ $1 == "" ]]
then
branch=$(git rev-parse --abbrev-ref HEAD &> /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
4 changes: 4 additions & 0 deletions etc/bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@ _git_info(){
_git_browse(){
__git_complete_remote_or_refspec
}

_git_browse_ci(){
__git_complete_remote_or_refspec
}
1 change: 1 addition & 0 deletions etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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'\
Expand Down
1 change: 1 addition & 0 deletions etc/git-extras.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
34 changes: 34 additions & 0 deletions man/git-browse-ci.1
Original file line number Diff line number Diff line change
@@ -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\-ci\fR [remote_name]
.
.SH "DESCRIPTION"
Opens the current git repository CI page in your default web browser\.
.
.SH "OPTIONS"
<remote_name>
.
.P
The name of the remote you wish to browse to\. Defaults to the first remote if not specified\.
.
.SH "EXAMPLES"
$ git browse\-ci
.
.P
$ git browse\-ci upstream
.
.SH "AUTHOR"
Written by Peter Benjamin <\fIhttps://github\.com/pbnj\fR>
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>
119 changes: 119 additions & 0 deletions man/git-browse-ci.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions man/git-browse-ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
git-browse-ci(1) -- <View the web page for the current repository>
================================

## SYNOPSIS

`git-browse-ci` [remote_name]

## DESCRIPTION

Opens the current git repository CI page in your default web browser.

## OPTIONS

&lt;remote_name&gt;

The name of the remote you wish to browse to. Defaults to
the first remote if not specified.

## EXAMPLES

$ git browse-ci

$ git browse-ci upstream

## AUTHOR

Written by Peter Benjamin &lt;<https://github.com/pbnj>&gt;

## REPORTING BUGS

&lt;<https://github.com/tj/git-extras/issues>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;
1 change: 1 addition & 0 deletions man/git-extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)** <View the web page for the current repository>
- **git-browse(1)** <View the web page for the current repository>
- **git-brv(1)** List branches sorted by their last commit date
- **git-bulk(1)** Run git commands on multiple repositories
Expand Down
1 change: 1 addition & 0 deletions man/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f556430

Please sign in to comment.