Skip to content

Commit de4a68e

Browse files
authored
Documentation (#11)
* comment, coverage, post, testing docs * remove comment * Build
1 parent cc39f7d commit de4a68e

File tree

8 files changed

+195
-141
lines changed

8 files changed

+195
-141
lines changed

dist/index.js

Lines changed: 93 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "web-components-code-quality",
33
"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.",
4-
"version": "0.0.1",
4+
"version": "1.3.4",
55
"author": "Zebra Technologies",
66
"private": false,
77
"homepage": "https://github.com/ZebraDevs/web-components-code-quality",

src/scripts/analyze.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,28 @@ export const eslint = async (command: Command): Promise<StepResponse> => {
5050
* successfully, it builds a simple success comment.
5151
*/
5252
export const litAnalyzer = async (command: Command): Promise<StepResponse> => {
53-
let [response, outputStr] = await runCommand(command);
53+
const [response, initialOutputStr] = await runCommand(command);
54+
let outputStr = initialOutputStr;
5455
let problemCount = 0;
55-
if (response.error == true) {
56+
57+
if (response.error) {
5658
const lines = outputStr.split("\n");
57-
const problemsCountStr = lines
58-
.map((line) => {
59-
const match = line.match(
60-
/^\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|$/,
61-
);
62-
if (match) {
63-
const [filesChecked, filesWithProblems, problems, errors, warnings] =
64-
match;
65-
return problems;
66-
}
67-
})
68-
.join("");
59+
const problemsCountStr = lines.reduce((acc, line) => {
60+
const match = line.match(
61+
/^\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|$/,
62+
);
63+
if (match) {
64+
const [, , , problems] = match;
65+
return acc + problems;
66+
}
67+
return acc;
68+
}, "");
6969

70-
problemCount = parseInt(problemsCountStr);
70+
problemCount = parseInt(problemsCountStr, 10) || 0;
7171

7272
outputStr = outputStr.split("...").pop() || outputStr;
7373
}
74+
7475
return await buildComment(response, command.label, outputStr, problemCount);
7576
};
7677

src/scripts/comment.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { getOctokit } from "@actions/github";
33
import { Context } from "@actions/github/lib/context";
44
import { failedEmoji, passedEmoji, StepResponse } from "src/main";
55

6+
/**
7+
* Generates a formatted message for a group of steps.
8+
*
9+
* @param {string} name - The name of the group.
10+
* @param {StepResponse[]} steps - An array of step responses.
11+
* @param {boolean} showOnPass - A boolean indicating whether to show the message even if all steps pass.
12+
* @returns {string} A formatted string message for the group of steps.
13+
*/
614
const group = (
715
name: string,
816
steps: StepResponse[],
@@ -20,6 +28,12 @@ const group = (
2028
}
2129
};
2230

31+
/**
32+
* Generates an HTML list item (`<li>`) element containing the provided string.
33+
*
34+
* @param {string} str - The string to be included within the list item.
35+
* @returns {string} The HTML string representing the list item.
36+
*/
2337
const li = (str: string): string => {
2438
return `
2539
<li>
@@ -28,6 +42,25 @@ const li = (str: string): string => {
2842
`;
2943
};
3044

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

0 commit comments

Comments
 (0)