Skip to content

Commit

Permalink
problem count option
Browse files Browse the repository at this point in the history
  • Loading branch information
DE7924 committed Jan 3, 2025
1 parent 4991bfb commit 35eda05
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 25 deletions.
34 changes: 22 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,18 @@ export const runCommand = async (

export const buildComment = async (
response: StepResponse,
outputStr: string,
label: string,
outputStr?: string,
problemsCount?: number,
): Promise<StepResponse> => {
if (response.error == true) {
response.output = `${failedEmoji} - ${label}\n<details><summary>See Details</summary>${outputStr}</details>`;
if (problemsCount !== undefined) {
response.output = `${failedEmoji} - ${label}: ${problemsCount} problem${
problemsCount > 1 ? "s" : ""
} found\n<details><summary>See Details</summary>${outputStr}</details>`;
} else {
response.output = `${failedEmoji} - ${label}\n<details><summary>See Details</summary>${outputStr}</details>`;
}
} else {
response.output = `${passedEmoji} - ${label}\n`;
}
Expand All @@ -75,7 +82,7 @@ export const commandComment = async (
command: Command,
): Promise<StepResponse> => {
const [response, outputStr] = await runCommand(command);
return await buildComment(response, outputStr, command.label);
return await buildComment(response, command.label, outputStr);
};

const checkIfLocal = (): boolean => {
Expand Down
10 changes: 5 additions & 5 deletions src/scripts/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export const checkModifiedFiles = async (
const response = { output: "", error: false };
if (str.trim() !== "") {
filesModified = true;
return await buildComment(response, str, command.label);
return await buildComment(response, command.label, str);
} else {
return await buildComment(response, str, command.label);
return await buildComment(response, command.label, str);
}
})
.catch(async (error) => {
setFailed(`Failed to check for modified files: ${error as string}`);
const response = { output: "", error: true };
return await buildComment(response, error.message, command.label);
return await buildComment(response, command.label, error.message);
});

return [result, filesModified];
Expand All @@ -33,13 +33,13 @@ export const updateChanges = async (
await runBashCommand(cmd).catch(async (error) => {
setFailed(`Failed to execute command "${cmd}": ${error as string}`);
response.error = true;
response = await buildComment(response, error.message, command.label);
response = await buildComment(response, command.label, error.message);
return;
});
}

if (response.error === false) {
response = await buildComment(response, "", command.label);
response = await buildComment(response, command.label);
}

return response;
Expand Down
13 changes: 9 additions & 4 deletions src/scripts/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const testing = async (
setFailed(`Failed to read test results: ${error as string}`);
}

let problemCount = 0;
if (response.error && failedToReadFile == false) {
const jsonResults = JSON.parse(
convert.xml2json(testResults, { compact: false, spaces: 2 }),
Expand Down Expand Up @@ -81,6 +82,7 @@ export const testing = async (
);

if (testCaseFailure) {
problemCount++;
const file = testCase["attributes"]["file"];
const line = testCase["attributes"]["line"];
const failureType = testCaseFailure["attributes"]["type"];
Expand All @@ -92,7 +94,7 @@ export const testing = async (

outputStr += "</table>";
}
return await buildComment(response, outputStr, command.label);
return await buildComment(response, command.label, outputStr, problemCount);
};

export const typeDoc = async (command: Command): Promise<StepResponse> => {
Expand All @@ -110,7 +112,6 @@ export const typeDoc = async (command: Command): Promise<StepResponse> => {
response.error = true;
setFailed(`Failed ${command.label}: ${error as string}`);
}
console.log("commandOutput: ", commandOutput);

if (response.error) {
commandOutput = commandOutput.replace(/\[\d+m/g, "");
Expand All @@ -126,9 +127,13 @@ export const typeDoc = async (command: Command): Promise<StepResponse> => {
})
.join("");
const outputStr = `<table><tr><th>File</th><th>Line</th><th>Column</th><th>Message</th></tr>${table}</table>`;
return await buildComment(response, outputStr, command.label);
const [_, errors, warnings] = lines.filter((line) => {
return line.match(/^Found (\d+) errors and (\d+) warnings/);
});
const problemCount = parseInt(errors) + parseInt(warnings);
return await buildComment(response, command.label, outputStr, problemCount);
}
return await buildComment(response, "", command.label);
return await buildComment(response, command.label);
};

const loadCoverageData = (coveragePath: string): LCOVRecord[] | undefined => {
Expand Down

0 comments on commit 35eda05

Please sign in to comment.