Skip to content

Commit fdf6e3d

Browse files
committed
Added support for a PR number in the email notification.
1 parent 6015d4c commit fdf6e3d

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

.vortex/docs/content/workflows/variables.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,14 @@ Default value: `${VORTEX_NOTIFY_PROJECT}`
12621262

12631263
Defined in: `scripts/vortex/notify-email.sh`
12641264

1265+
### `VORTEX_NOTIFY_EMAIL_PR_NUMBER`
1266+
1267+
Git reference to notify about.
1268+
1269+
Default value: `${VORTEX_NOTIFY_PR_NUMBER}`
1270+
1271+
Defined in: `scripts/vortex/notify-email.sh`
1272+
12651273
### `VORTEX_NOTIFY_EMAIL_RECIPIENTS`
12661274

12671275
Email address(es) to send notifications to.

.vortex/tests/bats/notify.bats

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ load _helper.bash
4747
popd >/dev/null || exit 1
4848
}
4949

50-
@test "Notify: email" {
50+
@test "Notify: email, branch" {
5151
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
5252

5353
export VORTEX_NOTIFY_CHANNELS="email"
@@ -65,6 +65,38 @@ load _helper.bash
6565
assert_output_contains "Notification email(s) sent to: [email protected], [email protected], [email protected]"
6666
assert_output_contains "Finished email notification."
6767

68+
assert_output_contains "Site testproject \"develop\" branch has been deployed"
69+
assert_output_contains "and is available at https://develop.testproject.com."
70+
echo "${output}" >&3
71+
72+
assert_output_contains "Finished dispatching notifications."
73+
74+
popd >/dev/null || exit 1
75+
}
76+
77+
@test "Notify: email, PR" {
78+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
79+
80+
export VORTEX_NOTIFY_CHANNELS="email"
81+
export VORTEX_NOTIFY_PROJECT="testproject"
82+
export DRUPAL_SITE_EMAIL="[email protected]"
83+
export VORTEX_NOTIFY_EMAIL_RECIPIENTS="[email protected]|John Doe, [email protected]|Jane Doe"
84+
export VORTEX_NOTIFY_REF="develop"
85+
export VORTEX_NOTIFY_PR_NUMBER="123"
86+
export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com"
87+
run ./scripts/vortex/notify.sh
88+
assert_success
89+
90+
assert_output_contains "Started dispatching notifications."
91+
92+
assert_output_contains "Started email notification."
93+
assert_output_contains "Notification email(s) sent to: [email protected], [email protected]"
94+
assert_output_contains "Finished email notification."
95+
96+
assert_output_contains "Site testproject \"PR-123\" has been deployed"
97+
assert_output_contains "and is available at https://develop.testproject.com."
98+
echo "${output}" >&3
99+
68100
assert_output_contains "Finished dispatching notifications."
69101

70102
popd >/dev/null || exit 1

scripts/vortex/notify-email.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ VORTEX_NOTIFY_EMAIL_RECIPIENTS="${VORTEX_NOTIFY_EMAIL_RECIPIENTS:-}"
3535
# Git reference to notify about.
3636
VORTEX_NOTIFY_EMAIL_REF="${VORTEX_NOTIFY_EMAIL_REF:-${VORTEX_NOTIFY_REF:-}}"
3737

38+
# Git reference to notify about.
39+
VORTEX_NOTIFY_EMAIL_PR_NUMBER="${VORTEX_NOTIFY_EMAIL_PR_NUMBER:-${VORTEX_NOTIFY_PR_NUMBER:-}}"
40+
3841
# Environment URL to notify about.
3942
VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL="${VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL:-${VORTEX_NOTIFY_ENVIRONMENT_URL:-}}"
4043

@@ -68,11 +71,16 @@ else
6871
exit 1
6972
fi
7073

74+
ref_info="\"${VORTEX_NOTIFY_EMAIL_REF}\" branch"
75+
if [ -n "${VORTEX_NOTIFY_EMAIL_PR_NUMBER}" ]; then
76+
ref_info="\"PR-${VORTEX_NOTIFY_EMAIL_PR_NUMBER}\""
77+
fi
78+
7179
timestamp=$(date '+%d/%m/%Y %H:%M:%S %Z')
7280
subject="${VORTEX_NOTIFY_EMAIL_PROJECT} deployment notification of \"${VORTEX_NOTIFY_EMAIL_REF}\""
7381
content="## This is an automated message ##
7482
75-
Site ${VORTEX_NOTIFY_EMAIL_PROJECT} \"${VORTEX_NOTIFY_EMAIL_REF}\" branch has been deployed at ${timestamp} and is available at ${VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL}.
83+
Site ${VORTEX_NOTIFY_EMAIL_PROJECT} ${ref_info} has been deployed at ${timestamp} and is available at ${VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL}.
7684
7785
Login at: ${VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL}/user/login"
7886

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

129137
if [ -n "${sent}" ]; then
130138
note "Notification email(s) sent to: ${sent// /, }"
139+
note "Subject: ${subject}"
140+
note "Content: ${content}"
131141
else
132142
note "No notification emails were sent."
133143
fi

0 commit comments

Comments
 (0)