Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save adamreisnz/8d3a67b426ee6e834473 to your computer and use it in GitHub Desktop.
Save adamreisnz/8d3a67b426ee6e834473 to your computer and use it in GitHub Desktop.
A terminal script to setup GitHub issue labels for a project.
#!/bin/bash
echo -n "GitHub username: "
read USER
echo -n "GitHub password or token: "
read -s PASS
echo ""
echo -n "GitHub Repo (e.g. foo/bar): "
read REPO
REPO_USER=$(echo "$REPO" | cut -f1 -d /)
REPO_NAME=$(echo "$REPO" | cut -f2 -d /)
# Delete default labels
echo "DELETE https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/bug"
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/bug"
echo "DELETE https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/duplicate"
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/duplicate"
echo "DELETE https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/enhancement"
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/enhancement"
echo "DELETE https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/help%20wanted"
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/help%20wanted"
echo "DELETE https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/invalid"
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/invalid"
echo "DELETE https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/question"
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/question"
echo "DELETE https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/wontfix"
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels/wontfix"
# Bug, 3rd party bug, error
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"bug","color":"b60205"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"3rd party bug","color":"b60205"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"error","color":"b60205"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
# Regression, refactoring, security
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"regression","color":"d93f0b"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"refactoring","color":"d93f0b"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"security","color":"d93f0b"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
# Feature, enhancement, task, test, question
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"feature","color":"0052cc"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"enhancement","color":"207de5"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"task","color":"006b75"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"test","color":"cc317c"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
# Discussion, question, feedback, more info needed
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"discussion","color":"fbca04"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"question","color":"fbca04"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"feedback","color":"fbca04"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"more info needed","color":"fbca04"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
# Duplicate, invalid, wont fix
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"duplicate","color":"e6e6e6"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"invalid","color":"e6e6e6"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"wontfix","color":"e6e6e6"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
# Client, server
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"client","color":"e6e6e6"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
echo "POST https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
curl --user "$USER:$PASS" --include --request POST --data '{"name":"server","color":"e6e6e6"}' "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels"
Setup GitHub issue labels script
@stkent
Copy link

stkent commented Jan 16, 2016

The line

REPO_USER=$(echo "$USER" | cut -f1 -d /)

should instead read

REPO_USER=$(echo "$REPO" | cut -f1 -d /)

@apotek
Copy link

apotek commented Feb 5, 2016

@adambuczynski This did not work (got 401 Unauthorized responses), until I followed @stkent's suggestion above. With that fix in place, the script works as intended.

Thank you to the both of you.

@adamreisnz
Copy link
Author

@stkent @apotek you're right. I replaced it with user because it wasn't working for me, but I was using the repo name without user prefix, and only dealing with my own repositories. Thanks for the heads up.

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