66 "os"
77 "path/filepath"
88 "sort"
9+ "strings"
910 "testing"
1011
1112 approverCfg "github.com/form3tech-oss/github-team-approver-commons/v2/pkg/configuration"
@@ -525,6 +526,24 @@ func (s *ApiStage) InvalidReviewCommentsExist() *ApiStage {
525526 return s
526527}
527528
529+ func (s * ApiStage ) InvalidAndIgnoredReviewCommentsExist () * ApiStage {
530+ msgIgnored := fmt .Sprintf ("%s\n - @%s\n " , ignoredReviewerMsg , "alice" )
531+ msgInvalid := fmt .Sprintf ("%s\n - @%s\n " , invalidReviewerMsg , "some other user" )
532+ comments := []* github.IssueComment {
533+ {
534+ ID : github .Int64 (1 ),
535+ Body : github .String (msgIgnored ),
536+ },
537+ {
538+ ID : github .Int64 (2 ),
539+ Body : github .String (msgInvalid ),
540+ },
541+ }
542+ s .fakeGitHub .SetIssueComments (comments )
543+
544+ return s
545+ }
546+
528547func (s * ApiStage ) AliceApprovesPullRequest () * ApiStage {
529548 reviews := []* github.PullRequestReview {
530549 {
@@ -762,33 +781,49 @@ func (s *ApiStage) ExpectedReviewRequestsMadeForFoo() *ApiStage {
762781}
763782
764783func (s * ApiStage ) ExpectCommentAliceIgnoredAsReviewer () * ApiStage {
765- comment := s .fakeGitHub .ReportedComment ()
766- require .NotNil (s .t , comment )
767- require .NotEmpty (s .t , comment .Body )
768- require .Contains (s .t , * comment .Body , ignoredReviewerMsg )
769- require .Contains (s .t , * comment .Body , "alice" )
784+
785+ var comments []* github.IssueComment
786+ for _ , c := range s .fakeGitHub .ReportedComments () {
787+ if strings .Contains (* c .Body , ignoredReviewerMsg ) {
788+ comments = append (comments , c )
789+ }
790+ }
791+
792+ require .Len (s .t , comments , 1 )
793+ require .NotNil (s .t , comments [0 ])
794+ require .NotEmpty (s .t , comments [0 ].Body )
795+ require .Contains (s .t , * comments [0 ].Body , ignoredReviewerMsg )
796+ require .Contains (s .t , * comments [0 ].Body , "alice" )
770797
771798 return s
772799}
773800
774- func (s * ApiStage ) ExpectCommentCharlieIgnoredAsReviewer () * ApiStage {
775- comment := s .fakeGitHub .ReportedComment ()
776- require .NotNil (s .t , comment )
777- require .NotEmpty (s .t , comment .Body )
778- require .Contains (s .t , * comment .Body , invalidReviewerMsg )
779- require .Contains (s .t , * comment .Body , "charlie" )
801+ func (s * ApiStage ) ExpectInvalidCommentCharlieIgnoredAsReviewer () * ApiStage {
802+
803+ var comments []* github.IssueComment
804+ for _ , c := range s .fakeGitHub .ReportedComments () {
805+ if strings .Contains (* c .Body , invalidReviewerMsg ) {
806+ comments = append (comments , c )
807+ }
808+ }
809+
810+ require .Len (s .t , comments , 1 )
811+ require .NotNil (s .t , comments [0 ])
812+ require .NotEmpty (s .t , comments [0 ].Body )
813+ require .Contains (s .t , * comments [0 ].Body , invalidReviewerMsg )
814+ require .Contains (s .t , * comments [0 ].Body , "charlie" )
780815
781816 return s
782817}
783818
784819func (s * ApiStage ) ExpectNoCommentsMade () * ApiStage {
785- require .Nil (s .t , s .fakeGitHub .ReportedComment ())
820+ require .Empty (s .t , s .fakeGitHub .ReportedComments ())
786821
787822 return s
788823}
789824
790825func (s * ApiStage ) ExpectNoReviewRequestsMade () * ApiStage {
791- require .Nil (s .t , s .fakeGitHub .ReportedComment ())
826+ require .Empty (s .t , s .fakeGitHub .ReportedComments ())
792827
793828 return s
794829}
@@ -799,6 +834,16 @@ func (s *ApiStage) ExpectPreviousIgnoredReviewCommentsDeleted() *ApiStage {
799834 return s
800835}
801836
837+ func (s * ApiStage ) ExpectPreviousAliceIgnoredReviewCommentsRetained () * ApiStage {
838+ require .Len (s .t , s .fakeGitHub .Comments (), 1 )
839+ comment := s .fakeGitHub .Comments ()[0 ]
840+ require .NotNil (s .t , comment )
841+ require .NotEmpty (s .t , comment .Body )
842+ require .Contains (s .t , * comment .Body , ignoredReviewerMsg )
843+ require .Contains (s .t , * comment .Body , "alice" )
844+ return s
845+ }
846+
802847func (s * ApiStage ) IgnoreRepositoryExists () * ApiStage {
803848 ignoredRepo := fmt .Sprintf (
804849 "%s/%s" ,
0 commit comments