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 e8e1dbb99063933923eb0cc85e4c9c14eb6095c6
parent 8512d74024b69613a55dbe6830ccc1a39239d6cd
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Mon, 11 Feb 2019 09:47:59 +0100

Add script to create gitlab projects through HTTP API

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

diff --git a/links/bin/gitlab-create-project b/links/bin/gitlab-create-project @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +glserver="https://gitlab.com" + +function show_help { + echo "${0##*/} [VISIBILITY] PROJECTNAME[S]" + echo "creates a $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_post_create_project { + curl --header "PRIVATE-TOKEN: $(pass Online/gitlab.com-admesg-private-access-token)" \ + -H "Accept: application/json" \ + -H "Content-type: application/json" \ + -X POST \ + --data-urlencode "name=$2" \ + --data-urlencode "visibility_level=$1" \ + "$glserver/api/v3/projects" +} + +function die { + printf '%s\n' "$1" >&2 + exit 1 +} + +[[ $# -lt 2 ]] && (show_help && exit 1) + +visibility=0 +while :; do + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + 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 + send_post_create_project "$visibility" "$projectname" +done