Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2022-10-30 14:44:06 +0100
committerLevente Polyak <anthraxx@archlinux.org>2023-05-19 22:27:13 +0200
commit2a59c32bf4ff117bd02d58a4e3f322b709259f1e (patch)
tree57b49351cf080b1d4eb85bce76abbba920e61400 /src
parent77d800eab2419b334cafd94b2e986351919def77 (diff)
repo: added command to create a new packaging repository
Diffstat (limited to 'src')
-rw-r--r--src/lib/repo.sh10
-rw-r--r--src/lib/repo/create.sh113
2 files changed, 123 insertions, 0 deletions
diff --git a/src/lib/repo.sh b/src/lib/repo.sh
index 8b8df11..6b3817a 100644
--- a/src/lib/repo.sh
+++ b/src/lib/repo.sh
@@ -29,6 +29,7 @@ pkgctl_repo_usage() {
COMMANDS
clone Clone a package repository
configure Configure a clone according to distro specs
+ create Create a new GitLab package repository
web Open the packaging repository's website
OPTIONS
@@ -38,6 +39,7 @@ pkgctl_repo_usage() {
$ ${COMMAND} clone libfoo linux libbar
$ ${COMMAND} clone --maintainer mynickname
$ ${COMMAND} configure *
+ $ ${COMMAND} create libfoo
$ ${COMMAND} web linux
_EOF_
}
@@ -71,6 +73,14 @@ pkgctl_repo() {
pkgctl_repo_configure "$@"
exit 0
;;
+ create)
+ _DEVTOOLS_COMMAND+=" $1"
+ shift
+ # shellcheck source=src/lib/repo/create.sh
+ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/repo/create.sh
+ pkgctl_repo_create "$@"
+ exit 0
+ ;;
web)
_DEVTOOLS_COMMAND+=" $1"
shift
diff --git a/src/lib/repo/create.sh b/src/lib/repo/create.sh
new file mode 100644
index 0000000..31b46e1
--- /dev/null
+++ b/src/lib/repo/create.sh
@@ -0,0 +1,113 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+[[ -z ${DEVTOOLS_INCLUDE_REPO_CREATE_SH:-} ]] || return 0
+DEVTOOLS_INCLUDE_REPO_CREATE_SH=1
+
+_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
+# shellcheck source=src/lib/common.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
+# shellcheck source=src/lib/api/gitlab.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/api/gitlab.sh
+# shellcheck source=src/lib/repo/clone.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/repo/clone.sh
+# shellcheck source=src/lib/repo/configure.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/repo/configure.sh
+
+set -e
+
+
+pkgctl_repo_create_usage() {
+ local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}}
+ cat <<- _EOF_
+ Usage: ${COMMAND} [OPTIONS] [PKGBASE]...
+
+ Create a new Git packaging repository in the canonical GitLab namespace.
+
+ This command requires a valid GitLab API authentication. To setup a new
+ GitLab token or check the currently configured one please consult the
+ 'auth' subcommand for further instructions.
+
+ If invoked without a parameter, try to create a packaging repository
+ based on the PKGBUILD from the current working directory and configure
+ the local repository afterwards.
+
+ OPTIONS
+ -c, --clone Clone the Git repository after creation
+ -h, --help Show this help text
+
+ EXAMPLES
+ $ ${COMMAND} libfoo
+_EOF_
+}
+
+pkgctl_repo_create() {
+ # options
+ local pkgbases=()
+ local pkgbase
+ local clone=0
+ local configure=0
+
+ # variables
+ local path
+
+ while (( $# )); do
+ case $1 in
+ -h|--help)
+ pkgctl_repo_create_usage
+ exit 0
+ ;;
+ -c|--clone)
+ clone=1
+ shift
+ ;;
+ -*)
+ die "invalid argument: %s" "$1"
+ ;;
+ *)
+ pkgbases=("$@")
+ break
+ ;;
+ esac
+ done
+
+ # check if invoked without any path from within a packaging repo
+ if (( ${#pkgbases[@]} == 0 )); then
+ if [[ -f PKGBUILD ]]; then
+ if ! path=$(realpath -e .); then
+ die "failed to read path from current directory"
+ fi
+ pkgbases=("$(basename "${path}")")
+ clone=0
+ configure=1
+ else
+ pkgctl_repo_create_usage
+ exit 1
+ fi
+ fi
+
+ # create projects
+ for pkgbase in "${pkgbases[@]}"; do
+ if ! gitlab_api_create_project "${pkgbase}" >/dev/null; then
+ die "failed to create project: ${pkgbase}"
+ fi
+ msg_success "Successfully created ${pkgbase}"
+ if (( clone )); then
+ pkgctl_repo_clone "${pkgbase}"
+ elif (( configure )); then
+ pkgctl_repo_configure
+ fi
+ done
+
+ # some convenience hints if not in auto clone/configure mode
+ if (( ! clone )) && (( ! configure )); then
+ cat <<- _EOF_
+
+ For new clones:
+ $(msg2 "pkgctl repo clone ${pkgbases[*]}")
+ For existing clones:
+ $(msg2 "pkgctl repo configure ${pkgbases[*]}")
+ _EOF_
+ fi
+}