Skip to content

Commit

Permalink
Properly escape backticks in error messages (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Aug 19, 2024
1 parent 281dae2 commit f974860
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import mdEscape = require("markdown-escape");
import randomSeed = require("random-seed");
import { getErrorMessageFromStack, getHash, getHashForStack } from "./utils/hashStackTrace";
import { createCopyingOverlayFS, createTempOverlayFS, OverlayBaseFS } from "./utils/overlayFS";
import { asMarkdownInlineCode } from "./utils/markdownUtils";

interface Params {
/**
Expand Down Expand Up @@ -434,7 +435,7 @@ ${summary.replayScript}
`;
// No url means is user test repo
if (!summary.repo.url) {
text += `# Manually download user test \`${summary.repo.name}\`\n`;
text += `# Manually download user test ${asMarkdownInlineCode(summary.repo.name)}\n`;
}
else {
text += `git clone ${summary.repo.url} --recurse-submodules\n`;
Expand Down Expand Up @@ -512,7 +513,7 @@ ${summary.replayScript}
`;
// No url means is user test repo
if (!summary.repo.url) {
text += `# Manually download user test \`${summary.repo.name}\`\n`;
text += `# Manually download user test ${asMarkdownInlineCode(summary.repo.name)}\n`;
}
else {
text += `git clone ${summary.repo.url} --recurse-submodules\n`;
Expand Down Expand Up @@ -721,15 +722,15 @@ export async function getTscRepoResult(
summary += `### ${makeMarkdownLink(projectUrl)}\n`;

for (const errorMessage of newlyReportedErrorMessages) {
summary += ` - ${buildWithNewWhenOldFails ? "[NEW] " : ""}\`${errorMessage}\`\n`;
summary += ` - ${buildWithNewWhenOldFails ? "[NEW] " : ""}${asMarkdownInlineCode(errorMessage)}\n`;

for (const error of newlyReportedErrorMessageMap.get(errorMessage)!) {
summary += ` - ${error.fileUrl ? makeMarkdownLink(error.fileUrl) : "Project Scope"}${isComposite ? ` in ${makeMarkdownLink(error.projectUrl)}` : ``}\n`;
}
}

for (const errorMessage of newlyUnreportedErrorMessages) {
summary += ` - ${buildWithNewWhenOldFails ? "[MISSING] " : ""}\`${errorMessage}\`\n`;
summary += ` - ${buildWithNewWhenOldFails ? "[MISSING] " : ""}${asMarkdownInlineCode(errorMessage)}\n`;

for (const error of newlyUnreportedErrorMessageMap.get(errorMessage)!) {
summary += ` - ${error.fileUrl ? makeMarkdownLink(error.fileUrl) : "Project Scope"}${isComposite ? ` in ${makeMarkdownLink(error.projectUrl)}` : ``}\n`;
Expand Down
3 changes: 2 additions & 1 deletion src/postGithubComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path = require("path");
import { artifactFolderUrlPlaceholder, getArtifactsApiUrlPlaceholder, Metadata, metadataFileName, RepoStatus, resultFileNameSuffix } from "./main";
import git = require("./utils/gitUtils");
import pu = require("./utils/packageUtils");
import { asMarkdownInlineCode } from "./utils/markdownUtils";

const { argv } = process;

Expand Down Expand Up @@ -76,7 +77,7 @@ const outputs = resultPaths.map(p =>
.replaceAll(getArtifactsApiUrlPlaceholder, getArtifactsApi));

const suiteDescription = isTopReposRun ? `top ${repoCount} repos` : "user tests";
let header = `@${userToTag} Here are the results of running the ${suiteDescription} with ${entrypoint} comparing \`${oldTscResolvedVersion}\` and \`${newTscResolvedVersion}\`:
let header = `@${userToTag} Here are the results of running the ${suiteDescription} with ${entrypoint} comparing ${asMarkdownInlineCode(oldTscResolvedVersion ?? "old")} and ${asMarkdownInlineCode(newTscResolvedVersion ?? "new")}:
${summary.join("\n")}`;

Expand Down
9 changes: 9 additions & 0 deletions src/utils/markdownUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function asMarkdownInlineCode(s: string) {
let backticks = "`";
let space = "";
while (s.includes(backticks)) {
backticks += "`";
space = " "
}
return `${backticks}${space}${s}${space}${backticks}`;
}

0 comments on commit f974860

Please sign in to comment.