Skip to content

Commit

Permalink
fix: Makes action just warn on missing permissions to pr (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
davelosert authored Feb 11, 2023
1 parent 598954c commit 50ed2cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'node:path';
import { parseVitestJsonFinal, parseVitestJsonSummary } from './parseJsonReports.js';
import { writeSummaryToPR } from './writeSummaryToPR.js';
import * as core from '@actions/core';
import {RequestError} from '@octokit/request-error'
import { parseCoverageThresholds } from './parseCoverageThresholds.js';
import { generateFileCoverageHtml } from './generateFileCoverageHtml.js';

Expand Down Expand Up @@ -33,7 +34,19 @@ const run = async () => {
.addRaw(tableData)
.addDetails('File Coverage', fileTable)

await writeSummaryToPR(summary);
try {
await writeSummaryToPR(summary);
} catch (error) {
if (error instanceof RequestError && (error.status === 404 || error.status === 403)) {
core.warning(
`Couldn't write a comment to the pull-request. Please make sure your job has the permission 'pull-request: write'.`
)
} else {
// Rethrow to handle it in the catch block of the run()-call.
throw error;
}
}

await summary.write();
};

Expand Down
2 changes: 1 addition & 1 deletion src/writeSummaryToPR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Octokit = ReturnType<typeof github.getOctokit>;

const writeSummaryToPR = async (summary: typeof core.summary) => {
if (!github.context.payload.pull_request) {
console.log('[vitest-coverage-report] Not in the context of a pull request. Skipping comment creation.');
core.info('[vitest-coverage-report] Not in the context of a pull request. Skipping comment creation.');
return;
}

Expand Down

0 comments on commit 50ed2cb

Please sign in to comment.