benjamincharity
7/2/2015 - 3:08 AM

A terminal script to setup GitHub issue labels for a project.

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"