@@ -444,16 +444,12 @@ describe('pull-request', () => {
444
444
445
445
expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
446
446
expect . objectContaining ( {
447
- body : expect . stringContaining (
448
- '**Note**: The following Terraform modules no longer exist in source; however, corresponding tags/releases exist.' ,
449
- ) ,
447
+ body : expect . stringContaining ( '**⚠️ The following module no longer exists in source but has tags/releases.' ) ,
450
448
} ) ,
451
449
) ;
452
450
expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
453
451
expect . objectContaining ( {
454
- body : expect . stringContaining (
455
- 'Automation tag/release deletion is **enabled** and corresponding tags/releases will be automatically deleted.<br>' ,
456
- ) ,
452
+ body : expect . stringContaining ( 'It will be automatically deleted.' ) ,
457
453
} ) ,
458
454
) ;
459
455
@@ -464,16 +460,7 @@ describe('pull-request', () => {
464
460
465
461
expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
466
462
expect . objectContaining ( {
467
- body : expect . stringContaining (
468
- '**Note**: The following Terraform modules no longer exist in source; however, corresponding tags/releases exist.' ,
469
- ) ,
470
- } ) ,
471
- ) ;
472
- expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
473
- expect . objectContaining ( {
474
- body : expect . stringContaining (
475
- 'Automation tag/release deletion is **disabled** — **no** subsequent action will take place.<br>' ,
476
- ) ,
463
+ body : expect . stringContaining ( '⏸️ Existing tags and releases will be **preserved**' ) ,
477
464
} ) ,
478
465
) ;
479
466
} ) ;
@@ -503,37 +490,180 @@ describe('pull-request', () => {
503
490
) ;
504
491
} ) ;
505
492
506
- it ( 'should include modules to remove when specified' , async ( ) => {
493
+ it ( 'should include modules to remove when flag enabled' , async ( ) => {
494
+ const modulesToRemove = [ 'legacy-module1' , 'legacy-module2' ] ;
495
+
496
+ stubOctokitReturnData ( 'issues.createComment' , {
497
+ data : { id : 1 , html_url : 'https://github.com/org/repo/pull/1#issuecomment-1' } ,
498
+ } ) ;
499
+ stubOctokitReturnData ( 'issues.listComments' , { data : [ ] } ) ;
500
+ config . set ( { deleteLegacyTags : true } ) ;
501
+
502
+ await addReleasePlanComment ( [ ] , modulesToRemove , { status : WikiStatus . SUCCESS } ) ;
503
+
504
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
505
+ expect . objectContaining ( {
506
+ body : expect . stringContaining ( '- `legacy-module1`' ) ,
507
+ } ) ,
508
+ ) ;
509
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
510
+ expect . objectContaining ( {
511
+ body : expect . stringContaining ( '- `legacy-module2`' ) ,
512
+ } ) ,
513
+ ) ;
514
+ } ) ;
515
+
516
+ it ( 'should not include modules to remove when flag disabled ' , async ( ) => {
507
517
const modulesToRemove = [ 'legacy-module1' , 'legacy-module2' ] ;
508
518
509
519
stubOctokitReturnData ( 'issues.createComment' , {
510
520
data : { id : 1 , html_url : 'https://github.com/org/repo/pull/1#issuecomment-1' } ,
511
521
} ) ;
512
522
stubOctokitReturnData ( 'issues.listComments' , { data : [ ] } ) ;
523
+ config . set ( { deleteLegacyTags : false } ) ;
513
524
514
525
await addReleasePlanComment ( [ ] , modulesToRemove , { status : WikiStatus . SUCCESS } ) ;
515
526
527
+ const createCommentCalls = vi . mocked ( context . octokit . rest . issues . createComment ) . mock . calls ;
528
+ expect ( createCommentCalls . length ) . toBeGreaterThanOrEqual ( 1 ) ;
529
+
530
+ // Get the comment body text from the first call
531
+ const commentBody = createCommentCalls [ 0 ] ?. [ 0 ] ?. body as string ;
532
+
533
+ // Ensure both modules are not included in the body
534
+ expect ( commentBody ) . not . toContain ( '`legacy-module1`' ) ;
535
+ expect ( commentBody ) . not . toContain ( '`legacy-module2`' ) ;
536
+ expect ( commentBody ) . toContain ( '⏸️ Existing tags and releases will be **preserved**' ) ;
537
+ } ) ;
538
+
539
+ it ( 'should handle cleanup when delete-legacy-tags is enabled but no modules to remove' , async ( ) => {
540
+ const newCommentId = 12345 ;
541
+ config . set ( { deleteLegacyTags : true } ) ;
542
+ stubOctokitReturnData ( 'issues.createComment' , {
543
+ data : { id : newCommentId , html_url : 'https://github.com/org/repo/pull/1#issuecomment-1' } ,
544
+ } ) ;
545
+ stubOctokitReturnData ( 'issues.listComments' , { data : [ ] } ) ;
546
+
547
+ await addReleasePlanComment ( terraformChangedModules , [ ] , { status : WikiStatus . SUCCESS } ) ;
548
+
516
549
expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
517
550
expect . objectContaining ( {
518
- body : expect . stringContaining ( '`legacy-module1`, `legacy-module2`' ) ,
551
+ body : expect . stringContaining (
552
+ '✅ All tags and releases are synchronized with the codebase. No cleanup required.' ,
553
+ ) ,
519
554
} ) ,
520
555
) ;
521
556
} ) ;
522
557
558
+ it ( 'should handle multiple modules to remove with plural warning message' , async ( ) => {
559
+ const newCommentId = 12345 ;
560
+ const terraformModuleNamesToRemove = [ 'aws/module1' , 'aws/module2' , 'gcp/module3' ] ;
561
+ config . set ( { deleteLegacyTags : true } ) ;
562
+ stubOctokitReturnData ( 'issues.createComment' , {
563
+ data : { id : newCommentId , html_url : 'https://github.com/org/repo/pull/1#issuecomment-1' } ,
564
+ } ) ;
565
+ stubOctokitReturnData ( 'issues.listComments' , { data : [ ] } ) ;
566
+
567
+ await addReleasePlanComment ( terraformChangedModules , terraformModuleNamesToRemove , {
568
+ status : WikiStatus . SUCCESS ,
569
+ } ) ;
570
+
571
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
572
+ expect . objectContaining ( {
573
+ body : expect . stringContaining ( '**⚠️ The following modules no longer exist in source but have tags/releases.' ) ,
574
+ } ) ,
575
+ ) ;
576
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
577
+ expect . objectContaining ( {
578
+ body : expect . stringContaining ( 'They will be automatically deleted.' ) ,
579
+ } ) ,
580
+ ) ;
581
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
582
+ expect . objectContaining ( {
583
+ body : expect . stringContaining ( '- `aws/module1`' ) ,
584
+ } ) ,
585
+ ) ;
586
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
587
+ expect . objectContaining ( {
588
+ body : expect . stringContaining ( '- `aws/module2`' ) ,
589
+ } ) ,
590
+ ) ;
591
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
592
+ expect . objectContaining ( {
593
+ body : expect . stringContaining ( '- `gcp/module3`' ) ,
594
+ } ) ,
595
+ ) ;
596
+ } ) ;
597
+
598
+ it ( 'should handle wiki failure status with error message' , async ( ) => {
599
+ const newCommentId = 12345 ;
600
+ const errorMessage = 'Repository does not have wiki enabled' ;
601
+ stubOctokitReturnData ( 'issues.createComment' , {
602
+ data : { id : newCommentId , html_url : 'https://github.com/org/repo/pull/1#issuecomment-1' } ,
603
+ } ) ;
604
+ stubOctokitReturnData ( 'issues.listComments' , { data : [ ] } ) ;
605
+
606
+ await addReleasePlanComment ( [ ] , [ ] , {
607
+ status : WikiStatus . FAILURE ,
608
+ errorMessage,
609
+ } ) ;
610
+
611
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
612
+ expect . objectContaining ( {
613
+ body : expect . stringContaining ( '**⚠️ Failed to checkout wiki:**' ) ,
614
+ } ) ,
615
+ ) ;
616
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
617
+ expect . objectContaining ( {
618
+ body : expect . stringContaining ( '```' ) ,
619
+ } ) ,
620
+ ) ;
621
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
622
+ expect . objectContaining ( {
623
+ body : expect . stringContaining ( errorMessage ) ,
624
+ } ) ,
625
+ ) ;
626
+ expect ( context . octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
627
+ expect . objectContaining ( {
628
+ body : expect . stringContaining ( 'Please consult the [README.md]' ) ,
629
+ } ) ,
630
+ ) ;
631
+ } ) ;
632
+
633
+ it ( 'should exclude branding when disabled' , async ( ) => {
634
+ const newCommentId = 12345 ;
635
+ config . set ( { disableBranding : true } ) ;
636
+ stubOctokitReturnData ( 'issues.createComment' , {
637
+ data : { id : newCommentId , html_url : 'https://github.com/org/repo/pull/1#issuecomment-1' } ,
638
+ } ) ;
639
+ stubOctokitReturnData ( 'issues.listComments' , { data : [ ] } ) ;
640
+
641
+ await addReleasePlanComment ( terraformChangedModules , [ ] , { status : WikiStatus . SUCCESS } ) ;
642
+
643
+ const createCommentCalls = vi . mocked ( context . octokit . rest . issues . createComment ) . mock . calls ;
644
+ expect ( createCommentCalls . length ) . toBeGreaterThanOrEqual ( 1 ) ;
645
+
646
+ // Get the comment body text from the first call
647
+ const commentBody = createCommentCalls [ 0 ] ?. [ 0 ] ?. body as string ;
648
+
649
+ // Ensure branding is not included
650
+ expect ( commentBody ) . not . toContain ( BRANDING_COMMENT ) ;
651
+ } ) ;
652
+
523
653
it ( 'should handle different wiki statuses' , async ( ) => {
524
654
const cases = [
525
655
{
526
656
status : WikiStatus . SUCCESS ,
527
- expectedContent : '✅ Wiki Check ' ,
657
+ expectedContent : '✅ Enabled ' ,
528
658
} ,
529
659
{
530
660
status : WikiStatus . FAILURE ,
531
661
errorMessage : 'Failed to clone' ,
532
- expectedContent : '⚠️ Wiki Check: Failed to checkout wiki. ' ,
662
+ expectedContent : '** ⚠️ Failed to checkout wiki:** ' ,
533
663
} ,
534
664
{
535
665
status : WikiStatus . DISABLED ,
536
- expectedContent : '🚫 Wiki Check: Generation is disabled ' ,
666
+ expectedContent : '🚫 Wiki generation **disabled** via `disable-wiki` flag. ' ,
537
667
} ,
538
668
] ;
539
669
0 commit comments