diff --git a/.gitea/workflows/pr-management.yml b/.gitea/workflows/pr-management.yml index 525b78e..d0c08ad 100644 --- a/.gitea/workflows/pr-management.yml +++ b/.gitea/workflows/pr-management.yml @@ -35,7 +35,27 @@ jobs: exit 0 fi - LABELS_JSON=$(echo "$UNIQUE_TYPES" | jq -R '("type: " + (. | ascii_downcase))' | jq -s '{"labels": .}') + # Gitea labels API requires integer IDs, not names — look them up first + ALL_LABELS=$(curl -s -H "Authorization: token $API_TOKEN" "$API_BASE_URL/repos/$REPO/labels?limit=50") + + LABEL_IDS=() + while IFS= read -r type; do + LABEL_NAME="type: $(echo "$type" | tr '[:upper:]' '[:lower:]')" + LABEL_ID=$(echo "$ALL_LABELS" | jq --arg name "$LABEL_NAME" '.[] | select(.name == $name) | .id') + if [[ -n "$LABEL_ID" ]]; then + LABEL_IDS+=("$LABEL_ID") + echo "Matched label '$LABEL_NAME' → ID $LABEL_ID" + else + echo "Warning: label '$LABEL_NAME' not found in repo, skipping." + fi + done <<< "$UNIQUE_TYPES" + + if [[ ${#LABEL_IDS[@]} -eq 0 ]]; then + echo "No matching label IDs found." + exit 0 + fi + + LABELS_JSON=$(printf '%s\n' "${LABEL_IDS[@]}" | jq -s '{"labels": .}') ISSUES_API_URL="$API_BASE_URL/repos/$REPO/issues/$PR_NUMBER/labels" curl -s -f -X POST -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$LABELS_JSON" "$ISSUES_API_URL"