Skip to content

Instantly share code, notes, and snippets.

@SuperPaintman
Created September 8, 2016 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SuperPaintman/53e562ea8cf653e474df968d432ae095 to your computer and use it in GitHub Desktop.
Save SuperPaintman/53e562ea8cf653e474df968d432ae095 to your computer and use it in GitHub Desktop.
Create default labels for Gitlab project
#!/bin/bash
#
# Author: SuperPaintman <SuperPaintmanDeveloper@gmail.com>
#
# Init
me=$(basename "$0")
RETVAL=0
env_name_token="GITLAB_PRIVATE_TOKEN"
# Tags
tags=()
tags+=('{ "name": "Bug", "color": "#eb5a46" }')
tags+=('{ "name": "Client Side", "color": "#00c2e0" }')
tags+=('{ "name": "Development", "color": "#f2d600" }')
tags+=('{ "name": "Feature", "color": "#ffab4a" }')
tags+=('{ "name": "In Progress", "color": "#7f8c8d" }')
tags+=('{ "name": "Production", "color": "#ff5f00" }')
tags+=('{ "name": "Ready", "color": "#ff0000" }')
tags+=('{ "name": "Server Side", "color": "#61bd4f" }')
tags+=('{ "name": "Test", "color": "#c377e0" }')
tags+=('{ "name": "Testing", "color": "#7f8c8d" }')
tags+=('{ "name": "To Do", "color": "#7f8c8d" }')
# Flags
token="${!env_name_token}"
# Help
show_help () {
cat <<EOF
Usage: $me [options] <gitlab_url> <project_id>
Options:
-h, --help Show help.
-t, --token Private token. Default env '\$$env_name_token'.
EOF
}
# Args
args=()
while [[ $# -gt 0 ]]; do
arg="$1"
shift
case $arg in
-h|--help)
show_help
exit $RETVAL
;;
-t|--token)
token="$1"
shift
;;
-*|--*)
echo -e "Unrecognized argument: $arg"
exit 1
;;
*)
args+=("$arg")
;;
esac
done
gitlab_url="${args[0]}"
project_id="${args[1]}"
if [ ${#args[@]} -ne 2 ]; then
show_help
exit 1
fi
if [ "$token" = "" ]; then
echo -e "Env $env_name_token or flag '-t' is required"
show_help
exit 1
fi
for tag in "${tags[@]}"; do
echo -e "Add: $tag"
curl -X POST \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" \
-d "$tag" "$gitlab_url/api/v3/projects/$project_id/labels"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment