Created
January 13, 2020 17:13
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use:
curl -s https://gist.githubusercontent.com/epwalsh/3159dfb4ed3d530e6b8b21ff5a58f5c6/raw/66591aab9b365d9437499b797ad095cf8ddf19aa/github-labels.sh | bash -