diff --git a/.vortex/docs/content/workflows/variables.mdx b/.vortex/docs/content/workflows/variables.mdx index a9395710d..6e3b6cb40 100644 --- a/.vortex/docs/content/workflows/variables.mdx +++ b/.vortex/docs/content/workflows/variables.mdx @@ -1262,6 +1262,14 @@ Default value: `${VORTEX_NOTIFY_PROJECT}` Defined in: `scripts/vortex/notify-email.sh` +### `VORTEX_NOTIFY_EMAIL_PR_NUMBER` + +Git reference to notify about. + +Default value: `${VORTEX_NOTIFY_PR_NUMBER}` + +Defined in: `scripts/vortex/notify-email.sh` + ### `VORTEX_NOTIFY_EMAIL_RECIPIENTS` Email address(es) to send notifications to. diff --git a/.vortex/tests/bats/notify.bats b/.vortex/tests/bats/notify.bats index 387f1d2a9..2ceb03627 100644 --- a/.vortex/tests/bats/notify.bats +++ b/.vortex/tests/bats/notify.bats @@ -47,7 +47,7 @@ load _helper.bash popd >/dev/null || exit 1 } -@test "Notify: email" { +@test "Notify: email, branch" { pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 export VORTEX_NOTIFY_CHANNELS="email" @@ -56,6 +56,8 @@ load _helper.bash export VORTEX_NOTIFY_EMAIL_RECIPIENTS="john@example.com|John Doe, jane@example.com|Jane Doe, jim@example.com" export VORTEX_NOTIFY_REF="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" + export VORTEX_DEBUG=1 + export TEST_VORTEX_DEBUG=1 run ./scripts/vortex/notify.sh assert_success @@ -65,6 +67,40 @@ load _helper.bash assert_output_contains "Notification email(s) sent to: john@example.com, jane@example.com, jim@example.com" assert_output_contains "Finished email notification." + assert_output_contains "Site testproject \"develop\" branch has been deployed" + assert_output_contains "and is available at https://develop.testproject.com." + echo "${output}" >&3 + + assert_output_contains "Finished dispatching notifications." + + popd >/dev/null || exit 1 +} + +@test "Notify: email, PR" { + pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 + + export VORTEX_NOTIFY_CHANNELS="email" + export VORTEX_NOTIFY_PROJECT="testproject" + export DRUPAL_SITE_EMAIL="testproject@example.com" + export VORTEX_NOTIFY_EMAIL_RECIPIENTS="john@example.com|John Doe, jane@example.com|Jane Doe" + export VORTEX_NOTIFY_REF="develop" + export VORTEX_NOTIFY_PR_NUMBER="123" + export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" + export VORTEX_DEBUG=1 + export TEST_VORTEX_DEBUG=1 + run ./scripts/vortex/notify.sh + assert_success + + assert_output_contains "Started dispatching notifications." + + assert_output_contains "Started email notification." + assert_output_contains "Notification email(s) sent to: john@example.com, jane@example.com" + assert_output_contains "Finished email notification." + + assert_output_contains "Site testproject \"PR-123\" has been deployed" + assert_output_contains "and is available at https://develop.testproject.com." + echo "${output}" >&3 + assert_output_contains "Finished dispatching notifications." popd >/dev/null || exit 1 diff --git a/scripts/vortex/notify-email.sh b/scripts/vortex/notify-email.sh index 6430712c1..40fced0d9 100755 --- a/scripts/vortex/notify-email.sh +++ b/scripts/vortex/notify-email.sh @@ -35,6 +35,9 @@ VORTEX_NOTIFY_EMAIL_RECIPIENTS="${VORTEX_NOTIFY_EMAIL_RECIPIENTS:-}" # Git reference to notify about. VORTEX_NOTIFY_EMAIL_REF="${VORTEX_NOTIFY_EMAIL_REF:-${VORTEX_NOTIFY_REF:-}}" +# Git reference to notify about. +VORTEX_NOTIFY_EMAIL_PR_NUMBER="${VORTEX_NOTIFY_EMAIL_PR_NUMBER:-${VORTEX_NOTIFY_PR_NUMBER:-}}" + # Environment URL to notify about. VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL="${VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL:-${VORTEX_NOTIFY_ENVIRONMENT_URL:-}}" @@ -68,11 +71,16 @@ else exit 1 fi +ref_info="\"${VORTEX_NOTIFY_EMAIL_REF}\" branch" +if [ -n "${VORTEX_NOTIFY_EMAIL_PR_NUMBER}" ]; then + ref_info="\"PR-${VORTEX_NOTIFY_EMAIL_PR_NUMBER}\"" +fi + timestamp=$(date '+%d/%m/%Y %H:%M:%S %Z') subject="${VORTEX_NOTIFY_EMAIL_PROJECT} deployment notification of \"${VORTEX_NOTIFY_EMAIL_REF}\"" content="## This is an automated message ## -Site ${VORTEX_NOTIFY_EMAIL_PROJECT} \"${VORTEX_NOTIFY_EMAIL_REF}\" branch has been deployed at ${timestamp} and is available at ${VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL}. +Site ${VORTEX_NOTIFY_EMAIL_PROJECT} ${ref_info} has been deployed at ${timestamp} and is available at ${VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL}. Login at: ${VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL}/user/login"