Skip to content

Commit

Permalink
Revert "feat: add scheduling messages (#453) (#457)" (#463)
Browse files Browse the repository at this point in the history
This reverts commit 229bffc.
  • Loading branch information
marboledacci committed Sep 20, 2024
1 parent 96ffc21 commit c0b82d5
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ workflows:
filters: *filters
exclude: RC010
- shellcheck/check:
shell: bash
shell: sh
filters: *filters
- bats/run:
path: ./src/tests
Expand Down
20 changes: 1 addition & 19 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,8 @@ jobs:
}
]
}
- slack/notify:
event: always
debug: true
step_name: "Custom template with scheduled offset"
scheduled_offset_seconds: 600 # 600 seconds after the job starts
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Sample sent using schedule offset after 5 minutes >"
}
}
]
}
- run:
name: Dynamically populate the mention and export the template as an environment variable
shell: bash -eo pipefail
command: |
echo 'export COMMIT_MESSAGE="This text comes from an environment variable"' >> $BASH_ENV
echo 'export SLACK_PARAM_MENTIONS="$COMMIT_MESSAGE"' >> $BASH_ENV
Expand Down Expand Up @@ -291,4 +273,4 @@ executors:
machine:
image: windows-server-2019-vs2019:current
resource_class: windows.medium
shell: powershell.exe
shell: bash.exe
26 changes: 0 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,6 @@ Post replies in threads with a special parameter `thread_id`. Including this par
}
```

## Scheduled Message

Set the `scheduled_offset_seconds` special parameter to a number of seconds if you want to post a scheduled message. Example:

```yaml
- slack/notify:
event: always
scheduled_offset_seconds: 30
custom: |
{
"blocks": [
{
"type": "section",
"fields": [
{
"type": "plain_text",
"text": "*This is a text notification*",
"emoji": true
}
]
}
]
}
```


---

## FAQ
Expand Down
9 changes: 0 additions & 9 deletions src/commands/notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,13 @@ parameters:
Any subsequent `notify` usage with the same identifier will be posted within the initial message's thread.
`thread_id` should be set to any arbitrary string to help you identify different threads. See examples for more information.
Enabling thread messages with this parameter implies using a very small amount of cacheing: ~200 B
scheduled_offset_seconds:
type: integer
default: 0
description: |
When set, the notification is a scheduled message.
steps:
- run:
shell: bash -eo pipefail
when: on_fail
name: Slack - Detecting Job Status (FAIL)
command: |
echo 'export CCI_STATUS="fail"' > /tmp/SLACK_JOB_STATUS
- run:
shell: bash -eo pipefail
when: on_success
name: Slack - Detecting Job Status (PASS)
command: |
Expand All @@ -115,7 +108,6 @@ steps:
when: always
- run:
when: always
shell: bash -eo pipefail
name: << parameters.step_name >>
environment:
SLACK_PARAM_EVENT: "<<parameters.event>>"
Expand All @@ -130,7 +122,6 @@ steps:
SLACK_PARAM_DEBUG: "<<parameters.debug>>"
SLACK_PARAM_CIRCLECI_HOST: "<<parameters.circleci_host>>"
SLACK_PARAM_THREAD: "<<parameters.thread_id>>"
SLACK_PARAM_OFFSET: "<<parameters.scheduled_offset_seconds>>"
SLACK_SCRIPT_NOTIFY: "<<include(scripts/notify.sh)>>"
SLACK_SCRIPT_UTILS: "<<include(scripts/utils.sh)>>"
# import pre-built templates using the orb-pack local script include.
Expand Down
37 changes: 0 additions & 37 deletions src/examples/scheduled_scheduled.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/scripts/main.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

# Workaround for Windows Support
# For details, see: https://github.com/CircleCI-Public/slack-orb/pull/380
Expand Down
23 changes: 2 additions & 21 deletions src/scripts/notify.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
# shellcheck disable=SC2016,SC3043

if [ "$SLACK_PARAM_DEBUG" -eq 1 ]; then
Expand Down Expand Up @@ -80,25 +80,7 @@ PostToSlack() {
echo "The message body being sent to Slack can be found below. To view redacted values, rerun the job with SSH and access: ${SLACK_MSG_BODY_LOG}"
echo "$SLACK_MSG_BODY"
fi

if [ "${SLACK_PARAM_OFFSET:0}" -ne 0 ]; then
if date --version >/dev/null 2>&1; then
# GNU date function
POST_AT=$(date -d "now + ${SLACK_PARAM_OFFSET} seconds" +%s)
elif date -v+1S >/dev/null 2>&1; then
# BSD date function
POST_AT=$(date -v"+${SLACK_PARAM_OFFSET}S" +%s)
else
# Alpine
POST_AT=$(date -u +%s | awk -v sec="$SLACK_PARAM_OFFSET" '{print $1 + sec}')
fi
SLACK_MSG_BODY=$(echo "$SLACK_MSG_BODY" | jq --arg post_at "$POST_AT" '.post_at = ($post_at|tonumber)')
# text is required for scheduled messages
SLACK_MSG_BODY=$(echo "$SLACK_MSG_BODY" | jq '.text = "Dummy fallback text"')
SLACK_SENT_RESPONSE=$(curl -s -f -X POST -H 'Content-type: application/json' -H "Authorization: Bearer $SLACK_ACCESS_TOKEN" --data "$SLACK_MSG_BODY" https://slack.com/api/chat.scheduleMessage)
else
SLACK_SENT_RESPONSE=$(curl -s -f -X POST -H 'Content-type: application/json' -H "Authorization: Bearer $SLACK_ACCESS_TOKEN" --data "$SLACK_MSG_BODY" https://slack.com/api/chat.postMessage)
fi
SLACK_SENT_RESPONSE=$(curl -s -f -X POST -H 'Content-type: application/json' -H "Authorization: Bearer $SLACK_ACCESS_TOKEN" --data "$SLACK_MSG_BODY" https://slack.com/api/chat.postMessage)

if [ "$SLACK_PARAM_DEBUG" -eq 1 ]; then
printf "%s\n" "$SLACK_SENT_RESPONSE" > "$SLACK_SENT_RESPONSE_LOG"
Expand Down Expand Up @@ -162,7 +144,6 @@ FilterBy() {
fi
# If any pattern supplied matches the current branch or the current tag, proceed; otherwise, exit with message.
FLAG_MATCHES_FILTER="false"
# shellcheck disable=SC2001
for i in $(echo "$1" | sed "s/,/ /g"); do
if echo "$2" | grep -Eq "^${i}$"; then
FLAG_MATCHES_FILTER="true"
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/false
# shellcheck shell=bash
# shellcheck shell=sh
# shellcheck disable=SC2154

detect_os() {
Expand Down

0 comments on commit c0b82d5

Please sign in to comment.