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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ const urlPluginOptions = t.intersection([
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 @@ const appPluginOptions = t.intersection([
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 @@ export default class SlackPlugin implements IPlugin {
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))
) {
return;
}

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

await this.createPost(auto, header, sanitizedNotes, releases, agent);
}
);
}
Expand Down