Skip to content

Instantly share code, notes, and snippets.

@camilleriluke
Last active September 3, 2020 19:11
Show Gist options
  • Save camilleriluke/89e57d7a5dd60e4425de039e05d3b1b6 to your computer and use it in GitHub Desktop.
Save camilleriluke/89e57d7a5dd60e4425de039e05d3b1b6 to your computer and use it in GitHub Desktop.
Github repository labels standard
#!/usr/bin/env bash
# You can craete a token from https://github.com/settings/tokens and give the
# "repo" persmission to the token
AUTH_TOKEN=$1
OWNERREPO=$2
if [[ "$#" -ne 2 ]]; then
echo "Usage: $0 AUTH_TOKEN OWNER/REPO\n"
exit 1
fi
echo "Updating labels for repository https://github.com/$OWNERREPO/labels"
echo "Removing default labels"
curl --request DELETE -H "Authorization: token $AUTH_TOKEN" "https://api.github.com/repos/$OWNERREPO/labels/help%20wanted"
curl --request DELETE -H "Authorization: token $AUTH_TOKEN" "https://api.github.com/repos/$OWNERREPO/labels/good%20first%20issue"
curl --request DELETE -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels/documentation
curl --request DELETE -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels/bug
curl --request DELETE -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels/duplicate
curl --request DELETE -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels/enhancement
curl --request DELETE -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels/invalid
curl --request DELETE -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels/question
curl --request DELETE -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels/wontfix
echo "Adding new labels"
curl --request POST --data '{"name": "Priority: Critical", "color": "d93f0b"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Priority: Low", "color": "efefef"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Priority: Medium", "color": "fbca04"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Status: On Hold", "color": "fef2c0"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Status: Review Needed", "color": "c5def5"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Status: WIP", "color": "ff6dbb"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Status: 🛳🇮🇹", "color": "c2e0c6"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Type: Bug", "color": "d4c5f9"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Type: New functionality", "color": "47f770"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Type: Refactoring", "color": "bd25c4"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
curl --request POST --data '{"name": "Type: Maintenance", "color": "5319e7"}' -H "Authorization: token $AUTH_TOKEN" https://api.github.com/repos/$OWNERREPO/labels
@lukKowalski
Copy link

Works great!
Small potential improvement, why not reading vars from command line:

...
AUTH_TOKEN=$1
# This could be your personal account or an org
OWNER=$2
REPO=$3
...

@camilleriluke
Copy link
Author

Thanks @lukKowalski. Script is now updated to be used like so:

Usage: repo-labels.sh AUTH_TOKEN OWNER/REPO

@camilleriluke
Copy link
Author

Update: Added removal of documentation default label

@camilleriluke
Copy link
Author

Update: Removed label Type: Enhancement and added Type: Refactoring and Type: New functionality

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