Skip to content

Commit a7cc58b

Browse files
authored
ci: use SLACK_CHANNEL env var for activity notifications (#16323)
# Overview Updates the activity notifications workflow and action scripts to read the Slack channel from a `SLACK_CHANNEL` secret rather than hardcoded constants. Also fixes a bug where step failures were silently swallowed. ## Key Changes - **Remove `CHANNELS` constants** - Deleted `src/constants.ts` and its imports from both action modules. The channel is now read from `process.env.SLACK_CHANNEL`, validated at startup with a `TypeError` if unset. - **Add `SLACK_CHANNEL` to workflow env** - `activity-notifications.yml` now passes `SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}`. This makes the target channel configurable without code changes. - **Remove `continue-on-error: true` from both steps** - Both steps had `continue-on-error: true`, which caused script failures to be reported as passed at the job level. Removing it surfaces failures correctly. ## Design Decisions `SLACK_CHANNEL` accepts either a channel name (e.g. `#payload-dev`) or a channel ID (e.g. `C1234567890`). Channel ID is recommended since it stays stable if the channel is renamed. The `DEBUG` routing logic (which previously switched between `CHANNELS.DEV` and `CHANNELS.DEBUG`) has been removed along with the constants. The channel is now set directly via the secret.
1 parent 6731036 commit a7cc58b

6 files changed

Lines changed: 15 additions & 16 deletions

File tree

.github/actions/activity/dist/new-issues/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/activity/dist/popular-issues/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/activity/src/constants.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/actions/activity/src/new-issues.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { info, setFailed } from '@actions/core'
22
import { getOctokit } from '@actions/github'
33
import { WebClient } from '@slack/web-api'
44

5-
import { CHANNELS } from './constants'
65
import { daysAgo } from './lib/utils'
76
import { SlimIssue } from './types'
87

@@ -42,9 +41,12 @@ export async function run() {
4241
try {
4342
if (!process.env.GITHUB_TOKEN) throw new TypeError('GITHUB_TOKEN not set')
4443
if (!process.env.SLACK_TOKEN) throw new TypeError('SLACK_TOKEN not set')
44+
if (!process.env.SLACK_CHANNEL) throw new TypeError('SLACK_CHANNEL not set')
4545

46-
const octoClient = getOctokit(process.env.GITHUB_TOKEN)
47-
const slackClient = new WebClient(process.env.SLACK_TOKEN)
46+
const { GITHUB_TOKEN, SLACK_TOKEN, SLACK_CHANNEL } = process.env
47+
48+
const octoClient = getOctokit(GITHUB_TOKEN)
49+
const slackClient = new WebClient(SLACK_TOKEN)
4850

4951
const { data } = await octoClient.rest.search.issuesAndPullRequests({
5052
order: 'desc',
@@ -70,7 +72,7 @@ export async function run() {
7072

7173
await slackClient.chat.postMessage({
7274
text: messageText,
73-
channel: process.env.DEBUG === 'true' ? CHANNELS.DEBUG : CHANNELS.DEV,
75+
channel: SLACK_CHANNEL,
7476
icon_emoji: ':github:',
7577
username: 'GitHub Notifier',
7678
})

.github/actions/activity/src/popular-issues.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { info, setFailed } from '@actions/core'
22
import { getOctokit } from '@actions/github'
33
import { WebClient } from '@slack/web-api'
44

5-
import { CHANNELS } from './constants'
65
import { daysAgo } from './lib/utils'
76
import { SlimIssue } from './types'
87

@@ -51,9 +50,12 @@ export async function run() {
5150
try {
5251
if (!process.env.GITHUB_TOKEN) throw new TypeError('GITHUB_TOKEN not set')
5352
if (!process.env.SLACK_TOKEN) throw new TypeError('SLACK_TOKEN not set')
53+
if (!process.env.SLACK_CHANNEL) throw new TypeError('SLACK_CHANNEL not set')
5454

55-
const octoClient = getOctokit(process.env.GITHUB_TOKEN)
56-
const slackClient = new WebClient(process.env.SLACK_TOKEN)
55+
const { GITHUB_TOKEN, SLACK_TOKEN, SLACK_CHANNEL } = process.env
56+
57+
const octoClient = getOctokit(GITHUB_TOKEN)
58+
const slackClient = new WebClient(SLACK_TOKEN)
5759

5860
const { data } = await octoClient.rest.search.issuesAndPullRequests({
5961
order: 'desc',
@@ -79,7 +81,7 @@ export async function run() {
7981

8082
await slackClient.chat.postMessage({
8183
text: messageText,
82-
channel: process.env.DEBUG === 'true' ? CHANNELS.DEBUG : CHANNELS.DEV,
84+
channel: SLACK_CHANNEL,
8385
icon_emoji: ':github:',
8486
username: 'GitHub Notifier',
8587
})

.github/workflows/activity-notifications.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ jobs:
2121
uses: ./.github/actions/setup
2222
- name: Popular Issues to Slack
2323
run: node ./.github/actions/activity/dist/popular-issues/index.js
24-
continue-on-error: true
2524
- name: New Issues to Slack
2625
run: node ./.github/actions/activity/dist/new-issues/index.js
27-
continue-on-error: true
2826
env:
2927
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3028
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
29+
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
3130
DEBUG: ${{ github.event.inputs.debug || 'false' }}

0 commit comments

Comments
 (0)