ci: use jq to format json data (#103)

This commit is contained in:
Guoguo
2026-01-08 17:08:49 +08:00
committed by GitHub
parent f10b8cd967
commit da177d55d7

View File

@@ -12,41 +12,42 @@ jobs:
steps:
- name: Send Issue Data to API
env:
RAW_TITLE: ${{ github.event.issue.title }}
RAW_BODY: ${{ github.event.issue.body }}
RAW_LABELS: ${{ toJSON(github.event.issue.labels) }}
RAW_ASSIGNEES: ${{ toJSON(github.event.issue.assignees) }}
API_URL: ${{ secrets.ISSUE_TRACKER_API_URL }}
VERIFY_TOKEN: ${{ secrets.VERIFY_TOKEN }}
run: |
ISSUE_DATA=$(cat <<EOF
{
"action": "${{ github.event.action }}",
"issue": {
"id": ${{ github.event.issue.id }},
"number": ${{ github.event.issue.number }},
"title": $(echo '${{ github.event.issue.title }}' | jq -R .),
"body": $(echo '${{ github.event.issue.body }}' | jq -Rs .),
"state": "${{ github.event.issue.state }}",
"created_at": "${{ github.event.issue.created_at }}",
"updated_at": "${{ github.event.issue.updated_at }}",
"closed_at": "${{ github.event.issue.closed_at }}",
"url": "${{ github.event.issue.html_url }}",
"user": {
"login": "${{ github.event.issue.user.login }}",
"id": ${{ github.event.issue.user.id }}
},
"labels": $(echo '${{ toJSON(github.event.issue.labels) }}' | jq -c .),
"assignees": $(echo '${{ toJSON(github.event.issue.assignees) }}' | jq -c .)
},
"repository": {
"name": "${{ github.repository }}",
"full_name": "${{ github.event.repository.full_name }}",
"url": "${{ github.event.repository.html_url }}"
},
"sender": {
"login": "${{ github.event.sender.login }}",
"id": ${{ github.event.sender.id }}
}
}
EOF
)
ISSUE_DATA=$(jq -n \
--arg action "${{ github.event.action }}" \
--arg id "${{ github.event.issue.id }}" \
--arg num "${{ github.event.issue.number }}" \
--arg title "$RAW_TITLE" \
--arg body "$RAW_BODY" \
--arg state "${{ github.event.issue.state }}" \
--arg created_at "${{ github.event.issue.created_at }}" \
--arg updated_at "${{ github.event.issue.updated_at }}" \
--arg url "${{ github.event.issue.html_url }}" \
--arg user_login "${{ github.event.issue.user.login }}" \
--argjson labels "$RAW_LABELS" \
--argjson assignees "$RAW_ASSIGNEES" \
'{
action: $action,
issue: {
id: ($id | tonumber),
number: ($num | tonumber),
title: $title,
body: $body,
state: $state,
created_at: $created_at,
updated_at: $updated_at,
url: $url,
user: { login: $user_login },
labels: $labels,
assignees: $assignees
}
}')
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$API_URL" \
-H "Content-Type: application/json" \