@@ -643,7 +643,7 @@ func TestHandlePullRequest(t *testing.T) {
643
643
pr := github.PullRequest {Number : 5 , User : github.User {Login : "author" }, Body : tc .body , Draft : tc .draft }
644
644
repo := github.Repo {Owner : github.User {Login : "org" }, Name : "repo" }
645
645
fghc := newFakeGitHubClient (& pr , tc .filesChanged )
646
- c := plugins.Blunderbuss {
646
+ c := plugins.BlunderbussConfig {
647
647
ReviewerCount : & tc .reviewerCount ,
648
648
MaxReviewerCount : 0 ,
649
649
ExcludeApprovers : false ,
@@ -667,6 +667,70 @@ func TestHandlePullRequest(t *testing.T) {
667
667
}
668
668
}
669
669
670
+ func TestHandlePullRequestShardedConfig (t * testing.T ) {
671
+ froc := & fakeRepoownersClient {
672
+ foc : & fakeOwnersClient {
673
+ owners : map [string ]string {
674
+ "a.go" : "1" ,
675
+ },
676
+ leafReviewers : map [string ]sets.Set [string ]{
677
+ "a.go" : sets .New ("al" ),
678
+ },
679
+ },
680
+ }
681
+
682
+ var tc = struct {
683
+ action github.PullRequestEventAction
684
+ body string
685
+ filesChanged []string
686
+ reviewerCount int
687
+ expectedRequested []string
688
+ draft bool
689
+ ignoreDrafts bool
690
+ ignoreAuthors []string
691
+ }{
692
+ action : github .PullRequestActionOpened ,
693
+ filesChanged : []string {"a.go" },
694
+ draft : false ,
695
+ ignoreDrafts : true ,
696
+ reviewerCount : 1 ,
697
+ }
698
+
699
+ pr := github.PullRequest {Number : 5 , User : github.User {Login : "author" }, Body : tc .body , Draft : tc .draft }
700
+ repo := github.Repo {Owner : github.User {Login : "org" }, Name : "repo" }
701
+ fghc := newFakeGitHubClient (& pr , tc .filesChanged )
702
+ c := & plugins.Configuration {
703
+ Blunderbuss : plugins.Blunderbuss {
704
+ BlunderbussConfig : & plugins.BlunderbussConfig {
705
+ ReviewerCount : & tc .reviewerCount ,
706
+ MaxReviewerCount : 0 ,
707
+ ExcludeApprovers : false ,
708
+ IgnoreDrafts : tc .ignoreDrafts ,
709
+ IgnoreAuthors : tc .ignoreAuthors ,
710
+ },
711
+ Orgs : map [string ]plugins.BlunderbussOrgConfig {
712
+ "org" : {
713
+ Repos : map [string ]plugins.BlunderbussRepoConfig {
714
+ "org/repo" : {
715
+ BlunderbussConfig : plugins.BlunderbussConfig {
716
+ IgnoreAuthors : []string {"author" },
717
+ }}}}}}}
718
+ bc := c .BlunderbussFor (repo .Owner .Login , repo .Name )
719
+
720
+ if err := handlePullRequest (
721
+ fghc , froc , logrus .WithField ("plugin" , PluginName ),
722
+ bc , tc .action , & pr , & repo ,
723
+ ); err != nil {
724
+ t .Fatalf ("unexpected error from handle: %v" , err )
725
+ }
726
+
727
+ sort .Strings (fghc .requested )
728
+ sort .Strings (tc .expectedRequested )
729
+ if ! reflect .DeepEqual (fghc .requested , tc .expectedRequested ) {
730
+ t .Fatalf ("expected the requested reviewers to be %q, but got %q." , tc .expectedRequested , fghc .requested )
731
+ }
732
+ }
733
+
670
734
func TestHandleGenericComment (t * testing.T ) {
671
735
froc := & fakeRepoownersClient {
672
736
foc : & fakeOwnersClient {
@@ -740,7 +804,7 @@ func TestHandleGenericComment(t *testing.T) {
740
804
pr := github.PullRequest {Number : 5 , User : github.User {Login : "author" }}
741
805
fghc := newFakeGitHubClient (& pr , tc .filesChanged )
742
806
repo := github.Repo {Owner : github.User {Login : "org" }, Name : "repo" }
743
- config := plugins.Blunderbuss {
807
+ config := plugins.BlunderbussConfig {
744
808
ReviewerCount : & tc .reviewerCount ,
745
809
MaxReviewerCount : 0 ,
746
810
ExcludeApprovers : false ,
@@ -762,17 +826,125 @@ func TestHandleGenericComment(t *testing.T) {
762
826
}
763
827
}
764
828
829
+ func TestHandleGenericCommentShardedConfig (t * testing.T ) {
830
+ froc := & fakeRepoownersClient {
831
+ foc : & fakeOwnersClient {
832
+ owners : map [string ]string {
833
+ "a.go" : "1" ,
834
+ "b.go" : "2" ,
835
+ },
836
+ leafReviewers : map [string ]sets.Set [string ]{
837
+ "a.go" : sets .New ("al" ),
838
+ "b.go" : sets .New ("bob" ),
839
+ "c.go" : sets .New ("sarah" ),
840
+ "d.go" : sets .New ("busy-user" ),
841
+ },
842
+ },
843
+ }
844
+
845
+ overrideOrgReviewerCount := 2
846
+ overrideRepoReviewerCount := 3
847
+ var testcases = []struct {
848
+ name string
849
+ orgConfig map [string ]plugins.BlunderbussOrgConfig
850
+ expectedRequested int
851
+ }{
852
+ {
853
+ name : "overrides default config with org config" ,
854
+ orgConfig : map [string ]plugins.BlunderbussOrgConfig {
855
+ "org" : {
856
+ BlunderbussConfig : & plugins.BlunderbussConfig {
857
+ ReviewerCount : & overrideOrgReviewerCount ,
858
+ MaxReviewerCount : overrideOrgReviewerCount ,
859
+ }},
860
+ },
861
+ expectedRequested : 2 ,
862
+ },
863
+ {
864
+ name : "overrides default and org config with repo config" ,
865
+ orgConfig : map [string ]plugins.BlunderbussOrgConfig {
866
+ "org" : {
867
+ BlunderbussConfig : & plugins.BlunderbussConfig {
868
+ ReviewerCount : & overrideOrgReviewerCount ,
869
+ MaxReviewerCount : overrideOrgReviewerCount ,
870
+ },
871
+ Repos : map [string ]plugins.BlunderbussRepoConfig {
872
+ "org/repo" : {
873
+ BlunderbussConfig : plugins.BlunderbussConfig {
874
+ ReviewerCount : & overrideRepoReviewerCount ,
875
+ MaxReviewerCount : overrideRepoReviewerCount ,
876
+ }}}},
877
+ },
878
+ expectedRequested : 3 ,
879
+ },
880
+ {
881
+ name : "Uses org config with invalid repo config key" ,
882
+ orgConfig : map [string ]plugins.BlunderbussOrgConfig {
883
+ "org" : {
884
+ BlunderbussConfig : & plugins.BlunderbussConfig {
885
+ ReviewerCount : & overrideOrgReviewerCount ,
886
+ MaxReviewerCount : overrideOrgReviewerCount ,
887
+ },
888
+ Repos : map [string ]plugins.BlunderbussRepoConfig {
889
+ "repo" : {
890
+ BlunderbussConfig : plugins.BlunderbussConfig {
891
+ ReviewerCount : & overrideRepoReviewerCount ,
892
+ MaxReviewerCount : overrideRepoReviewerCount ,
893
+ }}}},
894
+ },
895
+ expectedRequested : 2 ,
896
+ },
897
+ }
898
+
899
+ for _ , tc := range testcases {
900
+ t .Run (tc .name , func (t * testing.T ) {
901
+ pr := github.PullRequest {Number : 5 , User : github.User {Login : "author" }}
902
+ fghc := newFakeGitHubClient (& pr , []string {"a.go" , "b.go" , "c.go" , "d.go" })
903
+ defaultReviewerCount := 1
904
+ repo := github.Repo {Owner : github.User {Login : "org" }, Name : "repo" }
905
+
906
+ config := & plugins.Configuration {
907
+ Blunderbuss : plugins.Blunderbuss {
908
+ BlunderbussConfig : & plugins.BlunderbussConfig {
909
+ IgnoreAuthors : []string {"bob" },
910
+ ReviewerCount : & defaultReviewerCount ,
911
+ UseStatusAvailability : false ,
912
+ },
913
+ Orgs : tc .orgConfig ,
914
+ }}
915
+ bc := config .BlunderbussFor (repo .Owner .Login , repo .Name )
916
+
917
+ if err := handleGenericComment (
918
+ fghc , froc , logrus .WithField ("plugin" , PluginName ), bc ,
919
+ github .GenericCommentActionCreated , true , pr .Number , "open" , & repo , "/auto-cc" ,
920
+ ); err != nil {
921
+ t .Fatalf ("unexpected error from handle: %v" , err )
922
+ }
923
+
924
+ if tc .expectedRequested != len (fghc .requested ) {
925
+ t .Fatalf ("expected the requested reviewers to be %d, but got %d." , tc .expectedRequested , len (fghc .requested ))
926
+ }
927
+ })
928
+ }
929
+ }
930
+
765
931
func TestHandleGenericCommentEvent (t * testing.T ) {
766
932
pc := plugins.Agent {
767
- PluginConfig : & plugins.Configuration {},
933
+ PluginConfig : & plugins.Configuration {
934
+ Blunderbuss : plugins.Blunderbuss {
935
+ BlunderbussConfig : & plugins.BlunderbussConfig {},
936
+ }},
768
937
}
769
938
ce := github.GenericCommentEvent {}
770
939
handleGenericCommentEvent (pc , ce )
771
940
}
772
941
773
942
func TestHandlePullRequestEvent (t * testing.T ) {
774
943
pc := plugins.Agent {
775
- PluginConfig : & plugins.Configuration {},
944
+ PluginConfig : & plugins.Configuration {
945
+ Blunderbuss : plugins.Blunderbuss {
946
+ BlunderbussConfig : & plugins.BlunderbussConfig {},
947
+ }},
776
948
}
777
949
pre := github.PullRequestEvent {}
778
950
handlePullRequestEvent (pc , pre )
@@ -791,17 +963,21 @@ func TestHelpProvider(t *testing.T) {
791
963
configInfoIncludes []string
792
964
}{
793
965
{
794
- name : "Empty config" ,
795
- config : & plugins.Configuration {},
966
+ name : "Empty config" ,
967
+ config : & plugins.Configuration {
968
+ Blunderbuss : plugins.Blunderbuss {
969
+ BlunderbussConfig : & plugins.BlunderbussConfig {},
970
+ }},
796
971
enabledRepos : enabledRepos ,
797
972
configInfoIncludes : []string {configString (0 )},
798
973
},
799
974
{
800
975
name : "ReviewerCount specified" ,
801
976
config : & plugins.Configuration {
802
977
Blunderbuss : plugins.Blunderbuss {
803
- ReviewerCount : & []int {2 }[0 ],
804
- },
978
+ BlunderbussConfig : & plugins.BlunderbussConfig {
979
+ ReviewerCount : & []int {2 }[0 ],
980
+ }},
805
981
},
806
982
enabledRepos : enabledRepos ,
807
983
configInfoIncludes : []string {configString (2 )},
0 commit comments