File tree 2 files changed +66
-0
lines changed
2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,14 @@ async function run() {
42
42
} ) ;
43
43
console . log ( `Removed the "safe-to-test" label from pull request.` ) ;
44
44
} catch ( error ) {
45
+ // When multiple actions are executed in a workflow, the action may try
46
+ // to remove a label that was already removed by another action (race
47
+ // condition).
48
+ if ( error . message === 'Label does not exist' ) {
49
+ console . log ( 'Label was removed during the execution of the action, skipping.' ) ;
50
+ return ;
51
+ }
52
+
45
53
core . setFailed ( error . message ) ;
46
54
}
47
55
}
Original file line number Diff line number Diff line change @@ -150,4 +150,62 @@ describe('remove-safe-to-test-label', () => {
150
150
expect ( core . setFailed ) . toHaveBeenCalledWith ( errorMessage ) ;
151
151
}
152
152
} ) ;
153
+
154
+ test ( 'should handle the error when the label does not exist' , async ( ) => {
155
+ // Mock console.log
156
+ const consoleSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
157
+
158
+ const payload = {
159
+ pull_request : {
160
+ head : {
161
+ repo : {
162
+ full_name : 'fork-owner/repo' ,
163
+ } ,
164
+ } ,
165
+ base : {
166
+ repo : {
167
+ full_name : 'base-owner/repo' ,
168
+ } ,
169
+ } ,
170
+ labels : [
171
+ {
172
+ name : 'safe-to-test' ,
173
+ } ,
174
+ ] ,
175
+ number : 1 ,
176
+ } ,
177
+ repository : {
178
+ full_name : 'base-owner/repo' ,
179
+ } ,
180
+ } ;
181
+
182
+ github . context . eventName = 'pull_request' ;
183
+ github . context . payload = payload ;
184
+ github . context . repo = { owner : 'base-owner' , repo : 'repo' } ;
185
+
186
+ core . getInput . mockReturnValueOnce ( 'safe-to-test' ) ;
187
+
188
+ const mockRemoveLabel = jest . fn ( ) . mockRejectedValue ( new Error ( 'Label does not exist' ) ) ;
189
+ github . getOctokit . mockReturnValue ( {
190
+ rest : {
191
+ issues : {
192
+ removeLabel : mockRemoveLabel ,
193
+ } ,
194
+ } ,
195
+ } ) ;
196
+
197
+ await run ( ) ;
198
+
199
+ expect ( mockRemoveLabel ) . toHaveBeenCalledWith ( {
200
+ owner : 'base-owner' ,
201
+ repo : 'repo' ,
202
+ issue_number : 1 ,
203
+ name : 'safe-to-test' ,
204
+ } ) ;
205
+ expect ( consoleSpy ) . toHaveBeenCalledWith ( 'Label was removed during the execution of the action, skipping.' ) ;
206
+ expect ( core . setFailed ) . toHaveBeenCalledTimes ( 0 ) ; // Ensure setFailed was not called, indicating the action handled the error gracefully.
207
+
208
+ // Restore console.log to its original implementation
209
+ consoleSpy . mockRestore ( ) ;
210
+ } ) ;
153
211
} ) ;
You can’t perform that action at this time.
0 commit comments