-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
In the following code block on src/discord/index.ts:
export const sendDiscordItemMessage = async (
message: DiscordItemMessage,
): Promise<Result<any, Error>> => {
const webhookUrl = process.env.DISCORD_CHANNEL_WEBHOOK_URL ?? "";
const messageHeader = formatMessageTitle(message.title, message.message);
const messageSections = message.sections.map((section) => {
const sectionHeader = formatMessageSectionTitle(section.title);
const sectionItems = section.items
.map((item) => formatItem(item))
.join("\n");
return `${sectionHeader} ${sectionItems}`;
});
try {
const response = await axios.post(webhookUrl, {
content: `${messageHeader} ${messageSections.join()}`,
});
return Ok(response.data);
} catch (error) {
return Err(new Error("Failed to send Discord message"));
}
};
The lines...
const messageHeader = formatMessageTitle(message.title, message.message);
const messageSections = message.sections.map((section) => {
const sectionHeader = formatMessageSectionTitle(section.title);
const sectionItems = section.items
.map((item) => formatItem(item))
.join("\n");
return `${sectionHeader} ${sectionItems}`;
});
and
content: `${messageHeader} ${messageSections.join()}`,
Should be separated into a separate method that has the single responsibility of building a discord message.
In addition to making this minor refactor, please also write some tests that method on test/discord/index.ts
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
Unrefined