Skip to content

Commit da177d5

Browse files
authored
ci: use jq to format json data (#103)
1 parent f10b8cd commit da177d5

1 file changed

Lines changed: 33 additions & 32 deletions

File tree

.github/workflows/issue-tracker.yml

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,42 @@ jobs:
1212
steps:
1313
- name: Send Issue Data to API
1414
env:
15+
RAW_TITLE: ${{ github.event.issue.title }}
16+
RAW_BODY: ${{ github.event.issue.body }}
17+
RAW_LABELS: ${{ toJSON(github.event.issue.labels) }}
18+
RAW_ASSIGNEES: ${{ toJSON(github.event.issue.assignees) }}
1519
API_URL: ${{ secrets.ISSUE_TRACKER_API_URL }}
1620
VERIFY_TOKEN: ${{ secrets.VERIFY_TOKEN }}
1721
run: |
18-
ISSUE_DATA=$(cat <<EOF
19-
{
20-
"action": "${{ github.event.action }}",
21-
"issue": {
22-
"id": ${{ github.event.issue.id }},
23-
"number": ${{ github.event.issue.number }},
24-
"title": $(echo '${{ github.event.issue.title }}' | jq -R .),
25-
"body": $(echo '${{ github.event.issue.body }}' | jq -Rs .),
26-
"state": "${{ github.event.issue.state }}",
27-
"created_at": "${{ github.event.issue.created_at }}",
28-
"updated_at": "${{ github.event.issue.updated_at }}",
29-
"closed_at": "${{ github.event.issue.closed_at }}",
30-
"url": "${{ github.event.issue.html_url }}",
31-
"user": {
32-
"login": "${{ github.event.issue.user.login }}",
33-
"id": ${{ github.event.issue.user.id }}
34-
},
35-
"labels": $(echo '${{ toJSON(github.event.issue.labels) }}' | jq -c .),
36-
"assignees": $(echo '${{ toJSON(github.event.issue.assignees) }}' | jq -c .)
37-
},
38-
"repository": {
39-
"name": "${{ github.repository }}",
40-
"full_name": "${{ github.event.repository.full_name }}",
41-
"url": "${{ github.event.repository.html_url }}"
42-
},
43-
"sender": {
44-
"login": "${{ github.event.sender.login }}",
45-
"id": ${{ github.event.sender.id }}
46-
}
47-
}
48-
EOF
49-
)
22+
ISSUE_DATA=$(jq -n \
23+
--arg action "${{ github.event.action }}" \
24+
--arg id "${{ github.event.issue.id }}" \
25+
--arg num "${{ github.event.issue.number }}" \
26+
--arg title "$RAW_TITLE" \
27+
--arg body "$RAW_BODY" \
28+
--arg state "${{ github.event.issue.state }}" \
29+
--arg created_at "${{ github.event.issue.created_at }}" \
30+
--arg updated_at "${{ github.event.issue.updated_at }}" \
31+
--arg url "${{ github.event.issue.html_url }}" \
32+
--arg user_login "${{ github.event.issue.user.login }}" \
33+
--argjson labels "$RAW_LABELS" \
34+
--argjson assignees "$RAW_ASSIGNEES" \
35+
'{
36+
action: $action,
37+
issue: {
38+
id: ($id | tonumber),
39+
number: ($num | tonumber),
40+
title: $title,
41+
body: $body,
42+
state: $state,
43+
created_at: $created_at,
44+
updated_at: $updated_at,
45+
url: $url,
46+
user: { login: $user_login },
47+
labels: $labels,
48+
assignees: $assignees
49+
}
50+
}')
5051
5152
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$API_URL" \
5253
-H "Content-Type: application/json" \

0 commit comments

Comments
 (0)