dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 9c3db8254f386a03d23f31562285cf34a4d5273d
parent e8e1dbb99063933923eb0cc85e4c9c14eb6095c6
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Mon, 11 Feb 2019 13:47:39 +0100

Fix curl calls

Diffstat:
Alinks/bin/gitlab-project | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+), 0 deletions(-)

diff --git a/links/bin/gitlab-project b/links/bin/gitlab-project @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +# https://docs.gitlab.com/ee/api/README.html +glserver="https://gitlab.com" +apiversion="v4" +whoami="admesg" +#debug="-v" + +function show_help { + echo "${0##*/} { CREATE [VISIBILITY] | DELETE } PROJECTNAME[S]" + echo "where ACTION is 'create' or 'delete', where 'create' creates a " + echo "$glserver project with name PROJECTNAME." + echo "VISIBILITY can be 'private', 'internal', or 'public'." + echo "If VISIBILITY is not set, the project will be set as 'private'." +} + +function send_create_project { + curl "$debug" \ + --header "PRIVATE-TOKEN: $(pass Online/gitlab.com-admesg-private-access-token)" \ + --header "Accept: application/json" \ + --header "Content-type: application/json" \ + --request POST \ + --data "{\"name\":\"$2\", \"visibility_level\":$1}" \ + "$glserver/api/$apiversion/projects" +} + +function send_delete_project { + curl "$debug" \ + --header "PRIVATE-TOKEN: $(pass Online/gitlab.com-admesg-private-access-token)" \ + --request DELETE \ + "$glserver/api/$apiversion/projects/$whoami%2F$1" +} + +function die { + printf '%s\n' "$1" >&2 + exit 1 +} + +[[ $# -lt 2 ]] && (show_help && exit 1) + +visibility=0 +delete=0 +while :; do + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + delete) + delete=1 + ;; + create) # default operation + ;; + private) + visibility=0 + ;; + internal) + visibility=10 + ;; + public) + visibility=20 + ;; + --) # end all options + shift + break + ;; + -?*) + die 'Error: Unknown option specified' + ;; + *) # no more options + break + esac + shift +done + +[[ $# -lt 1 ]] && die 'Error: No project name[s] specified' + +# loop over PROJECTNAME[S] +for projectname in "$@"; do + + if [[ "$delete" = 1 ]]; then + echo "deleting $projectname" + send_delete_project "$projectname" + else + send_create_project "$visibility" "$projectname" + fi +done