diff --git a/Commands.md b/Commands.md index 269dde6f3..72e45227b 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/bin/git-browse-ci b/bin/git-browse-ci new file mode 100755 index 000000000..440c9ce60 --- /dev/null +++ b/bin/git-browse-ci @@ -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 diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index 1493fdda4..0479ea214 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 cbc536f2c..2cfa46eb7 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 931fc0a2e..17bcdfa80 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 000000000..2316e79a0 --- /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\-ci\fR [remote_name] +. +.SH "DESCRIPTION" +Opens the current git repository CI page 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\-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> diff --git a/man/git-browse-ci.html b/man/git-browse-ci.html new file mode 100644 index 000000000..172b17020 --- /dev/null +++ b/man/git-browse-ci.html @@ -0,0 +1,119 @@ + + + + + + git-browse-ci(1) - <View the web page for the current repository> + + + + +
+ + + +
    +
  1. git-browse-ci(1)
  2. +
  3. Git Extras
  4. +
  5. git-browse-ci(1)
  6. +
+ +

NAME

+

+ git-browse-ci - +

+ +

SYNOPSIS

+ +

git-browse-ci [remote_name]

+ +

DESCRIPTION

+ +

Opens the current git repository CI page 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-ci

+ +

$ git browse-ci upstream

+ +

AUTHOR

+ +

Written by Peter Benjamin <https://github.com/pbnj>

+ +

REPORTING BUGS

+ +

<https://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. March 2022
  3. +
  4. git-browse-ci(1)
  5. +
+ +
+ + diff --git a/man/git-browse-ci.md b/man/git-browse-ci.md new file mode 100644 index 000000000..8c40d66c1 --- /dev/null +++ b/man/git-browse-ci.md @@ -0,0 +1,35 @@ +git-browse-ci(1) -- +================================ + +## SYNOPSIS + +`git-browse-ci` [remote_name] + +## DESCRIPTION + +Opens the current git repository CI page 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-ci + + $ git browse-ci upstream + +## AUTHOR + +Written by Peter Benjamin <> + +## REPORTING BUGS + +<> + +## SEE ALSO + +<> diff --git a/man/git-extras.md b/man/git-extras.md index a0d4e9e63..aa77cfe27 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 d57a9c18a..0e0381696 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