Skip to content

Instantly share code, notes, and snippets.

@epwalsh
Created January 13, 2020 17:13
Show Gist options
  • Save epwalsh/3159dfb4ed3d530e6b8b21ff5a58f5c6 to your computer and use it in GitHub Desktop.
Save epwalsh/3159dfb4ed3d530e6b8b21ff5a58f5c6 to your computer and use it in GitHub Desktop.
Create good default labels for a repository. Adapted from https://github.com/amatkivskiy/github-labels-creator.
#!/bin/bash
label_names=(
'Status: Changes Requested'
'Status: Do Not Merge'
'Status: Help Wanted'
'Status: In Progress'
'Status: Mergeable'
'Status: Review Needed'
'Type: Bug'
'Type: Duplicate'
'Type: Enhancement'
'Type: Question'
'Type: Wontfix'
'Priority: Critical'
'Priority: High'
'Priority: Medium'
'Priority: Low'
)
label_colors=(
'fbca04'
'd90ba8'
'1d76db'
'd4c5f9'
'128A0C'
'5319e7'
'ee0701'
'cccccc'
'84b6eb'
'cc317c'
'ffffff'
'b60205'
'd93f0b'
'fbca04'
'0e8a16'
)
default_labels=(
'bug'
'duplicate'
'enhancement'
'invalid'
'question'
'wontfix'
'documentation'
'help%20wanted'
'good%20first%20issue'
)
echo "Usage: github-labels.sh REPO"
if [[ $# -eq 0 ]]; then
echo "Not enough parameters for the script to work."
exit
fi
repository=$1
# Delete default labels
for ((i=0;i<${#default_labels[@]};++i)); do
response=$(curl --write-out %{http_code} \
--silent \
--output /dev/null \
-X DELETE \
"https://api.github.com/repos/$repository/labels/${default_labels[i]}" \
-H "authorization: token $GITHUB_TOKEN" )
if [ "$response" -eq "204" ]
then
echo "Label ${default_labels[i]} has been successfuly deleted"
else
echo "Failed to delete ${default_labels[i]}. Code $response"
fi
done
# Create custom labels
for ((i=0;i<${#label_names[@]};++i)); do
response=$(curl --write-out %{http_code} \
--silent \
--output /dev/null \
-X POST \
"https://api.github.com/repos/$repository/labels" \
-H "authorization: token $GITHUB_TOKEN" \
-H "content-type: application/json" \
-d "{\"name\": \"${label_names[i]}\",\"color\": \"${label_colors[i]}\"}")
if [ "$response" -eq "201" ]
then
echo "Successfuly created label ${label_names[i]}"
else
echo "Failed to create ${label_names[i]}. Code $response"
fi
done
@epwalsh
Copy link
Author

epwalsh commented Jan 13, 2020

To use:

curl -s https://gist.githubusercontent.com/epwalsh/3159dfb4ed3d530e6b8b21ff5a58f5c6/raw/66591aab9b365d9437499b797ad095cf8ddf19aa/github-labels.sh | bash -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment