I am trying to create labels using github api, but pass in emojis to the label name. Any ideas on how I can do this properly?
source config.txt
labels2=(
"Sleep $zzz_unicode:FFFFFF"
)
# Read repository names from file
while IFS= read -r repo; do
REPO_USER=$(echo "$repo" | cut -f1 -d /)
REPO_NAME=$(echo "$repo" | cut -f2 -d /)
echo "-----------------------------------------[$REPO_USER/$REPO_NAME]---------------------------------"
# Iterate over labels
for label in "${labels2[@]}"; do
label_name=$(echo "$label" | cut -d ":" -f 1)
label_color=$(echo "$label" | cut -d ":" -f 2)
data="{\"name\":\"$label_name $emoji\",\"color\":\"$label_color\"}"
response=$(curl -s -w "%{http_code}" -u "$token:x-oauth-basic" --request POST --data "$data" "https://api.github.com/repos/$REPO_USER/$REPO_NAME/labels")
response_code=$(echo "$response" | tail -n1)
response_body=$(echo "$response" | sed '$d')
if [[ $response_code -eq 201 ]]; then
echo "Label '$label_name $emoji' created successfully in repository '$REPO_USER/$REPO_NAME'"
else
echo "Failed to create label '$label_name $emoji' in repository '$REPO_USER/$REPO_NAME'. Response: $response_body"
fi
done
done < repo_names.txt
Tried using github unicode, as well as the actual emoji in label creation:
"Bug :FF0000"
"Sleep $zzz_unicode:FFFFFF"
I created a label manually on a repo:
Bug with color FF0000. I can run a script to return all labels for that repo:
Fetching labels for Repo...
[
{
"id": someID,
"node_id": "some_nodeID",
"url": "https://api.github.com/repos/repo/labels/test%20%F0%9F%90%9B",
"name": "test ",
"color": "ff0000",
"default": false,
"description": ""
}
]
But if I try using my script above to create the label for me using github API with the emoji in the label itself during creation: "Bug :FF0000" It creates label asBug ??
If I try creation with unicode: "Sleep $zzz_unicode:FFFFFF" it creates label as Sleep Note that sleep is just a test - zzz is github zzz emoji but should work the same.
Github requires that you use their naming convention when submitting a request. Here is an example of my lables I wanted to implement:
And then just ensuring you are extracting label components properly when making your request.
Here is an overview: