diff --git a/src/index.ts b/src/index.ts index 3e0a819..59f99bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { Probot } from 'probot'; import { EventPayloads } from '@octokit/webhooks'; import { WebClient } from '@slack/web-api'; +import { isQuietPeriod } from './util'; const API_REVIEW_REQUESTED_LABEL_ID = 1603621692; // api-review/requested const { SLACK_BOT_TOKEN, NODE_ENV } = process.env; @@ -21,11 +22,12 @@ async function postToSlack(pr: EventPayloads.WebhookPayloadPullRequestPullReques /[&<>]/g, (x) => ({ '&': '&', '<': '<', '>': '>' })[x]!, ); + const name = isQuietPeriod() ? 'API WG' : ''; await slack.chat.postMessage({ channel: '#wg-api', unfurl_links: false, text: - `Hey ! Just letting you know that the following PR needs API review:\n` + + `Hey ${name}! Just letting you know that the following PR needs API review:\n` + `*<${pr._links.html.href}|${escapedTitle} (#${pr.number})>*`, }); } diff --git a/src/remind.ts b/src/remind.ts index ed785e1..b1d0cdf 100644 --- a/src/remind.ts +++ b/src/remind.ts @@ -1,5 +1,6 @@ import { ProbotOctokit } from 'probot'; import { WebClient } from '@slack/web-api'; +import { isQuietPeriod } from './util'; const { SLACK_BOT_TOKEN, NODE_ENV } = process.env; if (!SLACK_BOT_TOKEN && NODE_ENV !== 'test') { @@ -18,7 +19,9 @@ async function main() { q: `repo:electron/electron ${q}`, sort: 'created', }); - if (items.length) { + + // silence during quiet period + if (items.length && !isQuietPeriod()) { const text = `:blob-wave: *Reminder:* the <${searchUrl}|following PRs> are awaiting API review.\n` + items diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..cae9363 --- /dev/null +++ b/src/util.ts @@ -0,0 +1,6 @@ +/** + * If the current date on runtime matches Electron's quiet period + */ +export function isQuietPeriod() { + return new Date().getMonth() === 11; +} diff --git a/test/index.test.ts b/test/index.test.ts index 1e11d19..2ff8ab8 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -29,17 +29,39 @@ describe('New PR Slack Notifications', () => { probot.load(zoilist); }); - it('posts to slack when the api-review/requested label is added', async () => { - const payload = require('./fixtures/pull_request.labeled.semver_minor.json'); + afterEach(() => { + jest.useRealTimers(); + }); - await probot.receive({ name: 'pull_request', payload, id: 'abc123' }); + describe('when the `api-review/requested` label is added', () => { + it('posts to slack', async () => { + jest.useFakeTimers('modern').setSystemTime(new Date('2023-11-11')); + const payload = require('./fixtures/pull_request.labeled.semver_minor.json'); + + await probot.receive({ name: 'pull_request', payload, id: 'abc123' }); + + expect(client.chat.postMessage).toHaveBeenCalledWith({ + channel: '#wg-api', + unfurl_links: false, + text: + `Hey ! Just letting you know that the following PR needs API review:\n` + + '**', + }); + }); + + it('does not @mention anyone in the month of December', async () => { + jest.useFakeTimers('modern').setSystemTime(new Date('2023-12-25')); + const payload = require('./fixtures/pull_request.labeled.semver_minor.json'); + + await probot.receive({ name: 'pull_request', payload, id: 'abc123' }); - expect(client.chat.postMessage).toHaveBeenCalledWith({ - channel: '#wg-api', - unfurl_links: false, - text: - `Hey ! Just letting you know that the following PR needs API review:\n` + - '**', + expect(client.chat.postMessage).toHaveBeenCalledWith({ + channel: '#wg-api', + unfurl_links: false, + text: + `Hey API WG! Just letting you know that the following PR needs API review:\n` + + '**', + }); }); });