Skip to content

Commit

Permalink
Add titles to Lintje annotations
Browse files Browse the repository at this point in the history
Add a name to the GitHub Action annotations so it's clear what action
the annotations are from.
  • Loading branch information
tombruijn committed Jun 26, 2022
1 parent c280bdf commit 59ff073
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## v0.7.1 - updated 2022-06-26

### Changed

- Add titles to Lintje annotations. Makes it easier to tell which action the
annotation is coming from.

### Fixed

- Remove colorized output from GitHub workflow summary annotations. Colorized
Expand Down
28 changes: 21 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69197,6 +69197,8 @@ const cache = __nccwpck_require__(7799);
const { LINTJE_VERSION } = __nccwpck_require__(9554);
const { download } = __nccwpck_require__(1608);

const annotationOptions = { title: "Lintje (Git Linter)" };

function runLintje(commitCount) {
const commitRange = commitArgument(commitCount);
const env = {};
Expand Down Expand Up @@ -69248,9 +69250,9 @@ function handleSuccess(stdout) {
const { statusLine, issueLines } = splitOutput(stdout);
if (statusLine.endsWith(" hint") || statusLine.endsWith(" hints")) {
core.info(issueLines);
core.notice(removeColorOutput(statusLine));
logNotice(removeColorOutput(statusLine));
} else {
core.notice("Lintje has found no issues.");
logNotice("Lintje has found no issues.");
}
}

Expand All @@ -69277,6 +69279,18 @@ async function downloadIfNotCached() {
await cache.saveCache(paths, cacheKey);
}

function logNotice(string) {
core.notice(string, annotationOptions);
}

function logWarning(string) {
core.warning(string, annotationOptions);
}

function logError(string) {
core.error(string, annotationOptions);
}

async function main() {
try {
await downloadIfNotCached();
Expand All @@ -69287,7 +69301,7 @@ async function main() {

if (error) {
core.info(stdout);
core.warning((stderr || "").toString());
logWarning((stderr || "").toString());
core.setFailed(`Lintje failed with status code "${status}": ${error}`);
return;
}
Expand All @@ -69297,25 +69311,25 @@ async function main() {
handleSuccess(stdout);

if (stderr) {
core.warning(stderr.toString());
logWarning(stderr.toString());
}
break;
case 1: // Lintje found issues
handleFailure(stdout);

if (stderr) {
core.warning(stderr.toString());
logWarning(stderr.toString());
}
break;
case 2: // Internal Lintje failure
core.setFailed("Lintje encountered an error while performing its checks.");
core.info(stdout);
core.error((stderr || "").toString());
logError((stderr || "").toString());
break;
default:
core.setFailed(`Unknown exit code received from Lintje: ${status}`);
core.info(stdout);
core.error((stderr || "").toString());
logError((stderr || "").toString());
break;
}
} catch (error) {
Expand Down
24 changes: 16 additions & 8 deletions src/__tests__/runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const { download } = require("../utils/downloader");
const rootDir = path.join(__dirname, "../../");
const colorEnv = { TERM: "xterm-256color" };

const annotationOptions = "title=Lintje (Git Linter)";

describe("runner", () => {
function cleanup() {
if (fs.existsSync("lintje")) {
Expand Down Expand Up @@ -75,7 +77,9 @@ describe("runner", () => {
["HEAD", "--color"],
{ env: colorEnv }
);
expect(stdoutSpy).toHaveBeenCalledWith(expect.stringContaining("::notice::Lintje has found no issues."));
expect(stdoutSpy).toHaveBeenCalledWith(
expect.stringContaining(`::notice ${annotationOptions}::Lintje has found no issues.`)
);
expect(process.exitCode).toBeUndefined(); // Success
});

Expand All @@ -102,7 +106,9 @@ describe("runner", () => {
["HEAD~2...HEAD", "--color"],
{ env: colorEnv }
);
expect(stdoutSpy).toHaveBeenCalledWith(expect.stringContaining("::notice::Lintje has found no issues."));
expect(stdoutSpy).toHaveBeenCalledWith(
expect.stringContaining(`::notice ${annotationOptions}::Lintje has found no issues.`)
);
expect(process.exitCode).toBeUndefined(); // Success
});

Expand Down Expand Up @@ -133,7 +139,7 @@ describe("runner", () => {
expect(stdoutSpy)
.toHaveBeenCalledWith(
expect.stringContaining(
"::notice::1 commit and branch inspected, 0 errors detected, 1 hint"
`::notice ${annotationOptions}::1 commit and branch inspected, 0 errors detected, 1 hint`
)
);
expect(process.exitCode).toBeUndefined(); // Success
Expand Down Expand Up @@ -195,9 +201,7 @@ describe("runner", () => {
);
expect(stdoutSpy)
.toHaveBeenCalledWith(
expect.stringContaining(
"::error::Lintje encountered an error while performing its checks."
)
expect.stringContaining("::error::Lintje encountered an error while performing its checks.")
);
expect(stdoutSpy).toHaveBeenCalledWith(expect.stringContaining("Some Lintje error"));
expect(process.exitCode).toEqual(1); // Failure
Expand All @@ -219,7 +223,9 @@ describe("runner", () => {
await run();

expect(childProcess.spawnSync).not.toHaveBeenCalled();
expect(stdoutSpy).toHaveBeenCalledWith(expect.stringContaining("::error::Lintje failed with error: Error: Oh no!"));
expect(stdoutSpy).toHaveBeenCalledWith(
expect.stringContaining("::error::Lintje failed with error: Error: Oh no!")
);
expect(process.exitCode).toEqual(1); // Failure
});

Expand Down Expand Up @@ -300,7 +306,9 @@ describe("runner", () => {
{ env: colorEnv }
);
expect(stdoutSpy).toHaveBeenCalledWith(expect.stringContaining("Some \u{1b}[0mcolored error lines"));
expect(stdoutSpy).toHaveBeenCalledWith(expect.stringContaining("::error::1 commit and branch inspected, 3 errors detected"));
expect(stdoutSpy).toHaveBeenCalledWith(
expect.stringContaining("::error::1 commit and branch inspected, 3 errors detected")
);
});

test("runs lintje without color", async () => {
Expand Down
28 changes: 21 additions & 7 deletions src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const cache = require("@actions/cache");
const { LINTJE_VERSION } = require("./version");
const { download } = require("./utils");

const annotationOptions = { title: "Lintje (Git Linter)" };

function runLintje(commitCount) {
const commitRange = commitArgument(commitCount);
const env = {};
Expand Down Expand Up @@ -58,9 +60,9 @@ function handleSuccess(stdout) {
const { statusLine, issueLines } = splitOutput(stdout);
if (statusLine.endsWith(" hint") || statusLine.endsWith(" hints")) {
core.info(issueLines);
core.notice(removeColorOutput(statusLine));
logNotice(removeColorOutput(statusLine));
} else {
core.notice("Lintje has found no issues.");
logNotice("Lintje has found no issues.");
}
}

Expand All @@ -87,6 +89,18 @@ async function downloadIfNotCached() {
await cache.saveCache(paths, cacheKey);
}

function logNotice(string) {
core.notice(string, annotationOptions);
}

function logWarning(string) {
core.warning(string, annotationOptions);
}

function logError(string) {
core.error(string, annotationOptions);
}

async function main() {
try {
await downloadIfNotCached();
Expand All @@ -97,7 +111,7 @@ async function main() {

if (error) {
core.info(stdout);
core.warning((stderr || "").toString());
logWarning((stderr || "").toString());
core.setFailed(`Lintje failed with status code "${status}": ${error}`);
return;
}
Expand All @@ -107,25 +121,25 @@ async function main() {
handleSuccess(stdout);

if (stderr) {
core.warning(stderr.toString());
logWarning(stderr.toString());
}
break;
case 1: // Lintje found issues
handleFailure(stdout);

if (stderr) {
core.warning(stderr.toString());
logWarning(stderr.toString());
}
break;
case 2: // Internal Lintje failure
core.setFailed("Lintje encountered an error while performing its checks.");
core.info(stdout);
core.error((stderr || "").toString());
logError((stderr || "").toString());
break;
default:
core.setFailed(`Unknown exit code received from Lintje: ${status}`);
core.info(stdout);
core.error((stderr || "").toString());
logError((stderr || "").toString());
break;
}
} catch (error) {
Expand Down

0 comments on commit 59ff073

Please sign in to comment.