Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 93 additions & 64 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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "web-components-code-quality",
"description": "This action is designed to format and test Web Component repositories on pull requests. It helps ensure that your code meets the required quality standards.",
"version": "0.0.1",
"version": "1.3.4",
"author": "Zebra Technologies",
"private": false,
"homepage": "https://github.com/ZebraDevs/web-components-code-quality",
Expand Down
31 changes: 16 additions & 15 deletions src/scripts/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,28 @@ export const eslint = async (command: Command): Promise<StepResponse> => {
* successfully, it builds a simple success comment.
*/
export const litAnalyzer = async (command: Command): Promise<StepResponse> => {
let [response, outputStr] = await runCommand(command);
const [response, initialOutputStr] = await runCommand(command);
let outputStr = initialOutputStr;
let problemCount = 0;
if (response.error == true) {

if (response.error) {
const lines = outputStr.split("\n");
const problemsCountStr = lines
.map((line) => {
const match = line.match(
/^\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|$/,
);
if (match) {
const [filesChecked, filesWithProblems, problems, errors, warnings] =
match;
return problems;
}
})
.join("");
const problemsCountStr = lines.reduce((acc, line) => {
const match = line.match(
/^\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|$/,
);
if (match) {
const [, , , problems] = match;
return acc + problems;
}
return acc;
}, "");

problemCount = parseInt(problemsCountStr);
problemCount = parseInt(problemsCountStr, 10) || 0;

outputStr = outputStr.split("...").pop() || outputStr;
}

return await buildComment(response, command.label, outputStr, problemCount);
};

Expand Down
33 changes: 33 additions & 0 deletions src/scripts/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { getOctokit } from "@actions/github";
import { Context } from "@actions/github/lib/context";
import { failedEmoji, passedEmoji, StepResponse } from "src/main";

/**
* Generates a formatted message for a group of steps.
*
* @param {string} name - The name of the group.
* @param {StepResponse[]} steps - An array of step responses.
* @param {boolean} showOnPass - A boolean indicating whether to show the message even if all steps pass.
* @returns {string} A formatted string message for the group of steps.
*/
const group = (
name: string,
steps: StepResponse[],
Expand All @@ -20,6 +28,12 @@ const group = (
}
};

/**
* Generates an HTML list item (`<li>`) element containing the provided string.
*
* @param {string} str - The string to be included within the list item.
* @returns {string} The HTML string representing the list item.
*/
const li = (str: string): string => {
return `
<li>
Expand All @@ -28,6 +42,25 @@ const li = (str: string): string => {
`;
};

/**
* Posts a comment on a GitHub issue or pull request summarizing the results of various checks.
* If a comment with the summary already exists, it updates the comment instead.
*
* @param {ReturnType<typeof getOctokit>} ocotokit - The Octokit instance for making GitHub API requests.
* @param {Context} context - The context of the GitHub action, including issue and repository information.
* @param {StepResponse | undefined} npmIStr - The result of the npm install step.
* @param {StepResponse | undefined} cemStr - The result of the custom element manifest step.
* @param {StepResponse | undefined} eslintStr - The result of the ESLint step.
* @param {StepResponse | undefined} litAnalyzerStr - The result of the Lit Analyzer step.
* @param {StepResponse | undefined} prettierStr - The result of the Prettier formatting step.
* @param {StepResponse | undefined} playwrightStr - The result of the Playwright testing step.
* @param {StepResponse | undefined} testingStr - The result of the general testing step.
* @param {StepResponse | undefined} coverageStr - The result of the code coverage step.
* @param {StepResponse | undefined} typeDocStr - The result of the TypeDoc documentation generation step.
* @param {StepResponse | undefined} checkModifiedFilesStr - The result of the check for modified files step.
* @param {StepResponse | undefined} updateChangesStr - The result of the update changes step.
* @returns {Promise<StepResponse>} A promise that resolves to a StepResponse indicating the success or failure of the comment operation.
*/
export const comment = async (
ocotokit: ReturnType<typeof getOctokit>,
context: Context,
Expand Down
Loading
Loading