Skip to content

Instantly share code, notes, and snippets.

@jbanety
Forked from omegahm/create_labels.sh
Last active December 8, 2016 17:43
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 jbanety/b8077dfe87ee3c5aa9bd1735baceef8f to your computer and use it in GitHub Desktop.
Save jbanety/b8077dfe87ee3c5aa9bd1735baceef8f to your computer and use it in GitHub Desktop.
Create Gtihub labels from Bash
#!/usr/bin/env bash
###
# Label definitions
###
declare -A LABELS
# Plateforme
LABELS["framework"]="BFD4F2"
LABELS["app"]="BFD4F2"
LABELS["site"]="BFD4F2"
# Problèmes
LABELS["bug"]="EE3F46"
LABELS["sécurité"]="EE3F46"
LABELS["prod"]="F45D43"
# Ennuyeux
LABELS["corvée"]="FEF2C0"
LABELS["contenu"]="FFF2C1"
# Expérience
LABELS["design"]="FFC274"
LABELS["ux"]="FFC274"
# Environnement
LABELS["staging"]="FAD8C7"
LABELS["tests"]="FAD8C7"
# Feedback
LABELS["discussion"]="CC317C"
LABELS["question"]="CC317C"
LABELS["besoin aide"]="CC317C"
# Améliorations
LABELS["amélioration"]="5EBEFF"
LABELS["optimisation"]="5EBEFF"
# Ajouts
LABELS["fonction"]="91CA55"
# En attente
LABELS["en cours"]="FBCA04"
LABELS["a surveillé"]="FBCA04"
# Inactive
LABELS["invalide"]="D2DAE1"
LABELS["wontfix"]="D2DAE1"
LABELS["doublon"]="D2DAE1"
LABELS["en attente"]="D2DAE1"
# Fixs rapides
LABELS["boum"]="D93F0B"
LABELS["45mins"]="D93F0B"
###
# Get a token from Github
###
if [ ! -f ".token" ]; then
read -p "Utilisateur GitHub : " user
read -p "Les 6 chiffres du code à 2 facteurs : " otp_code
curl -u "$user" -H "X-Github-OTP: $otp_code" -d '{"scopes":["repo", "public_repo"], "note":"Creating Labels"}' "https://api.github.com/authorizations" | jq -r '.token' > .token
fi
TOKEN=$(cat .token)
read -p "Qui est le proproio du repo ? " owner
read -p "Quel repo ?: " 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" ]; then
ERROR=$(echo "$CURL_OUTPUT" | jq -r '.errors[0].code')
if [ "$ERROR" == "already_exists" ]; then
# We update
echo "'$K' existe déjà. Mise à jour..."
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 "Erreur inconnue $ERROR"
echo "Curl: "
echo "$CURL_OUTPUT"
echo "RIP..."
exit;
fi
else
echo "'$K' créé."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment