Skip to content

Commit

Permalink
migrate to js action
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoireW committed Oct 15, 2024
1 parent bec594f commit 381195e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
29 changes: 13 additions & 16 deletions dblinter-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ function buildReport(reportPath) {
return report;
}

async function createComment(report) {
async function createComment(report, options) {
const context = github.context;

const octokit = github.getOctokit(options.githubToken);

const issue_number = context.payload.pull_request?.number;

let comment;
for await (const {data: comments} of octokit.paginate.iterator(octokit.rest.issues.listComments, {
...context.repo,
Expand All @@ -45,7 +49,7 @@ async function createComment(report) {
});
} else {
await octokit.rest.issues.createComment({
issue_number: context.payload.pull_request?.number,
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: report
Expand Down Expand Up @@ -111,9 +115,10 @@ function validateInput(){
const postgresVersion = validateInputForExec("postgres-version");
const flywayVersion = validateInputForExec("flyway-version");

const prComment = core.getInput('pr-comment')==='true';
const inPR = github.context.eventName.toLowerCase()==='pull_request'
const prComment = inPR && core.getInput('pr-comment')==='true';
const githubToken = core.getInput('GITHUB_TOKEN');
if ( (github.context.eventName.toLowerCase()==='pull_request') && prComment && !githubToken) {
if ( inPR && prComment && !githubToken) {
core.setFailed("GITHUB_TOKEN is required to create a PR comment");
exit(1);
}
Expand Down Expand Up @@ -221,20 +226,12 @@ async function main() {

core.setOutput("sarif-report", options.reportPath);

docker.dockerCommand(`kill ${postgres.pgContainer}`);

const report = buildReport(options.reportPath);
await docker.dockerCommand(`kill ${postgres.pgContainer}`, {echo: false});

const github_token = core.getInput('GITHUB_TOKEN');
const octokit = github.getOctokit(github_token);
if (options.prComment) {
const report = buildReport(options.reportPath);

const context = github.context;
const issue_number = context.payload.pull_request?.number;

if (!issue_number) {
core.info('No issue number found.');
} else {
createComment(report);
await createComment(report, options);
}
}

Expand Down
5 changes: 2 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/sourcemap-register.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "dblinter-report",
"main": "dblinter-report.js",
"scripts": {
"package": "ncc build dblinter-report.js -o dist -m -s"
"package": "ncc build dblinter-report.js -o dist -m"
},
"keywords": [],
"author": "",
Expand Down

0 comments on commit 381195e

Please sign in to comment.