Skip to content

Commit

Permalink
Added support for a PR number in the email notification.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Jan 31, 2025
1 parent 6015d4c commit fdf6e3d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .vortex/docs/content/workflows/variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 33 additions & 1 deletion .vortex/tests/bats/notify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -65,6 +65,38 @@ load _helper.bash
assert_output_contains "Notification email(s) sent to: [email protected], [email protected], [email protected]"
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="[email protected]"
export VORTEX_NOTIFY_EMAIL_RECIPIENTS="[email protected]|John Doe, [email protected]|Jane Doe"
export VORTEX_NOTIFY_REF="develop"
export VORTEX_NOTIFY_PR_NUMBER="123"
export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com"
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: [email protected], [email protected]"
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
Expand Down
12 changes: 11 additions & 1 deletion scripts/vortex/notify-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}}"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -128,6 +136,8 @@ sent="${sent%"${sent##*[![:space:]]}"}"

if [ -n "${sent}" ]; then
note "Notification email(s) sent to: ${sent// /, }"
note "Subject: ${subject}"
note "Content: ${content}"
else
note "No notification emails were sent."
fi
Expand Down

1 comment on commit fdf6e3d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.