pkgrepo: add subcommand to open the packaging repository's website

This can be quite handy if a packager quickly wants to check the GitLab
page for merge requests or but reports. Quickly calling a cli command
inside the current packaging clone or with the pkgname provided will
open the remote location inside the browser.

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
This commit is contained in:
Levente Polyak 2022-09-13 00:24:31 +02:00
parent 95424a88eb
commit d15bd29a9d
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
2 changed files with 73 additions and 0 deletions

View File

@ -19,6 +19,7 @@ _pkgrepo_cmds=(
"pkgrepo command"
"clone[Clone a package repository]"
"configure[Configure a clone according to distro specs]"
"web[Open the packaging repository's website]"
)
_pkgrepo_clone_args=(
@ -35,6 +36,11 @@ _pkgrepo_configure_args=(
'*:git_dir:_files -/'
)
_pkgrepo_web_args=(
'(-h --help)'{-h,--help}'[Display usage]'
'*:git_dir:_files -/'
)
_arch_nspawn_args=(
'-C[Location of a pacman config file]:pacman_config:_files -g "*.conf(.)"'
'-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"'

View File

@ -28,6 +28,7 @@ usage() {
COMMANDS
clone Clone a package repository
configure Configure a clone according to distro specs
web Opens the packaging repository's website
OPTIONS
-h, --help Show this help text
@ -72,6 +73,18 @@ usage_configure() {
_EOF_
}
usage_web() {
cat <<- _EOF_
Usage: ${COMMAND} web [PKGNAME...]
Opens the packaging repository's website via xdg-open. If called with
no arguments, open the package cloned in the current working directory.
OPTIONS
-h, --help Show this help text
_EOF_
}
if (( $# < 1 )); then
usage
exit 1
@ -107,6 +120,11 @@ while (( $# )); do
shift
break
;;
web)
WEB=1
shift
break
;;
*)
die "invalid argument: %s" "$1"
;;
@ -184,6 +202,26 @@ elif (( CONFIGURE )); then
;;
esac
done
elif (( WEB )); then
# option checking
while (( $# )); do
case $1 in
-h|--help)
usage_web
exit 0
;;
--)
shift
break
;;
-*)
die "invalid argument: %s" "$1"
;;
*)
break
;;
esac
done
fi
pkgbases=("$@")
@ -231,6 +269,31 @@ if (( CLONE_ALL )); then
stat_done
fi
# Check web mode requirements and current directory shorthand
if (( WEB )); then
# Check if web mode has xdg-open
if ! command -v xdg-open &>/dev/null; then
die "The web command requires 'xdg-open'"
fi
# Check if used without pkgnames in a packaging directory
if (( ! $# )); then
path=${PWD}
if [[ ! -d "${path}/.git" ]]; then
die "Not a Git repository: ${path}"
fi
giturl=$(git -C "${path}" remote get-url origin)
if [[ ${giturl} != *${GIT_PACKAGING_NAMESPACE}* ]]; then
die "Not a packaging repository: ${path}"
fi
pkgbase=$(basename "${giturl}")
pkgbase=${pkgbase%.git}
pkgbases=("${pkgbase}")
fi
fi
for pkgbase in "${pkgbases[@]}"; do
if (( CLONE )); then
if [[ ! -d ${pkgbase} ]]; then
@ -274,4 +337,8 @@ for pkgbase in "${pkgbases[@]}"; do
fi
fi
fi
if (( WEB )); then
xdg-open "${GIT_PACKAGING_URL_HTTPS}/${pkgbase}"
fi
done