summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/completion/zsh/_devtools.in7
-rw-r--r--doc/man/pkgctl-repo-create.1.asciidoc40
-rw-r--r--doc/man/pkgctl-repo.1.asciidoc4
-rw-r--r--src/lib/repo.sh10
-rw-r--r--src/lib/repo/create.sh113
5 files changed, 174 insertions, 0 deletions
diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in
index 6ff6cad..3395338 100644
--- a/contrib/completion/zsh/_devtools.in
+++ b/contrib/completion/zsh/_devtools.in
@@ -38,6 +38,7 @@ _pkgctl_repo_cmds=(
"pkgctl repo command"
"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]"
)
@@ -55,6 +56,12 @@ _pkgctl_repo_configure_args=(
'*:git_dir:_files -/'
)
+_pkgctl_repo_create_args=(
+ '(-c --clone)'{-c,--clone}'[Clone the Git repository after creation]'
+ '(-h --help)'{-h,--help}'[Display usage]'
+ '1:pkgbase'
+)
+
_pkgctl_repo_web_args=(
'(-h --help)'{-h,--help}'[Display usage]'
'*:git_dir:_files -/'
diff --git a/doc/man/pkgctl-repo-create.1.asciidoc b/doc/man/pkgctl-repo-create.1.asciidoc
new file mode 100644
index 0000000..b9d980b
--- /dev/null
+++ b/doc/man/pkgctl-repo-create.1.asciidoc
@@ -0,0 +1,40 @@
+pkgctl-repo-create(1)
+======================
+
+Name
+----
+pkgctl-repo-create - Create a new GitLab package repository
+
+Synopsis
+--------
+pkgctl repo create [OPTIONS] [PKGBASE...]
+
+Description
+-----------
+
+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.
+
+Options
+-------
+
+*-c, --clone*::
+ Clone the Git repository after creation
+
+*-h, --help*::
+ Show a help text
+
+See Also
+--------
+
+linkman:pkgctl-auth[1]
+linkman:pkgctl-repo-clone[1]
+linkman:pkgctl-repo-configure[1]
+
+include::include/footer.asciidoc[]
diff --git a/doc/man/pkgctl-repo.1.asciidoc b/doc/man/pkgctl-repo.1.asciidoc
index 564679a..630afd8 100644
--- a/doc/man/pkgctl-repo.1.asciidoc
+++ b/doc/man/pkgctl-repo.1.asciidoc
@@ -38,6 +38,9 @@ pkgctl repo clone::
pkgctl repo configure::
Configure a clone according to distro specs
+pkgctl repo create::
+ Create a new GitLab package repository
+
pkgctl repo web::
Open the packaging repository's website
@@ -46,6 +49,7 @@ See Also
linkman:pkgctl-repo-clone[1]
linkman:pkgctl-repo-configure[1]
+linkman:pkgctl-repo-create[1]
linkman:pkgctl-repo-web[1]
include::include/footer.asciidoc[]
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
+}