@@ -7,8 +7,10 @@ let mockAddLabel = jest.fn();
7
7
let mockListReviews = jest . fn ( ) . mockImplementation ( ( _props : { _owner : string , _repo : string , _pull_number : number } ) => {
8
8
return { data : [ { id : 1111122222 , user : { login : 'aws-cdk-automation' } , state : 'CHANGES_REQUESTED' } ] } ;
9
9
} ) ;
10
+
10
11
beforeAll ( ( ) => {
11
12
jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
13
+ jest . spyOn ( linter . PullRequestLinter . prototype as any , 'getTrustedCommunityMembers' ) . mockImplementation ( ( ) => [ 'trusted1' , 'trusted2' , 'trusted3' ] )
12
14
process . env . REPO_ROOT = path . join ( __dirname , '..' , '..' , '..' , '..' ) ;
13
15
} ) ;
14
16
@@ -514,8 +516,8 @@ describe('integration tests required on features', () => {
514
516
test ( 'with label no error' , async ( ) => {
515
517
labels . push ( { name : 'pr-linter/cli-integ-tested' } ) ;
516
518
const prLinter = configureMock ( issue , files ) ;
517
- await prLinter . validatePullRequestTarget ( SHA ) ;
518
519
// THEN: no exception
520
+ expect ( async ( ) => await prLinter . validatePullRequestTarget ( SHA ) ) . resolves ;
519
521
} ) ;
520
522
521
523
test ( 'with aws-cdk-automation author' , async ( ) => {
@@ -653,8 +655,8 @@ describe('integration tests required on features', () => {
653
655
mockListReviews . mockImplementation ( ( ) => {
654
656
return {
655
657
data : [
656
- { id : 1111122222 , user : { login : 'aws-cdk-automation' } , state : 'CHANGES_REQUESTED' } ,
657
- { id : 1111122223 , user : { login : 'someuser' } , author_association : 'MEMBER' , state : 'CHANGES_REQUESTED' } ,
658
+ { id : 1111122222 , user : { login : 'aws-cdk-automation' } , state : 'CHANGES_REQUESTED' , submitted_at : '2019-11-17T17:43:43Z' } ,
659
+ { id : 1111122223 , user : { login : 'someuser' } , author_association : 'MEMBER' , state : 'CHANGES_REQUESTED' , submitted_at : '2019-11-18T17:43:43Z' } ,
658
660
] ,
659
661
} ;
660
662
} ) ;
@@ -723,7 +725,7 @@ describe('integration tests required on features', () => {
723
725
mockListReviews . mockImplementation ( ( ) => {
724
726
return {
725
727
data : [
726
- { id : 1111122223 , user : { login : 'pahud ' } , state : 'APPROVED' } ,
728
+ { id : 1111122223 , user : { login : 'trusted1 ' } , state : 'APPROVED' } ,
727
729
] ,
728
730
} ;
729
731
} ) ;
@@ -761,8 +763,9 @@ describe('integration tests required on features', () => {
761
763
mockListReviews . mockImplementation ( ( ) => {
762
764
return {
763
765
data : [
764
- { id : 1111122223 , user : { login : 'pahud' } , state : 'COMMENTED' } ,
765
- { id : 1111122223 , user : { login : 'pahud' } , state : 'APPROVED' } ,
766
+ { id : 1111122223 , user : { login : 'trusted1' } , state : 'APPROVED' , submitted_at : '2019-11-18T17:43:43Z' } ,
767
+ { id : 1111122224 , user : { login : 'trusted2' } , state : 'CHANGES_REQUESTED' , submitted_at : '2019-11-17T18:43:43Z' } ,
768
+ { id : 1111122225 , user : { login : 'trusted3' } , state : 'COMMENTED' , submitted_at : '2019-11-17T19:43:43Z' } ,
766
769
] ,
767
770
} ;
768
771
} ) ;
@@ -795,12 +798,12 @@ describe('integration tests required on features', () => {
795
798
} ) ;
796
799
} ) ;
797
800
798
- test ( 'trusted community member can "request changes" on p2 PR by commenting ' , async ( ) => {
801
+ test ( 'trusted community member can "request changes" on p2 PR by requesting changes ' , async ( ) => {
799
802
// GIVEN
800
803
mockListReviews . mockImplementation ( ( ) => {
801
804
return {
802
805
data : [
803
- { id : 1111122223 , user : { login : 'pahud ' } , state : 'COMMENTED ' } ,
806
+ { id : 1111122223 , user : { login : 'trusted1 ' } , state : 'CHANGES_REQUESTED' , submitted_at : '2019-11-17T17:43:43Z ' } ,
804
807
] ,
805
808
} ;
806
809
} ) ;
@@ -828,6 +831,123 @@ describe('integration tests required on features', () => {
828
831
expect ( mockAddLabel . mock . calls ) . toEqual ( [ ] ) ;
829
832
} ) ;
830
833
834
+ test ( 'trusted community member can comment after requesting changes without dismissing' , async ( ) => {
835
+ // GIVEN
836
+ mockListReviews . mockImplementation ( ( ) => {
837
+ return {
838
+ data : [
839
+ { id : 1111122223 , user : { login : 'trusted1' } , state : 'CHANGES_REQUESTED' , submitted_at : '2019-11-17T17:43:43Z' } ,
840
+ { id : 1111122224 , user : { login : 'trusted1' } , state : 'COMMENTED' , submitted_at : '2019-11-18T17:43:43Z' } ,
841
+ ] ,
842
+ } ;
843
+ } ) ;
844
+ ( pr as any ) . labels = [ ] ;
845
+
846
+ // WHEN
847
+ const prLinter = configureMock ( pr ) ;
848
+ await prLinter . validateStatusEvent ( pr as any , {
849
+ sha : SHA ,
850
+ context : linter . CODE_BUILD_CONTEXT ,
851
+ state : 'success' ,
852
+ } as any ) ;
853
+
854
+ // THEN
855
+ expect ( mockRemoveLabel . mock . calls ) . toEqual ( [ ] ) ;
856
+ expect ( mockAddLabel . mock . calls ) . toEqual ( [ ] ) ;
857
+ } ) ;
858
+
859
+ test ( 'trusted community member comments dont mark as "changes requested"' , async ( ) => {
860
+ // GIVEN
861
+ mockListReviews . mockImplementation ( ( ) => {
862
+ return {
863
+ data : [
864
+ { id : 1111122223 , user : { login : 'trusted1' } , state : 'COMMENTED' , submitted_at : '2019-11-17T17:43:43Z' } ,
865
+ ] ,
866
+ } ;
867
+ } ) ;
868
+ ( pr as any ) . labels = [
869
+ {
870
+ name : 'pr/needs-community-review' ,
871
+ } ,
872
+ ] ;
873
+
874
+ // WHEN
875
+ const prLinter = configureMock ( pr ) ;
876
+ await prLinter . validateStatusEvent ( pr as any , {
877
+ sha : SHA ,
878
+ context : linter . CODE_BUILD_CONTEXT ,
879
+ state : 'success' ,
880
+ } as any ) ;
881
+
882
+ // THEN
883
+ expect ( mockRemoveLabel . mock . calls ) . toEqual ( [ ] ) ;
884
+ expect ( mockAddLabel . mock . calls ) . toEqual ( [ ] ) ;
885
+ } ) ;
886
+
887
+ test ( 'trusted community members can change own review from approval to requesting changes' , async ( ) => {
888
+ // GIVEN
889
+ mockListReviews . mockImplementation ( ( ) => {
890
+ return {
891
+ data : [
892
+ { id : 1111122223 , user : { login : 'trusted1' } , state : 'APPROVED' , submitted_at : '2019-11-17T17:43:43Z' } ,
893
+ { id : 1111122224 , user : { login : 'trusted1' } , state : 'CHANGES_REQUESTED' , submitted_at : '2019-11-18T17:43:43Z' } ,
894
+ ]
895
+ }
896
+ } ) ;
897
+ ( pr as any ) . labels = [
898
+ {
899
+ name : 'pr/needs-maintainer-review' ,
900
+ }
901
+ ] ;
902
+
903
+ // WHEN
904
+ const prLinter = configureMock ( pr ) ;
905
+ await prLinter . validateStatusEvent ( pr as any , {
906
+ sha : SHA ,
907
+ context : linter . CODE_BUILD_CONTEXT ,
908
+ state : 'success' ,
909
+ } as any ) ;
910
+
911
+ // THEN
912
+ expect ( mockRemoveLabel . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
913
+ issue_number : 1234 ,
914
+ name : 'pr/needs-maintainer-review' ,
915
+ owner : 'aws' ,
916
+ repo : 'aws-cdk' ,
917
+ } ) ;
918
+ expect ( mockAddLabel . mock . calls ) . toEqual ( [ ] ) ;
919
+ } ) ;
920
+
921
+ test ( 'trusted community members can change own review from requesting changes to approval' , async ( ) => {
922
+ // GIVEN
923
+ mockListReviews . mockImplementation ( ( ) => {
924
+ return {
925
+ data : [
926
+ { id : 1111122223 , user : { login : 'trusted1' } , state : 'CHANGES_REQUESTED' , submitted_at : '2019-11-17T17:43:43Z' } ,
927
+ { id : 1111122224 , user : { login : 'trusted1' } , state : 'APPROVED' , submitted_at : '2019-11-18T17:43:43Z' } ,
928
+ ]
929
+ }
930
+ } ) ;
931
+ ( pr as any ) . labels = [ ] ;
932
+
933
+ // WHEN
934
+ const prLinter = configureMock ( pr ) ;
935
+ await prLinter . validateStatusEvent ( pr as any , {
936
+ sha : SHA ,
937
+ context : linter . CODE_BUILD_CONTEXT ,
938
+ state : 'success' ,
939
+ } as any ) ;
940
+
941
+ // THEN
942
+ expect ( mockRemoveLabel . mock . calls ) . toEqual ( [ ] ) ;
943
+ expect ( mockAddLabel . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
944
+ issue_number : 1234 ,
945
+ labels : [ 'pr/needs-maintainer-review' ] ,
946
+ owner : 'aws' ,
947
+ repo : 'aws-cdk' ,
948
+ } ) ;
949
+ } ) ;
950
+
831
951
test ( 'untrusted community member approval has no affect' , async ( ) => {
832
952
// GIVEN
833
953
mockListReviews . mockImplementation ( ( ) => {
0 commit comments