Skip to content

Instantly share code, notes, and snippets.

@anthonycarminati
Last active February 4, 2016 23:09
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 anthonycarminati/4724b03e5b96aee8e0fe to your computer and use it in GitHub Desktop.
Save anthonycarminati/4724b03e5b96aee8e0fe to your computer and use it in GitHub Desktop.
Creates issue labels for a Github repo.
###
# Label definitions
###
declare -A LABELS
# Platform
LABELS["platform:ruby"]="BFD4F2"
LABELS["platform:sql"]="BFD4F2"
LABELS["platform:python"]="BFD4F2"
LABELS["platform:groove"]="BFD4F2"
LABELS["platform:c++"]="BFD4F2"
LABELS["platform:node.js"]="BFD4F2"
LABELS["platform:html"]="BFD4F2"
LABELS["platform:bash/os"]="BFD4F2"
# Important
LABELS["important:bug"]="EE3F46"
LABELS["important:security"]="EE3F46"
LABELS["important:production"]="EE3F46"
# Admin
LABELS["admin:chore"]="FEF2C0"
LABELS["admin:legal"]="FEF2C0"
# Experience
LABELS["experience:graphics"]="FFC274"
LABELS["experience:ui/ux"]="FFC274"
# Environment
LABELS["env:developement"]="FAD8C7"
LABELS["env:testing"]="FAD8C7"
LABELS["env:production"]="FAD8C7"
# Feedback
LABELS["feedback:discussion"]="CC317C"
LABELS["feedback:question"]="CC317C"
# Improvements
LABELS["improve:enhancement"]="5EBEFF"
LABELS["improve:optimizaiton"]="5EBEFF"
# Pending
LABELS["pending:in progress"]="FBCA04"
LABELS["pending:watchlist"]="FBCA04"
# Inactive
LABELS["inactive:invalid"]="D2DAE1"
LABELS["inactive:wontfix"]="D2DAE1"
LABELS["inactive:duplicate"]="D2DAE1"
LABELS["inactive:on hold"]="D2DAE1"
###
# Get a token from Github
###
TOKEN=$(cat .token)
read -p "Who owns the repo you want labels on?: " owner
read -p "What repo do you want labels on?: " repo
for K in "${!LABELS[@]}"; do
CURL_OUTPUT=$(curl -s -H "Authorization: token $TOKEN" -X POST "https://api.github.com/repos/$owner/$repo/labels" -d "{\"name\":\"$K\", \"color\":\"${LABELS[$K]}\"}")
HAS_ERROR=$(echo "$CURL_OUTPUT" | jq -r '.errors')
if [ ! -z "$HAS_ERROR" ] && [ "$HAS_ERROR" != null ]; then
ERROR=$(echo "$CURL_OUTPUT" | jq -r '.errors[0].code')
if [ "$ERROR" == "already_exists" ]; then
# We update
echo "'$K' already exists. Updating..."
CURL_OUTPUT=$(curl -s -H "Authorization: token $TOKEN" -X PATCH "https://api.github.com/repos/$owner/$repo/labels/${K/ /%20}" -d "{\"name\":\"$K\", \"color\":\"${LABELS[$K]}\"}")
else
echo "Unknown error: $ERROR"
echo "Output from curl: "
echo "$CURL_OUTPUT"
echo "Exiting..."
exit 1;
fi
else
echo "Created '$K'."
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment