Skip to content

Commit 358cb08

Browse files
committed
Factor out nested template literals
1 parent 1398321 commit 358cb08

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/slack.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,19 @@ const markdown = (text: string): MrkdwnElement => ({ text, type: "mrkdwn" });
158158
const plainText = (text: string): PlainTextElement => ({ text, type: "plain_text" });
159159

160160
const repoSection = ({ repoName, repoUrl, userLogin, userName, userUrl }: Repository): SectionBlock => {
161-
const repoLink = `<${repoUrl}|\`${repoName}\`>`;
161+
const repoLink = `<${repoUrl}|${code(repoName)}>`;
162162
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- also handles empty name case ""
163-
const userLink = `<${userUrl}|${userName ? userName : `\`${userLogin}\``}>`;
163+
const userLink = `<${userUrl}|${userName || code(userLogin)}>`;
164164
const lines = [`A new repository ${repoLink} was just created by ${userLink}.`];
165165
const match = /-\d+$/.exec(repoUrl);
166166
if (match !== null) {
167-
lines.push(`:redflag: *The \`${match[0]}\` makes this likely a mistake.*`);
167+
lines.push(`:redflag: *The ${code(match[0])} makes this likely a mistake.*`);
168168
}
169169
return ({
170170
type: "section",
171171
text: markdown(lines.join("\n")),
172172
});
173173
};
174+
175+
/** Format the value as inline code. */
176+
const code = (value: string): string => `\`${value}\``;

0 commit comments

Comments
 (0)