File tree 3 files changed +13
-7
lines changed
3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ GitHub Action.
30
30
## Usage
31
31
32
32
``` 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
+
33
39
jobs :
34
40
analyze :
35
41
runs-on : ubuntu-latest
Original file line number Diff line number Diff line change @@ -5,9 +5,10 @@ async function run() {
5
5
try {
6
6
const context = github . context ;
7
7
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 ( ', ' ) } .` ) ;
11
12
return ;
12
13
}
13
14
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ describe('verify-safe-to-test-label', () => {
106
106
expect ( core . setFailed ) . toHaveBeenCalledTimes ( 0 ) ;
107
107
} ) ;
108
108
109
- test ( 'should fail when eventName is not allowed' , async ( ) => {
109
+ test ( 'should skip when eventName is not allowed' , async ( ) => {
110
110
const payload = {
111
111
pull_request : {
112
112
head : {
@@ -133,9 +133,8 @@ describe('verify-safe-to-test-label', () => {
133
133
134
134
await run ( ) ;
135
135
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 ) ;
139
138
} ) ;
140
139
141
140
test ( 'should fail when there is an error' , async ( ) => {
You can’t perform that action at this time.
0 commit comments