From d15bd29a9d411dedc0a0682ec54b55e079d4f00f Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Tue, 13 Sep 2022 00:24:31 +0200 Subject: 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 --- src/pkgrepo.in | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'src') diff --git a/src/pkgrepo.in b/src/pkgrepo.in index 13f8847..c6f5951 100644 --- a/src/pkgrepo.in +++ b/src/pkgrepo.in @@ -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 -- cgit v1.2.3-70-g09d2