From 2ecf6ebf7d657147d8ee84000f0d39317c03ca19 Mon Sep 17 00:00:00 2001 From: Raniere Silva Date: Wed, 21 Jan 2015 21:58:36 -0200 Subject: [PATCH] Improve script to setup labels - Delete GitHub's default label that will not be used - Create new labels - Update color for labels --- tools/setup-labels | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/tools/setup-labels b/tools/setup-labels index 0f4ca6b..91ed734 100755 --- a/tools/setup-labels +++ b/tools/setup-labels @@ -17,6 +17,8 @@ ## ## $ tools/setup-label wking swc-modular-shell +CURL_FLAGS="--silent --fail" + if test $# -lt 2 then echo "Missing parameters." @@ -28,8 +30,9 @@ fi OWNER=$1 REPO=$2 GITHUB_URL=https://github.com/${OWNER}/${REPO} -LABELS=(getting-started working-in-progress discussion) -COLORS=(fbca04 f7c6c7 5319e7) +LABELS=(bug defer discussion duplicate enhancement filed-by-newcomer getting-started help-wanted left-as-was suitable-for-newcomer work-in-progress) +COLORS=(FF0000 66FF00 0000FF 98FB98 E0115F FFFF00 808000 89CFF0 568203 FCE883 545AA7) +LABELS_TO_DELETE=(help%20wanted invalid question wontfix) # Test if repository exists curl -s --head ${GITHUB_URL} | head -n 1 | grep -q "HTTP/1.[01] [23].." @@ -46,22 +49,36 @@ read USERNAME echo "Your GitHub password:" read -s PASSWORD +# Delete labels +for INDEX in $(seq 0 $((${#LABELS_TO_DELETE[*]} - 1))) +do + # Try to delete label + curl ${CURL_FLAGS} -X DELETE \ + -u ${USERNAME}:${PASSWORD} \ + "https://api.github.com/repos/${OWNER}/${REPO}/labels/${LABELS_TO_DELETE[${INDEX}]}" > /dev/null +done # Create labels -for INDEX in $(seq 1 ${#LABELS[*]}) +for INDEX in $(seq 0 $((${#LABELS[*]} - 1))) do - curl -s -f -X POST \ + # Try create new label + curl ${CURL_FLAGS} -X POST \ -u ${USERNAME}:${PASSWORD} \ -d "{\"name\":\"${LABELS[${INDEX}]}\",\"color\":\"${COLORS[${INDEX}]}\"}" \ "https://api.github.com/repos/${OWNER}/${REPO}/labels" > /dev/null if test $? -ne 0 then - echo "Failed when trying to create the label ${LABELS[${INDEX}]}." - echo "Probably the label ${LABELS[${INDEX}]} already exists." - echo "Please check at ${GITHUB_URL}/labels or run" - echo - echo " $ curl -X POST -u ${USERNAME} -d \"{\"name\":\"${LABELS[${INDEX}]}\",\"color\":\"${COLORS[${INDEX}]}\"}\" \"https://api.github.com/repos/${OWNER}/${REPO}/labels\"" - echo - echo "to get more information of the error. If you find a bug" - echo "report it at https://github.com/swcarpentry/lesson-template/." + # Try to fix label color + curl ${CURL_FLAGS} -X PATCH \ + -u ${USERNAME}:${PASSWORD} \ + -d "{\"name\":\"${LABELS[${INDEX}]}\",\"color\":\"${COLORS[${INDEX}]}\"}" \ + "https://api.github.com/repos/${OWNER}/${REPO}/labels/${LABELS[${INDEX}]}" > /dev/null + if test $? -ne 0 + then + echo "Failed when trying to create and update the label ${LABELS[${INDEX}]}." + echo "Please check at ${GITHUB_URL}/labels" + echo "" + echo "If you find a bug report it at" + echo "https://github.com/swcarpentry/lesson-template/." + fi fi done -- GitLab