-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPSEXP-1806 Fix multiline/markdown support in slack notification #162
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.github/actions/send-slack-notification/compute-message.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash -e | ||
|
||
echo 'result<<EOF' | ||
|
||
if [ -n "$BLOCK_MESSAGE" ]; then | ||
echo -n "${BLOCK_MESSAGE}" | sed -z 's/\n/\\n/g' | ||
else | ||
case $EVENT_NAME in | ||
pull_request) | ||
echo -n "${PR_TITLE}" | sed -z 's/\n/\\n/g' | ||
;; | ||
issues) | ||
echo -n "${ISSUE_BODY}" | sed -z 's/\n/\\n/g' | ||
;; | ||
*) | ||
echo -n "${COMMIT_MESSAGE}" | sed -z 's/\n/\\n/g' | ||
;; | ||
esac | ||
fi | ||
|
||
echo '' | ||
echo 'EOF' |
95 changes: 95 additions & 0 deletions
95
.github/actions/send-slack-notification/tests/send-slack-notification.bats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
setup() { | ||
# Runs everywhere | ||
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" | ||
PATH="$DIR/..:$PATH" | ||
|
||
# Mock send-slack-notification defaults | ||
export PR_TITLE="fix(jx-updatebot-pr): update release binary version to 0.3.13 #158" | ||
export ISSUE_BODY=$(cat << 'body' | ||
This PR adds support for retrying `jx-updatebot-pr` action in case there is a race condition on the target pr branch due to a concurrent commit from another project, i.e. | ||
|
||
``` | ||
- uses: Alfresco/alfresco-build-tools/.github/actions/jx-updatebot-pr@ref | ||
with: | ||
retries: '3' | ||
retries-wait: '10' | ||
|
||
``` | ||
body | ||
) | ||
export COMMIT_MESSAGE=$(cat << 'commit' | ||
fix: update retry inputs to use string type | ||
|
||
* use strings | ||
* add tests | ||
commit | ||
) | ||
} | ||
|
||
@test "basic slack message" { | ||
export BLOCK_MESSAGE="my custom message" | ||
|
||
run compute-message.sh | ||
|
||
[ "$status" -eq 0 ] | ||
|
||
expected_output=$(cat << BATS | ||
result<<EOF | ||
my custom message | ||
EOF | ||
BATS | ||
) | ||
|
||
[ "$output" = "$expected_output" ] | ||
} | ||
|
||
@test "pull_request slack message" { | ||
export EVENT_NAME=pull_request | ||
|
||
run compute-message.sh | ||
|
||
[ "$status" -eq 0 ] | ||
|
||
expected_output=$(cat << BATS | ||
result<<EOF | ||
fix(jx-updatebot-pr): update release binary version to 0.3.13 #158 | ||
EOF | ||
BATS | ||
) | ||
|
||
[ "$output" = "$expected_output" ] | ||
} | ||
|
||
@test "multiline markdown for issues slack message" { | ||
export EVENT_NAME=issues | ||
|
||
run compute-message.sh | ||
|
||
[ "$status" -eq 0 ] | ||
|
||
expected_output=$(cat << 'BATS' | ||
result<<EOF | ||
This PR adds support for retrying `jx-updatebot-pr` action in case there is a race condition on the target pr branch due to a concurrent commit from another project, i.e.\n\n```\n- uses: Alfresco/alfresco-build-tools/.github/actions/jx-updatebot-pr@ref\n with:\n retries: '3'\n retries-wait: '10'\n\n``` | ||
EOF | ||
BATS | ||
) | ||
|
||
[ "$output" = "$expected_output" ] | ||
} | ||
|
||
@test "multiline commit message for default slack message" { | ||
export EVENT_NAME=whatever | ||
|
||
run compute-message.sh | ||
|
||
[ "$status" -eq 0 ] | ||
|
||
expected_output=$(cat << 'BATS' | ||
result<<EOF | ||
fix: update retry inputs to use string type\n\n* use strings\n* add tests | ||
EOF | ||
BATS | ||
) | ||
|
||
[ "$output" = "$expected_output" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about removing the
-n
switch fromecho
commands and removing that emptyecho
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is to avoid having that last newline converted to
\n
by sed, while I really want a NL before the closing heredoc tagecho "\nEOF"
would have worked as well but for some reason looked less clear to me :D