fix: use integer label IDs for Forgejo issue creation
Forgejo's create-issue API expects `labels` as `[int64]` (label IDs),
not `[{"name": "..."}]` like GitHub. The previous format caused a JSON
unmarshal error, silently returning null instead of creating the issue.
Changes:
- Split label step to create-if-missing then look up the ID
- Pass label ID as integer to issue creation: `labels: [169]`
- Add error handling: log API response if issue creation returns null
- Also cleaned up another duplicate upstream-sync label
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
d1c8fd0946
commit
f3e800e254
2 files changed
+60
-31
No files matched your search
@@ -88,19 +88,31 @@ jobs:
|
||||
echo "issue_exists=false" >> "$GITHUB_OUTPUT"
|
||||
echo "No existing sync issue found"
|
||||
fi
|
||||
- name: Create upstream-sync label
|
||||
- name: Ensure upstream-sync label exists
|
||||
if: steps.compare.outputs.needs_sync == 'true'
|
||||
run: |-
|
||||
id: label
|
||||
run: |
|
||||
API="${{ env.GITHUB_API_URL }}/repos/${{ github.repository }}"
|
||||
AUTH="Authorization: token ${{ secrets.CLAUDE_BOT_TOKEN }}"
|
||||
|
||||
# Try to create the label (409 = already exists, which is fine)
|
||||
curl -s -o /dev/null -w "%{http_code}" \
|
||||
-X POST \
|
||||
-H "Authorization: token ${{ secrets.CLAUDE_BOT_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-X POST -H "$AUTH" -H "Content-Type: application/json" \
|
||||
-d '{"name":"upstream-sync","color":"#0075ca","description":"Upstream sync tracking"}' \
|
||||
"${{ env.GITHUB_API_URL }}/repos/${{ github.repository }}/labels" || true
|
||||
"$API/labels" || true
|
||||
|
||||
# Look up the label ID (Forgejo needs integer IDs, not names)
|
||||
LABEL_ID=$(curl -s -H "$AUTH" "$API/labels" | jq -r '[.[] | select(.name == "upstream-sync")] | .[0].id // ""')
|
||||
echo "label_id=$LABEL_ID" >> "$GITHUB_OUTPUT"
|
||||
echo "upstream-sync label ID: $LABEL_ID"
|
||||
- name: Create or update sync issue
|
||||
if: steps.compare.outputs.needs_sync == 'true'
|
||||
id: sync-issue
|
||||
run: |-
|
||||
API="${{ env.GITHUB_API_URL }}/repos/${{ github.repository }}"
|
||||
AUTH="Authorization: token ${{ secrets.CLAUDE_BOT_TOKEN }}"
|
||||
LABEL_ID="${{ steps.label.outputs.label_id }}"
|
||||
|
||||
BEHIND="${{ steps.compare.outputs.behind }}"
|
||||
AHEAD="${{ steps.compare.outputs.ahead }}"
|
||||
COMMIT_LOG=$(cat <<'LOG_EOF'
|
||||
@@ -157,22 +169,24 @@ jobs:
|
||||
if [ "${{ steps.existing.outputs.issue_exists }}" = "true" ]; then
|
||||
ISSUE_NUMBER="${{ steps.existing.outputs.issue_number }}"
|
||||
curl -s -o /dev/null \
|
||||
-X PATCH \
|
||||
-H "Authorization: token ${{ secrets.CLAUDE_BOT_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-X PATCH -H "$AUTH" -H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg title "$TITLE" --arg body "$BODY" '{title: $title, body: $body}')" \
|
||||
"${{ env.GITHUB_API_URL }}/repos/${{ github.repository }}/issues/${ISSUE_NUMBER}"
|
||||
"$API/issues/${ISSUE_NUMBER}"
|
||||
echo "Updated existing issue #${ISSUE_NUMBER}"
|
||||
echo "issue_number=${ISSUE_NUMBER}" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
# Forgejo expects labels as integer IDs, not objects with names
|
||||
RESPONSE=$(curl -s \
|
||||
-X POST \
|
||||
-H "Authorization: token ${{ secrets.CLAUDE_BOT_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg title "$TITLE" --arg body "$BODY" '{title: $title, body: $body, labels: [{"name": "upstream-sync"}]}')" \
|
||||
"${{ env.GITHUB_API_URL }}/repos/${{ github.repository }}/issues")
|
||||
-X POST -H "$AUTH" -H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg title "$TITLE" --arg body "$BODY" --argjson labels "[${LABEL_ID:-0}]" '{title: $title, body: $body, labels: $labels}')" \
|
||||
"$API/issues")
|
||||
ISSUE_NUMBER=$(echo "$RESPONSE" | jq '.number')
|
||||
echo "Created new upstream sync issue #${ISSUE_NUMBER}"
|
||||
if [ "$ISSUE_NUMBER" = "null" ] || [ -z "$ISSUE_NUMBER" ]; then
|
||||
echo "::error::Failed to create issue. API response:"
|
||||
echo "$RESPONSE" | jq '.'
|
||||
else
|
||||
echo "Created new upstream sync issue #${ISSUE_NUMBER}"
|
||||
fi
|
||||
echo "issue_number=${ISSUE_NUMBER}" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
merge-upstream:
|
||||
|
||||
Reference in new issue
Block a user