@@ -19,6 +19,7 @@ const {
19
19
singleGreenReviewer,
20
20
requestedChangesReviewers,
21
21
approvingReviews,
22
+ githubCI,
22
23
requestingChangesReviews,
23
24
commentsWithCI,
24
25
commentsWithLiteCI,
@@ -737,6 +738,255 @@ describe('PRChecker', () => {
737
738
} ) ;
738
739
} ) ;
739
740
741
+ describe ( 'checkGitHubCI' , ( ) => {
742
+ const baseData = {
743
+ pr : firstTimerPR ,
744
+ reviewers : allGreenReviewers ,
745
+ comments : commentsWithLGTM ,
746
+ reviews : approvingReviews ,
747
+ collaborators,
748
+ authorIsNew : ( ) => true ,
749
+ getThread ( ) {
750
+ return PRData . prototype . getThread . call ( this ) ;
751
+ }
752
+ } ;
753
+ const testArgv = Object . assign ( { } , argv , { ciType : 'github-check' } ) ;
754
+
755
+ it ( 'should error if no CI runs detected' , ( ) => {
756
+ const cli = new TestCLI ( ) ;
757
+
758
+ const expectedLogs = {
759
+ error : [
760
+ [ 'No CI runs detected' ]
761
+ ]
762
+ } ;
763
+
764
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'no-status' ] } ) ;
765
+
766
+ const checker = new PRChecker ( cli , data , testArgv ) ;
767
+
768
+ const status = checker . checkCI ( ) ;
769
+ assert ( ! status ) ;
770
+ cli . assertCalledWith ( expectedLogs ) ;
771
+ } ) ;
772
+
773
+ it ( 'should error if both statuses failed' , ( ) => {
774
+ const cli = new TestCLI ( ) ;
775
+
776
+ const expectedLogs = {
777
+ error : [
778
+ [ 'Last CI failed' ]
779
+ ]
780
+ } ;
781
+
782
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'both-apis-failure' ] } ) ;
783
+
784
+ const checker = new PRChecker ( cli , data , testArgv ) ;
785
+
786
+ const status = checker . checkCI ( ) ;
787
+ assert ( ! status ) ;
788
+ cli . assertCalledWith ( expectedLogs ) ;
789
+ } ) ;
790
+
791
+ it ( 'should succeed if both statuses succeeded' , ( ) => {
792
+ const cli = new TestCLI ( ) ;
793
+
794
+ const expectedLogs = {
795
+ info : [
796
+ [ 'Last CI run was successful' ]
797
+ ]
798
+ } ;
799
+
800
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'both-apis-success' ] } ) ;
801
+
802
+ const checker = new PRChecker ( cli , data , testArgv ) ;
803
+
804
+ const status = checker . checkCI ( ) ;
805
+ assert ( status ) ;
806
+ cli . assertCalledWith ( expectedLogs ) ;
807
+ } ) ;
808
+
809
+ it ( 'should error if Check suite failed' , ( ) => {
810
+ const cli = new TestCLI ( ) ;
811
+
812
+ const expectedLogs = {
813
+ error : [
814
+ [ 'Last CI failed' ]
815
+ ]
816
+ } ;
817
+
818
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'check-suite-failure' ] } ) ;
819
+
820
+ const checker = new PRChecker ( cli , data , testArgv ) ;
821
+
822
+ const status = checker . checkCI ( ) ;
823
+ assert ( ! status ) ;
824
+ cli . assertCalledWith ( expectedLogs ) ;
825
+ } ) ;
826
+
827
+ it ( 'should error if Check suite pending' , ( ) => {
828
+ const cli = new TestCLI ( ) ;
829
+
830
+ const expectedLogs = {
831
+ error : [
832
+ [ 'CI is still running' ]
833
+ ]
834
+ } ;
835
+
836
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'check-suite-pending' ] } ) ;
837
+
838
+ const checker = new PRChecker ( cli , data , testArgv ) ;
839
+
840
+ const status = checker . checkCI ( ) ;
841
+ assert ( ! status ) ;
842
+ cli . assertCalledWith ( expectedLogs ) ;
843
+ } ) ;
844
+
845
+ it ( 'should succeed if Check suite succeeded' , ( ) => {
846
+ const cli = new TestCLI ( ) ;
847
+
848
+ const expectedLogs = {
849
+ info : [
850
+ [ 'Last CI run was successful' ]
851
+ ]
852
+ } ;
853
+
854
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'check-suite-success' ] } ) ;
855
+
856
+ const checker = new PRChecker ( cli , data , testArgv ) ;
857
+
858
+ const status = checker . checkCI ( ) ;
859
+ assert ( status ) ;
860
+ cli . assertCalledWith ( expectedLogs ) ;
861
+ } ) ;
862
+
863
+ it ( 'should error if commit status failed' , ( ) => {
864
+ const cli = new TestCLI ( ) ;
865
+
866
+ const expectedLogs = {
867
+ error : [
868
+ [ 'Last CI failed' ]
869
+ ]
870
+ } ;
871
+
872
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'commit-status-only-failure' ] } ) ;
873
+
874
+ const checker = new PRChecker ( cli , data , testArgv ) ;
875
+
876
+ const status = checker . checkCI ( ) ;
877
+ assert ( ! status ) ;
878
+ cli . assertCalledWith ( expectedLogs ) ;
879
+ } ) ;
880
+
881
+ it ( 'should error if commit status pending' , ( ) => {
882
+ const cli = new TestCLI ( ) ;
883
+
884
+ const expectedLogs = {
885
+ error : [
886
+ [ 'CI is still running' ]
887
+ ]
888
+ } ;
889
+
890
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'commit-status-only-pending' ] } ) ;
891
+
892
+ const checker = new PRChecker ( cli , data , testArgv ) ;
893
+
894
+ const status = checker . checkCI ( ) ;
895
+ assert ( ! status ) ;
896
+ cli . assertCalledWith ( expectedLogs ) ;
897
+ } ) ;
898
+
899
+ it ( 'should succeed if commit status succeeded' , ( ) => {
900
+ const cli = new TestCLI ( ) ;
901
+
902
+ const expectedLogs = {
903
+ info : [
904
+ [ 'Last CI run was successful' ]
905
+ ]
906
+ } ;
907
+
908
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'commit-status-only-success' ] } ) ;
909
+
910
+ const checker = new PRChecker ( cli , data , testArgv ) ;
911
+
912
+ const status = checker . checkCI ( ) ;
913
+ assert ( status ) ;
914
+ cli . assertCalledWith ( expectedLogs ) ;
915
+ } ) ;
916
+
917
+ it ( 'should error if check suite succeeded but commit status failed ' , ( ) => {
918
+ const cli = new TestCLI ( ) ;
919
+
920
+ const expectedLogs = {
921
+ error : [
922
+ [ 'Last CI failed' ]
923
+ ]
924
+ } ;
925
+
926
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'status-failure-check-suite-succeed' ] } ) ;
927
+
928
+ const checker = new PRChecker ( cli , data , testArgv ) ;
929
+
930
+ const status = checker . checkCI ( ) ;
931
+ assert ( ! status ) ;
932
+ cli . assertCalledWith ( expectedLogs ) ;
933
+ } ) ;
934
+
935
+ it ( 'should error if commit status succeeded but check suite failed ' , ( ) => {
936
+ const cli = new TestCLI ( ) ;
937
+
938
+ const expectedLogs = {
939
+ error : [
940
+ [ 'Last CI failed' ]
941
+ ]
942
+ } ;
943
+
944
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'status-succeed-check-suite-failure' ] } ) ;
945
+
946
+ const checker = new PRChecker ( cli , data , testArgv ) ;
947
+
948
+ const status = checker . checkCI ( ) ;
949
+ assert ( ! status ) ;
950
+ cli . assertCalledWith ( expectedLogs ) ;
951
+ } ) ;
952
+
953
+ it ( 'should error if last commit doesnt have CI' , ( ) => {
954
+ const cli = new TestCLI ( ) ;
955
+
956
+ const expectedLogs = {
957
+ error : [
958
+ [ 'No CI runs detected' ]
959
+ ]
960
+ } ;
961
+
962
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'two-commits-first-ci' ] } ) ;
963
+
964
+ const checker = new PRChecker ( cli , data , testArgv ) ;
965
+
966
+ const status = checker . checkCI ( ) ;
967
+ assert ( ! status ) ;
968
+ cli . assertCalledWith ( expectedLogs ) ;
969
+ } ) ;
970
+
971
+ it ( 'should succeed with two commits if last one has CI' , ( ) => {
972
+ const cli = new TestCLI ( ) ;
973
+
974
+ const expectedLogs = {
975
+ info : [
976
+ [ 'Last CI run was successful' ]
977
+ ]
978
+ } ;
979
+
980
+ const data = Object . assign ( { } , baseData , { commits : githubCI [ 'two-commits-last-ci' ] } ) ;
981
+
982
+ const checker = new PRChecker ( cli , data , testArgv ) ;
983
+
984
+ const status = checker . checkCI ( ) ;
985
+ assert ( status ) ;
986
+ cli . assertCalledWith ( expectedLogs ) ;
987
+ } ) ;
988
+ } ) ;
989
+
740
990
describe ( 'checkAuthor' , ( ) => {
741
991
it ( 'should check odd commits for first timers' , ( ) => {
742
992
const cli = new TestCLI ( ) ;
0 commit comments