Skip to content

Commit dde431b

Browse files
authored
Support summary message error reactions (#140)
1 parent c3af984 commit dde431b

File tree

17 files changed

+306
-107
lines changed

17 files changed

+306
-107
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Post [GitHub Action](https://github.com/features/actions) deploy workflow progre
1313
- Posts summary message at beginning of the deploy workflow, surfacing commit message and author
1414
- Maps GitHub commit author to Slack user by full name, mentioning them in the summary message
1515
- Threads intermediate stage completions, sending unexpected failures back to the channel
16+
- Adds summary message reaction to unsuccessful jobs (useful with [Reacji Channeler](https://reacji-channeler.builtbyslack.com/))
1617
- Updates summary message duration at conclusion of the workflow
1718
- Supports `pull_request`, `push`, `release`, `schedule`, and `workflow_dispatch` [event types](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows)
1819

@@ -22,6 +23,7 @@ Post [GitHub Action](https://github.com/features/actions) deploy workflow progre
2223
1. Under **OAuth & Permissions**, add two Bot Token Scopes:
2324
1. [`chat:write`](https://api.slack.com/scopes/chat:write) to post messages
2425
1. [`chat:write.customize`](https://api.slack.com/scopes/chat:write.customize) to customize messages with GitHub commit author
26+
1. [`reactions:write`](https://api.slack.com/scopes/reactions:write) to add summary message error reactions
2527
1. [`users:read`](https://api.slack.com/scopes/users:read) to map GitHub user to Slack user
2628
1. Install the app to your workspace
2729
1. Copy the app's **Bot User OAuth Token** from the **OAuth & Permissions** page
@@ -39,10 +41,11 @@ on:
3941
branches:
4042
- main
4143

42-
# 1. Configure required environment variables
44+
# 1. Configure environment variables
4345
env:
44-
SLACK_DEPLOY_BOT_TOKEN: ${{ secrets.SLACK_DEPLOY_BOT_TOKEN }}
45-
SLACK_DEPLOY_CHANNEL: 'C040YVCUDRR' # replace with your Slack Channel ID
46+
SLACK_DEPLOY_BOT_TOKEN: ${{ secrets.SLACK_DEPLOY_BOT_TOKEN }} # required
47+
SLACK_DEPLOY_CHANNEL: 'C040YVCUDRR' # required - replace with your Slack Channel ID
48+
SLACK_DEPLOY_ERROR_REACTION: 'x' # optional emoji name added as non-successful summary message reaction
4649

4750
jobs:
4851
staging:
@@ -89,12 +92,11 @@ jobs:
8992

9093
## Environment Variables
9194

92-
Both environment variables are _required_.
93-
94-
| variable | description |
95-
| ------------------------ | -------------------------- |
96-
| `SLACK_DEPLOY_BOT_TOKEN` | Slack Bot User OAuth Token |
97-
| `SLACK_DEPLOY_CHANNEL` | Slack Channel ID |
95+
| variable | description |
96+
| ----------------------------- | --------------------------------------- |
97+
| `SLACK_DEPLOY_BOT_TOKEN` | **Required** Slack bot user OAuth token |
98+
| `SLACK_DEPLOY_CHANNEL` | **Required** Slack channel ID |
99+
| `SLACK_DEPLOY_ERROR_REACTION` | Optional Slack emoji name |
98100

99101
## Inputs
100102

dist/index.js

Lines changed: 113 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__tests__/postMessage.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ describe('postMessage', () => {
2424

2525
slack = {
2626
postMessage: jest.fn(async () => 'TS'),
27-
updateMessage: jest.fn(async () => undefined)
27+
updateMessage: jest.fn(async () => undefined),
28+
maybeAddErrorReaction: jest.fn(async () => undefined)
2829
} as unknown as SlackClient
2930

3031
jest.resetModules()
@@ -375,6 +376,10 @@ describe('postMessage', () => {
375376
expect(slack.updateMessage).not.toHaveBeenCalled()
376377
})
377378

379+
it('should not add error reaction', () => {
380+
expect(slack.maybeAddErrorReaction).not.toHaveBeenCalledWith()
381+
})
382+
378383
it('should not return timestamp ID', () => {
379384
expect(ts).toBe(null)
380385
})
@@ -437,6 +442,12 @@ describe('postMessage', () => {
437442
})
438443
)
439444
})
445+
446+
it('should add error reaction', () => {
447+
expect(slack.maybeAddErrorReaction).toHaveBeenCalledWith({
448+
ts: '1662768000' // 2022-09-10T00:00:00.000Z
449+
})
450+
})
440451
})
441452

442453
describe('conclusion success', () => {

0 commit comments

Comments
 (0)