From af9ffe4d46c83aca26140d1fea4fd6e28bd91cbf Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Fri, 19 Jul 2024 07:09:49 +1000 Subject: [PATCH] Fixed GitHub notification not handling longer deployment IDs. --- .scaffold/tests/bats/notify.bats | 2 +- scripts/drevops/notify-github.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.scaffold/tests/bats/notify.bats b/.scaffold/tests/bats/notify.bats index 6b94013f5..4efd6d084 100644 --- a/.scaffold/tests/bats/notify.bats +++ b/.scaffold/tests/bats/notify.bats @@ -148,7 +148,7 @@ load _helper.bash declare -a STEPS=( "Started dispatching notifications." "Started GitHub notification for post_deployment event." - "@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=mybranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"987654321\", \"othervar\": \"12345\"}]" + "@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=mybranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"98765432101\", \"othervar\": \"12345\"}]" "@curl -X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/123456789/statuses -s -d {\"state\":\"success\", \"environment_url\": \"https://develop.testproject.com\"} # {\"state\": \"success\", \"othervar\": \"54321\"}" "Marked deployment as finished." "Finished GitHub notification for post_deployment event." diff --git a/scripts/drevops/notify-github.sh b/scripts/drevops/notify-github.sh index bbbe3b15d..24f55b259 100755 --- a/scripts/drevops/notify-github.sh +++ b/scripts/drevops/notify-github.sh @@ -84,7 +84,7 @@ if [ "${DREVOPS_NOTIFY_EVENT}" = "pre_deployment" ]; then deployment_id="$(echo "${payload}" | extract_json_value "id")" # Check deployment ID. - { [ "${#deployment_id}" != "9" ] || [ "$(expr "x${deployment_id}" : "x[0-9]*$")" -eq 0 ]; } && fail "Unable to get a deployment ID." && exit 1 + { [ "${#deployment_id}" -lt 9 ] || [ "${#deployment_id}" -gt 11 ] || [ "$(expr "x${deployment_id}" : "x[0-9]*$")" -eq 0 ]; } && fail "Failed to get a deployment ID for a started operation. Payload: ${payload}" && exit 1 note "Marked deployment as started." else @@ -101,7 +101,7 @@ else deployment_id="$(echo "${payload}" | extract_json_first_value "id")" # Check deployment ID. - { [ "${#deployment_id}" != "9" ] || [ "$(expr "x${deployment_id}" : "x[0-9]*$")" -eq 0 ]; } && fail "Unable to get a deployment ID." && exit 1 + { [ "${#deployment_id}" -lt 9 ] || [ "${#deployment_id}" -gt 11 ] || [ "$(expr "x${deployment_id}" : "x[0-9]*$")" -eq 0 ]; } && fail "Failed to get a deployment ID for a finished operation. Payload: ${payload}" && exit 1 # Post status update. payload="$(curl \