Skip to content

Commit d28f935

Browse files
authored
Merge pull request #25 from johannes-huther/feature/random-request-id
Add random request ID (closes #22)
2 parents dabbf0a + 3957435 commit d28f935

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ Will deliver a payload with the following properties:
6262
"commit": "a636b6f0861bbee98039bf3df66ee13d8fbc9c74",
6363
"ref": "refs/heads/master",
6464
"head": "",
65-
"workflow": "Build and deploy"
65+
"workflow": "Build and deploy",
66+
"requestID": "74b1912d19cfe780f1fada4b525777fd"
6667
}
6768
```
69+
`requestID` contains a randomly generated identifier for each request.
70+
6871
<br/>
6972

7073
Add additional data to the payload:
@@ -92,7 +95,8 @@ and now look like:
9295
"data": {
9396
"weapon": "hammer",
9497
"drink": "beer"
95-
}
98+
},
99+
"requestID": "74b1912d19cfe780f1fada4b525777fd"
96100
}
97101
```
98102

entrypoint.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ if [ -z "$webhook_secret" ]; then
2929
exit 1
3030
fi
3131

32+
REQUEST_ID=$(cat /dev/urandom | tr -dc '0-9a-f' | fold -w 32 | head -n 1)
33+
3234
if [ -n "$webhook_type" ] && [ "$webhook_type" == "form-urlencoded" ]; then
3335

3436
EVENT=`urlencode "$GITHUB_EVENT_NAME"`
@@ -39,7 +41,7 @@ if [ -n "$webhook_type" ] && [ "$webhook_type" == "form-urlencoded" ]; then
3941
WORKFLOW=`urlencode "$GITHUB_WORKFLOW"`
4042

4143
CONTENT_TYPE="application/x-www-form-urlencoded"
42-
WEBHOOK_DATA="event=$EVENT&repository=$REPOSITORY&commit=$COMMIT&ref=$REF&head=$HEAD&workflow=$WORKFLOW"
44+
WEBHOOK_DATA="event=$EVENT&repository=$REPOSITORY&commit=$COMMIT&ref=$REF&head=$HEAD&workflow=$WORKFLOW&requestID=$REQUEST_ID"
4345

4446
if [ -n "$data" ]; then
4547
WEBHOOK_DATA="${WEBHOOK_DATA}&${data}"
@@ -55,10 +57,13 @@ else
5557
else
5658
WEBHOOK_DATA="{\"event\":\"$GITHUB_EVENT_NAME\",\"repository\":\"$GITHUB_REPOSITORY\",\"commit\":\"$GITHUB_SHA\",\"ref\":\"$GITHUB_REF\",\"head\":\"$GITHUB_HEAD_REF\",\"workflow\":\"$GITHUB_WORKFLOW\"}"
5759
fi
60+
61+
JSON_WITH_OPEN_CLOSE_BRACKETS_STRIPPED=`echo "$WEBHOOK_DATA" | sed 's/^{\(.*\)}$/\1/'`
5862
if [ -n "$data" ]; then
5963
CUSTOM_JSON_DATA=$(echo -n "$data" | jq -c '')
60-
JSON_WITH_OPEN_CLOSE_BRACKETS_STRIPPED=`echo "$WEBHOOK_DATA" | sed 's/^{\(.*\)}$/\1/'`
61-
WEBHOOK_DATA="{$JSON_WITH_OPEN_CLOSE_BRACKETS_STRIPPED,\"data\":$CUSTOM_JSON_DATA}"
64+
WEBHOOK_DATA="{$JSON_WITH_OPEN_CLOSE_BRACKETS_STRIPPED,\"data\":$CUSTOM_JSON_DATA,\"requestID\":\"$REQUEST_ID\"}"
65+
else
66+
WEBHOOK_DATA="{$JSON_WITH_OPEN_CLOSE_BRACKETS_STRIPPED,\"requestID\":\"$REQUEST_ID\"}"
6267
fi
6368

6469
fi

0 commit comments

Comments
 (0)