Skip to content

Instantly share code, notes, and snippets.

@adiberr
Last active October 22, 2022 10:47
Show Gist options
  • Select an option

  • Save adiberr/f9771452b2be61558a2380b2ba6f105d to your computer and use it in GitHub Desktop.

Select an option

Save adiberr/f9771452b2be61558a2380b2ba6f105d to your computer and use it in GitHub Desktop.
Simple script for creating labels in GitLab
#!/bin/sh
# Author: Adib Err (@adiberr)
# GitLab Docs: https://docs.gitlab.com/ee/api/labels.html#create-a-new-label
PROJECT_ID= # Your project id
GITLAB_API="https://gitlab.com/api/v4/projects/${PROJECT_ID}/labels"
if [ "$#" -ne 2 ]; then
echo "Usage: mklabel <label> <color>"
exit 1
fi;
NAME=$(echo $1 | sed -e 's/_/%20/g')
COLOR=$(echo $2 | sed -e 's/#/%23/')
curl -s -o /dev/null -w '%{http_code}\n' --data "name=${NAME}&color=${COLOR}" --header "PRIVATE-TOKEN: $(cat token.txt)" "${GITLAB_API}"
@adiberr
Copy link
Author

adiberr commented Oct 13, 2022

How to insert multiple labels at once :

$ printf './gl_label.sh %s "%s"\n' $(<labels.txt) | sh

$ cat labels.txt

breaking #d9534f
good_first_issue #5cb85c
help_wanted #5cb85c
type:_security #d9534f
type:_bug #d9534f
type:_fix #f0ad4e
type:_feature #5cb85c
type:_enhancement #428bca
type:_testing #428bca
type:_docs #428bca
type:_chore #428bca
status:_blocked #d9534f
status:_accepted #5cb85c
status:_completed #5cb85c
status:_in-progress #428bca
status:_available #808080
status:_inactive #808080
status:_on-hold #f0ad4e
status:_review-needed #f0ad4e
status:_revision-needed #d9534f
priority:_critical #d9534f
priority:_high #d9534f
priority:_medium #f0ad4e
priority:_low #5cb85c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment