Skip to content
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

Add filtering support to slack plugin #2376

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 31 additions & 8 deletions plugins/slack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@
basePluginOptions,
]);

const messageFilterOptions = t.partial({
filter: t.partial({
/** Only post when these packages are changed */
packages: t.array(t.string),
/** Only post when these strings are found */
search: t.array(t.string),
}),
});

const appPluginOptions = t.intersection([
t.interface({
/** Marks we are gonna use app auth */
Expand All @@ -233,7 +242,10 @@
basePluginOptions,
]);

const pluginOptions = t.union([urlPluginOptions, appPluginOptions]);
const pluginOptions = t.intersection([
t.union([urlPluginOptions, appPluginOptions]),
messageFilterOptions,
]);

export type ISlackPluginOptions = t.TypeOf<typeof pluginOptions>;

Expand Down Expand Up @@ -331,13 +343,24 @@
const proxyUrl = process.env.https_proxy || process.env.http_proxy;
const agent = proxyUrl ? createHttpsProxyAgent(proxyUrl) : undefined;

await this.createPost(
auto,
header,
sanitizeMarkdown(releaseNotes),
releases,
agent
);
const sanitizedNotes = sanitizeMarkdown(releaseNotes);

if (
this.options.filter?.packages &&
!this.options.filter.packages.some((p) => releaseNotes.includes(p))

Check warning on line 350 in plugins/slack/src/index.ts

View check run for this annotation

Codecov / codecov/patch

plugins/slack/src/index.ts#L350

Added line #L350 was not covered by tests
) {
return;

Check warning on line 352 in plugins/slack/src/index.ts

View check run for this annotation

Codecov / codecov/patch

plugins/slack/src/index.ts#L352

Added line #L352 was not covered by tests
}

// Only post if the search strings match the filter
if (
this.options.filter?.search &&
!this.options.filter.search.some((p) => releaseNotes.includes(p))

Check warning on line 358 in plugins/slack/src/index.ts

View check run for this annotation

Codecov / codecov/patch

plugins/slack/src/index.ts#L358

Added line #L358 was not covered by tests
) {
return;

Check warning on line 360 in plugins/slack/src/index.ts

View check run for this annotation

Codecov / codecov/patch

plugins/slack/src/index.ts#L360

Added line #L360 was not covered by tests
}

await this.createPost(auto, header, sanitizedNotes, releases, agent);
}
);
}
Expand Down Expand Up @@ -440,7 +463,7 @@
content: message.code,
title: languageMap[message.language] || message.language,
filetype: languageMap[message.language] || message.language,
}) as any,

Check warning on line 466 in plugins/slack/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
headers: {
"Content-Type":
"application/x-www-form-urlencoded; charset=utf-8",
Expand Down