Skip to content

Instantly share code, notes, and snippets.

@anthonycarminati
Last active February 4, 2016 23:09
Show Gist options
  • Select an option

  • Save anthonycarminati/4724b03e5b96aee8e0fe to your computer and use it in GitHub Desktop.

Select an option

Save anthonycarminati/4724b03e5b96aee8e0fe to your computer and use it in GitHub Desktop.

Revisions

  1. anthonycarminati revised this gist Feb 4, 2016. 1 changed file with 32 additions and 36 deletions.
    68 changes: 32 additions & 36 deletions create_labels
    Original file line number Diff line number Diff line change
    @@ -5,54 +5,50 @@
    declare -A LABELS

    # Platform
    LABELS["ruby"]="BFD4F2"
    LABELS["sql"]="BFD4F2"
    LABELS["python"]="BFD4F2"
    LABELS["groove"]="BFD4F2"
    LABELS["c++"]="BFD4F2"
    LABELS["node.js"]="BFD4F2"
    LABELS["html"]="BFD4F2"
    LABELS["bash/os"]="BFD4F2"

    # Problems
    LABELS["bug"]="EE3F46"
    LABELS["security"]="EE3F46"
    LABELS["production"]="EE3F46"

    # Mindless
    LABELS["chore"]="FEF2C0"
    LABELS["legal"]="FEF2C0"
    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["graphics"]="FFC274"
    LABELS["ui/ux"]="FFC274"
    LABELS["experience:graphics"]="FFC274"
    LABELS["experience:ui/ux"]="FFC274"

    # Environment
    LABELS["developement"]="FAD8C7"
    LABELS["testing"]="FAD8C7"
    LABELS["production"]="FAD8C7"
    LABELS["env:developement"]="FAD8C7"
    LABELS["env:testing"]="FAD8C7"
    LABELS["env:production"]="FAD8C7"

    # Feedback
    LABELS["discussion"]="CC317C"
    LABELS["rfc"]="CC317C"
    LABELS["question"]="CC317C"
    LABELS["feedback:discussion"]="CC317C"
    LABELS["feedback:question"]="CC317C"

    # Improvements
    LABELS["enhancement"]="5EBEFF"
    LABELS["optimizaiton"]="5EBEFF"

    # Additions
    LABELS["feature"]="91CA55"
    LABELS["improve:enhancement"]="5EBEFF"
    LABELS["improve:optimizaiton"]="5EBEFF"

    # Pending
    LABELS["in progress"]="FBCA04"
    LABELS["watchlist"]="FBCA04"
    LABELS["pending:in progress"]="FBCA04"
    LABELS["pending:watchlist"]="FBCA04"

    # Inactive
    LABELS["invalid"]="D2DAE1"
    LABELS["wontfix"]="D2DAE1"
    LABELS["duplicate"]="D2DAE1"
    LABELS["on hold"]="D2DAE1"
    LABELS["inactive:invalid"]="D2DAE1"
    LABELS["inactive:wontfix"]="D2DAE1"
    LABELS["inactive:duplicate"]="D2DAE1"
    LABELS["inactive:on hold"]="D2DAE1"

    ###
    # Get a token from Github
  2. anthonycarminati created this gist Feb 4, 2016.
    88 changes: 88 additions & 0 deletions create_labels
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    ###
    # Label definitions
    ###

    declare -A LABELS

    # Platform
    LABELS["ruby"]="BFD4F2"
    LABELS["sql"]="BFD4F2"
    LABELS["python"]="BFD4F2"
    LABELS["groove"]="BFD4F2"
    LABELS["c++"]="BFD4F2"
    LABELS["node.js"]="BFD4F2"
    LABELS["html"]="BFD4F2"
    LABELS["bash/os"]="BFD4F2"

    # Problems
    LABELS["bug"]="EE3F46"
    LABELS["security"]="EE3F46"
    LABELS["production"]="EE3F46"

    # Mindless
    LABELS["chore"]="FEF2C0"
    LABELS["legal"]="FEF2C0"

    # Experience
    LABELS["graphics"]="FFC274"
    LABELS["ui/ux"]="FFC274"

    # Environment
    LABELS["developement"]="FAD8C7"
    LABELS["testing"]="FAD8C7"
    LABELS["production"]="FAD8C7"

    # Feedback
    LABELS["discussion"]="CC317C"
    LABELS["rfc"]="CC317C"
    LABELS["question"]="CC317C"

    # Improvements
    LABELS["enhancement"]="5EBEFF"
    LABELS["optimizaiton"]="5EBEFF"

    # Additions
    LABELS["feature"]="91CA55"

    # Pending
    LABELS["in progress"]="FBCA04"
    LABELS["watchlist"]="FBCA04"

    # Inactive
    LABELS["invalid"]="D2DAE1"
    LABELS["wontfix"]="D2DAE1"
    LABELS["duplicate"]="D2DAE1"
    LABELS["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