Skip to content

Commit

Permalink
Add support for filtering which releases get posted to slack
Browse files Browse the repository at this point in the history
  • Loading branch information
adierkens committed Jul 13, 2023
1 parent d2785b9 commit 00f43aa
Showing 1 changed file with 31 additions and 8 deletions.
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

0 comments on commit 00f43aa

Please sign in to comment.