Skip to content

Commit c7597f6

Browse files
committed
feat: new option skip-comments-on-forks
1 parent dd72ead commit c7597f6

File tree

7 files changed

+54
-28
lines changed

7 files changed

+54
-28
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010

1111
- explanation about forks and token permissions with them.
12+
- new option `skip-comments-on-forks` to prevent blocking pull requests from forks because of lack of
13+
permissions.
1214

1315
### Changed
1416

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Configuration
5454
| `table-coverage-change` | Show only files which their coverage changed equal or above this percentage <br/> Default: `0` |
5555
| `signature` | Custom signature to be used at the bottom of the comment. <br/>If you need multiple comments per pull request each step needs to have a unique `signature` |
5656
| `github-token` | Custom [PAT][pat] to be used instead of the [default action token][default-token], should have the `repo` scope |
57+
| `skip-comments-on-forks` | Should skip trying to comment on [pull requests created from forks](#restrictions-on-forks) <br/> Default: `false` |
5758

5859
Example usage
5960
-------------

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ inputs:
7373
signature:
7474
description: Custom signature to be used at the bottom of the comment
7575
required: false
76+
skip-comments-on-forks:
77+
description: Should skip trying to comment on pull requests created from forks
78+
default: false
79+
7680
runs:
7781
using: node20
7882
main: bin/index.js

assets/summary-example.png

50 KB
Loading

bin/index.js

+35-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let baseFile = getInput("base-file") || process.env.BASE_FILE;
2525
const onlyWithCover = getBooleanInput("only-with-cover");
2626
const onlyWithCoverableLines = getBooleanInput("only-with-coverable-lines");
2727
const withChart = getBooleanInput("with-chart");
28+
const skipCommentOnForks = getBooleanInput("skip-comments-on-forks");
2829
const withTable = getBooleanInput("with-table");
2930
const showBranchesColumn = getBooleanInput("with-branches");
3031
const tableWithOnlyBellow = Number(getInput("table-below-coverage") || 100);
@@ -284,6 +285,16 @@ ${signature}`;
284285
)
285286
.write();
286287

288+
if (context.eventName !== "pull_request") return;
289+
290+
if (
291+
skipCommentOnForks &&
292+
`${context.repo.owner}/${context.repo.repo}` !==
293+
context.payload.pull_request?.head?.repo?.full_name
294+
) {
295+
return;
296+
}
297+
287298
let filter = (c: any) => c?.user?.type === "Bot";
288299

289300
try {

0 commit comments

Comments
 (0)