Skip to content

Commit c1059d4

Browse files
Exit with exit code 0 when event is not pull_request or pull_request_target (#3)
1 parent 0af9e3b commit c1059d4

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ GitHub Action.
3030
## Usage
3131

3232
```yaml
33+
on:
34+
# This action only works with pull_request and pull_request_target events.
35+
#
36+
# For other events, it succeeds with exit code 0.
37+
pull_request: # or pull_request_target
38+
3339
jobs:
3440
analyze:
3541
runs-on: ubuntu-latest

index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ async function run() {
55
try {
66
const context = github.context;
77

8-
const allowedEvents = ['pull_request', 'pull_request_target', 'merge_group'];
9-
if (allowedEvents.indexOf(context.eventName) === -1) {
10-
core.setFailed(`This action only works with the following events: ${allowedEvents.join(', ')}.`);
8+
const allowedEvents = ['pull_request', 'pull_request_target'];
9+
const isNotAllowedEvent = allowedEvents.indexOf(context.eventName) === -1;
10+
if (isNotAllowedEvent) {
11+
console.log(`Event "${context.eventName}", skipping. This action only works with the following events: ${allowedEvents.join(', ')}.`);
1112
return;
1213
}
1314

index.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('verify-safe-to-test-label', () => {
106106
expect(core.setFailed).toHaveBeenCalledTimes(0);
107107
});
108108

109-
test('should fail when eventName is not allowed', async () => {
109+
test('should skip when eventName is not allowed', async () => {
110110
const payload = {
111111
pull_request: {
112112
head: {
@@ -133,9 +133,8 @@ describe('verify-safe-to-test-label', () => {
133133

134134
await run();
135135

136-
expect(core.setFailed).toHaveBeenCalledWith(
137-
`This action only works with the following events: pull_request, pull_request_target, merge_group.`
138-
);
136+
expect(core.setFailed).toHaveBeenCalledTimes(0);
137+
expect(github.getOctokit).toHaveBeenCalledTimes(0);
139138
});
140139

141140
test('should fail when there is an error', async () => {

0 commit comments

Comments
 (0)