Skip to content

Commit 4e0330c

Browse files
committed
fix: actually use the skip-internal-contributors action input
Don't error when `GH_PAT_READ_ORG` is unavailable
1 parent 096dcea commit 4e0330c

7 files changed

Lines changed: 37 additions & 31 deletions

File tree

assets/coverage-report.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
| Category | Percentage | Covered/Total |
88
| :--------- | :--------: | :-----------: |
9-
| Statements | 100% | 176/176 |
10-
| Branches | 100% | 76/76 |
9+
| Statements | 100% | 178/178 |
10+
| Branches | 100% | 78/78 |
1111
| Functions | 100% | 21/21 |
12-
| Lines | 100% | 166/166 |
12+
| Lines | 100% | 168/168 |
1313

1414
## Coverage by File
1515

assets/jscpd-report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
77
| Format | Files analyzed | Total lines | Total tokens | Clones found | Duplicated lines | Duplicated tokens |
88
| ---------- | -------------- | ----------- | ------------ | ------------ | ---------------- | ----------------- |
9-
| typescript | 27 | 2008 | 16100 | 0 | 0 (0%) | 0 (0%) |
10-
| **Total:** | **27** | **2008** | **16100** | **0** | **0 (0%)** | **0 (0%)** |
9+
| typescript | 27 | 2014 | 16141 | 0 | 0 (0%) | 0 (0%) |
10+
| **Total:** | **27** | **2014** | **16141** | **0** | **0 (0%)** | **0 (0%)** |

assets/tests-report.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66

77
- **Total Tests**: 68
88
- **Test Suites**: 39
9-
- **Duration**: 941ms
9+
- **Duration**: 951ms
1010

1111
| Status | File | Tests ||| ⏭️ ||
1212
| :----: | :--------------------------------------------------------------------------------------------- | :---: | :-: | :-: | :-: | :--: |
13-
|| [tests/index.test.ts](#-testsindextestts) | 1 | 1 | - | - | 13ms |
13+
|| [tests/index.test.ts](#-testsindextestts) | 1 | 1 | - | - | 12ms |
1414
|| [tests/issues.test.ts](#-testsissuestestts) | 3 | 3 | - | - | 5ms |
15-
|| [tests/main.test.ts](#-testsmaintestts) | 11 | 11 | - | - | 8ms |
15+
|| [tests/main.test.ts](#-testsmaintestts) | 11 | 11 | - | - | 11ms |
1616
|| [tests/pull_request.test.ts](#-testspull_requesttestts) | 5 | 5 | - | - | 8ms |
1717
|| [tests/utils/action-inputs.test.ts](#-testsutilsaction-inputstestts) | 9 | 9 | - | - | 3ms |
1818
|| [tests/utils/add-labels.test.ts](#-testsutilsadd-labelstestts) | 3 | 3 | - | - | 2ms |
19-
|| [tests/utils/add-reactions.test.ts](#-testsutilsadd-reactionstestts) | 6 | 6 | - | - | 9ms |
19+
|| [tests/utils/add-reactions.test.ts](#-testsutilsadd-reactionstestts) | 6 | 6 | - | - | 7ms |
2020
|| [tests/utils/create-comment.test.ts](#-testsutilscreate-commenttestts) | 2 | 2 | - | - | 2ms |
2121
|| [tests/utils/fc-event.test.ts](#-testsutilsfc-eventtestts) | 6 | 6 | - | - | 2ms |
22-
|| [tests/utils/is-first-time-contributor.test.ts](#-testsutilsis-first-time-contributortestts) | 8 | 8 | - | - | 9ms |
23-
|| [tests/utils/is-internal-contributor.test.ts](#-testsutilsis-internal-contributortestts) | 8 | 8 | - | - | 7ms |
24-
|| [tests/utils/is-supported-event.test.ts](#-testsutilsis-supported-eventtestts) | 1 | 1 | - | - | 2ms |
22+
|| [tests/utils/is-first-time-contributor.test.ts](#-testsutilsis-first-time-contributortestts) | 8 | 8 | - | - | 7ms |
23+
|| [tests/utils/is-internal-contributor.test.ts](#-testsutilsis-internal-contributortestts) | 8 | 8 | - | - | 6ms |
24+
|| [tests/utils/is-supported-event.test.ts](#-testsutilsis-supported-eventtestts) | 1 | 1 | - | - | 1ms |
2525
|| [tests/utils/was-the-first-contribution.test.ts](#-testsutilswas-the-first-contributiontestts) | 5 | 5 | - | - | 3ms |
2626

2727
## Details
@@ -53,7 +53,7 @@
5353
✅ exits action when the issue or pull request author is NOT a first-time contributor
5454
✅ sets the correct action's outputs for issues
5555
✅ sets the correct action's outputs for pull requests
56-
throws if GH_PAT_READ_ORG is not set
56+
does not throw if GH_PAT_READ_ORG is not set
5757
5858
✅ fails the action when `fail-on-error` is enabled
5959
✅ doesn't fail the action when `fail-on-error` is disabled

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,24 @@ export async function run(): Promise<ErrorOccurred> {
5353
const is_pull_request = !!payload.pull_request
5454

5555
// skip internal contributors
56-
const pat_token = process.env['GH_PAT_READ_ORG']
57-
if (!pat_token) {
58-
throw new Error('GH_PAT_READ_ORG env variable is not set.')
59-
}
60-
const is_internal = await is_internal_contributor(octokit, pat_token, {
61-
author,
62-
owner,
63-
repo
64-
})
65-
if (is_internal) {
66-
core.info(`@${author} is an internal contributor. Exiting..`)
67-
return false
68-
} else {
69-
core.debug(`@${author} is NOT an internal contributor.`)
56+
const should_skip = core.getBooleanInput('skip-internal-contributors')
57+
if (should_skip) {
58+
const pat_token = process.env['GH_PAT_READ_ORG']
59+
if (pat_token) {
60+
const is_internal = await is_internal_contributor(octokit, pat_token, {
61+
author,
62+
owner,
63+
repo
64+
})
65+
if (is_internal) {
66+
core.info(`@${author} is an internal contributor. Exiting..`)
67+
return false
68+
} else {
69+
core.debug(`@${author} is NOT an internal contributor.`)
70+
}
71+
} else {
72+
core.info('`GH_PAT_READ_ORG` env variable is unavailable. Cannot skip internal contributors.')
73+
}
7074
}
7175

7276
// check if author is first-timer

tests/main.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,20 @@ describe('action', () => {
145145
expect(run_spy).toHaveReturned()
146146
})
147147

148-
it('throws if GH_PAT_READ_ORG is not set', async () => {
148+
it('does not throw if GH_PAT_READ_ORG is not set', async () => {
149149
// Supported event
150150
github_context_mock.eventName = 'pull_request_target'
151151
github_context_mock.payload.action = 'opened'
152152
github_context_mock.payload.pull_request = { number: 456, user: { login: 'ghosty' } }
153153
// remove PAT env
154154
vitest.unstubAllEnvs()
155+
// skip internal contributors
156+
core_getBooleanInput_spy.mockReturnValue(true)
155157

156158
await main.run()
157159

158160
expect(is_internal_contributor_spy).not.toHaveBeenCalled()
159-
expect(run_spy).toHaveResolvedWith(true)
161+
expect(run_spy).toHaveResolvedWith(false)
160162
})
161163

162164
describe('when an error is thrown', () => {

0 commit comments

Comments
 (0)