-
Notifications
You must be signed in to change notification settings - Fork 0
/
spinnaker-webhook.sh
executable file
·82 lines (73 loc) · 1.89 KB
/
spinnaker-webhook.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -e
USING_TOKEN=''
if [ -n "${INPUT_TOKEN}" ]; then
USING_TOKEN="${INPUT_TOKEN}"
elif [ -n "${SPINNAKER_WEBHOOK_TOKEN}" ]; then
USING_TOKEN="${SPINNAKER_WEBHOOK_TOKEN}"
else
echo "no token found"
exit 1
fi
USING_HOST=''
if [ -n "${INPUT_HOST}" ]; then
USING_HOST="${INPUT_HOST}"
elif [ -n "${SPINNAKER_WEBHOOK_HOST}" ]; then
USING_HOST="${SPINNAKER_WEBHOOK_HOST}"
else
echo "no host found"
exit 1
fi
USING_NAME=''
if [ -n "${INPUT_NAME}" ]; then
USING_NAME="${INPUT_NAME}"
elif [ -n "${SPINNAKER_WEBHOOK_NAME}" ]; then
USING_NAME="${SPINNAKER_WEBHOOK_NAME}"
else
echo "no name found"
exit 1
fi
USING_SHA="${GITHUB_SHA}"
if [ -n "${INPUT_SHA}" ]; then
USING_SHA="${INPUT_SHA}"
elif [ -n "${SPINNAKER_WEBHOOK_SHA}" ]; then
USING_SHA="${SPINNAKER_WEBHOOK_SHA}"
fi
if [ -z "${USING_SHA}" ]; then
echo "no sha found"
exit 1
fi
USING_EXTRA_PARAMS="{}"
if [ -n "${INPUT_EXTRA_PARAMS}" ]; then
USING_EXTRA_PARAMS="${INPUT_EXTRA_PARAMS}"
elif [ -n "${SPINNAKER_WEBHOOK_EXTRA_PARAMS}" ]; then
USING_EXTRA_PARAMS="${SPINNAKER_WEBHOOK_EXTRA_PARAMS}"
fi
message=$(git show --format=%s --no-patch $USING_SHA)
committer_name=$(git show --format=%an --no-patch $USING_SHA)
committer_email=$(git show --format=%ae --no-patch $USING_SHA)
webhook_body=$(jq --null-input \
--join-output \
--compact-output \
--arg token "$USING_TOKEN" \
--arg sha "$USING_SHA" \
--arg message "$message" \
--arg committer_name "$committer_name" \
--arg committer_email "$committer_email" \
--argjson extra_params "$USING_EXTRA_PARAMS" \
'{
$token,
parameters: ({
$sha,
$message,
$committer_name,
$committer_email
} + $extra_params)
}'
)
echo "payload"
echo "$(echo "$webhook_body" | jq .)"
curl -X POST --fail --show-error \
--data "$webhook_body" \
--header 'Content-Type: application/json' \
https://${USING_HOST}/webhooks/webhook/${USING_NAME}