@@ -243,3 +243,121 @@ test.serial("Does not post comments when failComment is set to false", async (t)
243
243
244
244
t . true ( gitlab . isDone ( ) ) ;
245
245
} ) ;
246
+
247
+ test . serial ( "Does not post comments when failCommentCondition disables it" , async ( t ) => {
248
+ const owner = "test_user" ;
249
+ const repo = "test_repo" ;
250
+ const env = { GITLAB_TOKEN : "gitlab_token" } ;
251
+ const pluginConfig = { failCommentCondition : "<% return false; %>" } ;
252
+ const branch = { name : "main" } ;
253
+ const options = { repositoryUrl : `https://gitlab.com/${ owner } /${ repo } .git` } ;
254
+ const errors = [ { message : "An error occured" } ] ;
255
+ const encodedRepoId = encodeURIComponent ( `${ owner } /${ repo } ` ) ;
256
+ const encodedFailTitle = encodeURIComponent ( "The automated release is failing 🚨" ) ;
257
+ const gitlab = authenticate ( env )
258
+ . get ( `/projects/${ encodedRepoId } /issues?state=opened&&search=${ encodedFailTitle } ` )
259
+ . reply ( 200 , [
260
+ {
261
+ id : 2 ,
262
+ iid : 2 ,
263
+ project_id : 1 ,
264
+ web_url : "https://gitlab.com/test_user/test_repo/issues/2" ,
265
+ title : "API should implemented authentication" ,
266
+ } ,
267
+ ] ) ;
268
+
269
+ await fail ( pluginConfig , { env, options, branch, errors, logger : t . context . logger } ) ;
270
+
271
+ t . true ( gitlab . isDone ( ) ) ;
272
+ } ) ;
273
+
274
+ test . serial ( "Does not post comments on existing issues when failCommentCondition disables this" , async ( t ) => {
275
+ const owner = "test_user" ;
276
+ const repo = "test_repo" ;
277
+ const env = { GITLAB_TOKEN : "gitlab_token" } ;
278
+ const pluginConfig = { failCommentCondition : "<% return !issue; %>" } ;
279
+ const branch = { name : "main" } ;
280
+ const options = { repositoryUrl : `https://gitlab.com/${ owner } /${ repo } .git` } ;
281
+ const errors = [ { message : "An error occured" } ] ;
282
+ const encodedRepoId = encodeURIComponent ( `${ owner } /${ repo } ` ) ;
283
+ const encodedFailTitle = encodeURIComponent ( "The automated release is failing 🚨" ) ;
284
+ const gitlab = authenticate ( env )
285
+ . get ( `/projects/${ encodedRepoId } /issues?state=opened&&search=${ encodedFailTitle } ` )
286
+ . reply ( 200 , [
287
+ {
288
+ id : 1 ,
289
+ iid : 1 ,
290
+ project_id : 1 ,
291
+ web_url : "https://gitlab.com/test_user%2Ftest_repo/issues/1" ,
292
+ title : "The automated release is failing 🚨" ,
293
+ } ,
294
+ {
295
+ id : 2 ,
296
+ iid : 2 ,
297
+ project_id : 1 ,
298
+ web_url : "https://gitlab.com/test_user%2Ftest_repo/issues/2" ,
299
+ title : "API should implemented authentication" ,
300
+ } ,
301
+ ] ) ;
302
+
303
+ await fail ( pluginConfig , { env, options, branch, errors, logger : t . context . logger } ) ;
304
+
305
+ t . true ( gitlab . isDone ( ) ) ;
306
+ } ) ;
307
+
308
+ test . serial ( "Post new issue if none exists yet with disabled comment on existing issues" , async ( t ) => {
309
+ const owner = "test_user" ;
310
+ const repo = "test_repo" ;
311
+ const env = { GITLAB_TOKEN : "gitlab_token" } ;
312
+ const pluginConfig = {
313
+ failComment : `Error: Release for branch \${branch.name} failed with error: \${errors.map(error => error.message).join(';')}` ,
314
+ failCommentCondition : "<% return !issue; %>" ,
315
+ } ;
316
+ const branch = { name : "main" } ;
317
+ const options = { repositoryUrl : `https://gitlab.com/${ owner } /${ repo } .git` } ;
318
+ const errors = [ { message : "An error occured" } ] ;
319
+ const encodedRepoId = encodeURIComponent ( `${ owner } /${ repo } ` ) ;
320
+ const encodedFailTitle = encodeURIComponent ( "The automated release is failing 🚨" ) ;
321
+ const gitlab = authenticate ( env )
322
+ . get ( `/projects/${ encodedRepoId } /issues?state=opened&&search=${ encodedFailTitle } ` )
323
+ . reply ( 200 , [
324
+ {
325
+ id : 2 ,
326
+ iid : 2 ,
327
+ project_id : 1 ,
328
+ web_url : "https://gitlab.com/test_user/test_repo/issues/2" ,
329
+ title : "API should implemented authentication" ,
330
+ } ,
331
+ ] )
332
+ . post ( `/projects/${ encodedRepoId } /issues` , {
333
+ id : "test_user%2Ftest_repo" ,
334
+ description : `Error: Release for branch main failed with error: An error occured` ,
335
+ labels : "semantic-release" ,
336
+ title : "The automated release is failing 🚨" ,
337
+ } )
338
+ . reply ( 200 , { id : 3 , web_url : "https://gitlab.com/test_user/test_repo/-/issues/3" } ) ;
339
+
340
+ await fail ( pluginConfig , { env, options, branch, errors, logger : t . context . logger } ) ;
341
+
342
+ t . true ( gitlab . isDone ( ) ) ;
343
+ t . deepEqual ( t . context . log . args [ 0 ] , [
344
+ "Created issue #%d: %s." ,
345
+ 3 ,
346
+ "https://gitlab.com/test_user/test_repo/-/issues/3" ,
347
+ ] ) ;
348
+ } ) ;
349
+
350
+ test . serial ( "Does not post comments when failCommentCondition is set to false" , async ( t ) => {
351
+ const owner = "test_user" ;
352
+ const repo = "test_repo" ;
353
+ const env = { GITLAB_TOKEN : "gitlab_token" } ;
354
+ const pluginConfig = { failCommentCondition : false } ;
355
+ const branch = { name : "main" } ;
356
+ const options = { repositoryUrl : `https://gitlab.com/${ owner } /${ repo } .git` } ;
357
+ const errors = [ { message : "An error occured" } ] ;
358
+ const gitlab = authenticate ( env ) ;
359
+
360
+ await fail ( pluginConfig , { env, options, branch, errors, logger : t . context . logger } ) ;
361
+
362
+ t . true ( gitlab . isDone ( ) ) ;
363
+ } ) ;
0 commit comments