JSON pre-processing tweaks.
This commit is contained in:
@@ -34,21 +34,19 @@ jobs:
|
|||||||
accept: 200,201,204,404
|
accept: 200,201,204,404
|
||||||
log-response: true
|
log-response: true
|
||||||
|
|
||||||
- name: Convert gocurl Response to JSON
|
- name: Extract gocurl Response to Valid JSON
|
||||||
id: preprocess-response
|
id: extract-json
|
||||||
run: |
|
run: |
|
||||||
RESPONSE='${{ steps.check-pr.outputs.response }}'
|
RESPONSE='${{ steps.check-pr.outputs.response }}'
|
||||||
|
|
||||||
# Extract the 'data' and 'status_code' fields into JSON format
|
# Extract only the JSON content starting with '{' and ending with '}'
|
||||||
DATA=$(echo "$RESPONSE" | grep -oP 'data:\K[^\s]+' || echo "null")
|
JSON_RESPONSE=$(echo "$RESPONSE" | grep -oP '\{.*\}' || echo '{}')
|
||||||
STATUS_CODE=$(echo "$RESPONSE" | grep -oP 'status_code:\K[^\s]+' || echo "0")
|
|
||||||
|
|
||||||
# Create valid JSON output
|
# Validate the JSON using jq
|
||||||
echo "{ \"data\": $DATA, \"status_code\": $STATUS_CODE }" > response.json
|
echo "$JSON_RESPONSE" | jq '.' > valid_response.json || echo '{}' > valid_response.json
|
||||||
cat response.json
|
|
||||||
|
|
||||||
# Export as output
|
# Output the validated JSON
|
||||||
echo "response_json=$(cat response.json)" >> $GITHUB_OUTPUT
|
echo "response_json=$(cat valid_response.json)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Parse PR Response
|
- name: Parse PR Response
|
||||||
id: parse-pr
|
id: parse-pr
|
||||||
|
|||||||
Reference in New Issue
Block a user