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
5,096 changes: 4,959 additions & 137 deletions dist/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

457 changes: 457 additions & 0 deletions dist/licenses.txt

Large diffs are not rendered by default.

197 changes: 194 additions & 3 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"all": "npm run build && npm run format && npm run lint && npm run package"
},
"dependencies": {
"@actions/core": "^1.11.1"
"@actions/core": "^1.11.1",
"@actions/github": "^6.0.1"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
Expand Down
63 changes: 54 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { setFailed, error, warning } from '@actions/core';
import {
setFailed,
info,
error,
warning,
getInput,
startGroup,
endGroup,
} from '@actions/core';
import { context } from '@actions/github';
import { existsSync, readFileSync } from 'node:fs';
import { PRCommentManager } from './pr-comment-manager';
import { PRCommentFormatter, CheckResult } from './pr-comment-formatter';

const args = process.argv.slice(2);

Expand All @@ -13,13 +24,7 @@ const fileContents = existsSync(file)
? readFileSync(file, { encoding: 'utf8' }).split('\n')
: [];

type Result = {
line: number;
column: number;
type: 'WARNING' | 'ERROR';
code: string;
message: string;
};
const fileResultsMap = new Map<string, CheckResult[]>();

for (let i = 0; i < fileContents.length - 1; i++) {
const line = fileContents[i];
Expand All @@ -28,7 +33,9 @@ for (let i = 0; i < fileContents.length - 1; i++) {
}

const fileName = line.split('FILE: ')[1];
const results: Result[] = JSON.parse(fileContents[++i]) || [];
const results: CheckResult[] = JSON.parse(fileContents[++i]) || [];

fileResultsMap.set(fileName, results);

if (results.length > 0 && process.env.STRICT === 'true') {
process.exitCode = 1;
Expand All @@ -50,3 +57,41 @@ for (let i = 0; i < fileContents.length - 1; i++) {
});
}
}

async function postPRComment() {
startGroup('Posting PR comment');

try {
const token = getInput('repo-token') || process.env.INPUT_REPO_TOKEN;
const prNumber = context.payload.pull_request?.number;

if (!token) {
info('No GitHub token provided, skipping PR comment');
return;
}

if (!prNumber) {
info('Not a pull request, skipping PR comment');
return;
}

const manager = new PRCommentManager({
token,
owner: context.repo.owner,
repo: context.repo.repo,
prNumber,
});

const formatter = new PRCommentFormatter(fileResultsMap);

const commentBody = formatter.getComment();

await manager.postComment(commentBody);
} catch (err) {
error(`Failed to post PR comment: ${err}`);
}

endGroup();
}

postPRComment();
Comment thread
Utsav-Ladani marked this conversation as resolved.
Loading
Loading