Skip to content

Commit

Permalink
use jo to create json and jq to merge jsons instead of string manipul…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
thesebas committed Apr 25, 2023
1 parent 2a731b9 commit aa690a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LABEL com.github.actions.description="An action that will call a webhook from yo
LABEL com.github.actions.icon="upload-cloud"
LABEL com.github.actions.color="gray-dark"

RUN apk add --no-cache bash curl openssl util-linux xxd jq
RUN apk add --no-cache bash curl openssl util-linux xxd jq jo

COPY LICENSE README.md /
COPY entrypoint.sh /entrypoint.sh
Expand Down
7 changes: 3 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ else
RAW_FILE_DATA=`cat $GITHUB_EVENT_PATH`
WEBHOOK_DATA=$(echo -n "$RAW_FILE_DATA" | jq -c '')
else
WEBHOOK_DATA="{\"event\":\"$EVENT_NAME\",\"repository\":\"$GITHUB_REPOSITORY\",\"commit\":\"$GITHUB_SHA\",\"ref\":\"$GITHUB_REF\",\"head\":\"$GITHUB_HEAD_REF\",\"workflow\":\"$GITHUB_WORKFLOW\"}"
WEBHOOK_DATA=$(jo event="$EVENT_NAME" repository="$GITHUB_REPOSITORY" commit="$GITHUB_SHA" ref="$GITHUB_REF" head="$GITHUB_HEAD_REF" workflow="$GITHUB_WORKFLOW")
fi

JSON_WITH_OPEN_CLOSE_BRACKETS_STRIPPED=`echo "$WEBHOOK_DATA" | sed 's/^{\(.*\)}$/\1/'`
if [ -n "$data" ]; then
CUSTOM_JSON_DATA=$(echo -n "$data" | jq -c '')
WEBHOOK_DATA="{$JSON_WITH_OPEN_CLOSE_BRACKETS_STRIPPED,\"requestID\":\"$REQUEST_ID\",\"data\":$CUSTOM_JSON_DATA}"
WEBHOOK_DATA=$(jq -s '.[0] * .[1]' <(echo $WEBHOOK_DATA) <(jo requestID="$REQUEST_ID" data="$CUSTOM_JSON_DATA"))
else
WEBHOOK_DATA="{$JSON_WITH_OPEN_CLOSE_BRACKETS_STRIPPED,\"requestID\":\"$REQUEST_ID\"}"
WEBHOOK_DATA=$(jq -s '.[0] * .[1]' <(echo $WEBHOOK_DATA) <(jo requestID="$REQUEST_ID"))
fi

fi
Expand Down

0 comments on commit aa690a7

Please sign in to comment.