Skip to content

Commit

Permalink
feat: add inline logging when debug steps is true (#17)
Browse files Browse the repository at this point in the history
* log results

* add line number to log

* only log results if debug is true
  • Loading branch information
a-b-r-o-w-n authored Nov 20, 2020
1 parent 7ad2aeb commit 0c09837
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
5 changes: 5 additions & 0 deletions __tests__/processResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { CHECK_NAME, processResults } from "../src/processResults";

jest.mock("@actions/core", () => ({
debug: jest.fn(),
warning: jest.fn(),
error: jest.fn(),
startGroup: jest.fn(),
endGroup: jest.fn(),
isDebug: () => true,
}));

jest.mock("../src/inputs", () => ({
Expand Down
24 changes: 21 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145548,14 +145548,28 @@ const core = tslib_1.__importStar(__webpack_require__(42186));
const inputs_1 = tslib_1.__importDefault(__webpack_require__(7063));
const { GITHUB_WORKSPACE } = process.env;
exports.CHECK_NAME = "ESLint";
function logFileAnnotations(filePath, annotations) {
core.startGroup(filePath);
annotations.forEach((a) => {
const { message, annotation_level, start_line } = a;
if (annotation_level === "warning") {
core.warning(`${message} (Line ${start_line})`);
}
else {
core.error(`${message} (Line ${start_line})`);
}
});
core.endGroup();
}
function processResults(results) {
const annotations = [];
let errorCount = 0;
for (const result of results) {
const { filePath, messages } = result;
const relFilePath = filePath.replace(`${GITHUB_WORKSPACE}/`, "");
const fileAnnotations = [];
for (const lintMessage of messages) {
const { line, severity, ruleId, message } = lintMessage;
core.debug(`Level ${severity} issue found on line ${line} [${ruleId}] ${message}`);
// if ruleId is null, it's likely a parsing error, so let's skip it
if (!ruleId) {
continue;
Expand All @@ -145567,14 +145581,18 @@ function processResults(results) {
// skip message if quiet is true
continue;
}
annotations.push({
path: filePath.replace(`${GITHUB_WORKSPACE}/`, ""),
fileAnnotations.push({
path: relFilePath,
start_line: line,
end_line: line,
annotation_level: severity === 2 ? "failure" : "warning",
message: `[${ruleId}] ${message}`,
});
}
annotations.push(...fileAnnotations);
if (core.isDebug()) {
logFileAnnotations(relFilePath, fileAnnotations);
}
}
return {
conclusion: errorCount > 0 ? "failure" : "success",
Expand Down
27 changes: 23 additions & 4 deletions src/processResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ const { GITHUB_WORKSPACE } = process.env;

export const CHECK_NAME = "ESLint";

function logFileAnnotations(filePath: string, annotations: any[]) {
core.startGroup(filePath);
annotations.forEach((a) => {
const { message, annotation_level, start_line } = a;

if (annotation_level === "warning") {
core.warning(`${message} (Line ${start_line})`);
} else {
core.error(`${message} (Line ${start_line})`);
}
});
core.endGroup();
}

export function processResults(
results: ESLint.LintResult[]
): Partial<RestEndpointMethodTypes["checks"]["update"]["parameters"]> {
Expand All @@ -17,12 +31,12 @@ export function processResults(

for (const result of results) {
const { filePath, messages } = result;
const relFilePath = filePath.replace(`${GITHUB_WORKSPACE}/`, "");
const fileAnnotations: any[] = [];

for (const lintMessage of messages) {
const { line, severity, ruleId, message } = lintMessage;

core.debug(`Level ${severity} issue found on line ${line} [${ruleId}] ${message}`);

// if ruleId is null, it's likely a parsing error, so let's skip it
if (!ruleId) {
continue;
Expand All @@ -35,14 +49,19 @@ export function processResults(
continue;
}

annotations.push({
path: filePath.replace(`${GITHUB_WORKSPACE}/`, ""),
fileAnnotations.push({
path: relFilePath,
start_line: line,
end_line: line,
annotation_level: severity === 2 ? "failure" : "warning",
message: `[${ruleId}] ${message}`,
});
}

annotations.push(...fileAnnotations);
if (core.isDebug()) {
logFileAnnotations(relFilePath, fileAnnotations);
}
}

return {
Expand Down

0 comments on commit 0c09837

Please sign in to comment.