Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add org and org/repo sharding for Blunderbuss" #29408

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions prow/cmd/deck/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,8 @@ func TestHandlePluginConfig(t *testing.T) {
}},
},
Blunderbuss: plugins.Blunderbuss{
BlunderbussConfig: plugins.BlunderbussConfig{
ExcludeApprovers: true,
}},
ExcludeApprovers: true,
},
}
pluginAgent := &plugins.ConfigAgent{}
pluginAgent.Set(&c)
Expand Down
46 changes: 10 additions & 36 deletions prow/plugins/blunderbuss/blunderbuss.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,43 +64,18 @@ func helpProvider(config *plugins.Configuration, _ []config.OrgRepo) (*pluginhel
two := 2
yamlSnippet, err := plugins.CommentMap.GenYaml(&plugins.Configuration{
Blunderbuss: plugins.Blunderbuss{
BlunderbussConfig: plugins.BlunderbussConfig{
ReviewerCount: &two,
MaxReviewerCount: 3,
ExcludeApprovers: true,
UseStatusAvailability: true,
IgnoreAuthors: []string{},
},
Orgs: map[string]plugins.BlunderbussOrgConfig{
"": {
BlunderbussConfig: &plugins.BlunderbussConfig{
ReviewerCount: &two,
MaxReviewerCount: 3,
ExcludeApprovers: true,
UseStatusAvailability: true,
IgnoreAuthors: []string{},
},
Repos: map[string]plugins.BlunderbussRepoConfig{
"": {
BlunderbussConfig: plugins.BlunderbussConfig{
ReviewerCount: &two,
MaxReviewerCount: 3,
ExcludeApprovers: true,
UseStatusAvailability: true,
IgnoreAuthors: []string{},
},
},
},
},
},
ReviewerCount: &two,
MaxReviewerCount: 3,
ExcludeApprovers: true,
UseStatusAvailability: true,
IgnoreAuthors: []string{},
},
})
if err != nil {
logrus.WithError(err).Warnf("cannot generate comments for %s plugin", PluginName)
}
pluginHelp := &pluginhelp.PluginHelp{
Description: "The blunderbuss plugin automatically requests reviews from reviewers when a new PR is created. " +
"The reviewers are selected based on the reviewers specified in the OWNERS files that apply to the files modified by the PR.",
Description: "The blunderbuss plugin automatically requests reviews from reviewers when a new PR is created. The reviewers are selected based on the reviewers specified in the OWNERS files that apply to the files modified by the PR.",
Config: map[string]string{
"": configString(reviewCount),
},
Expand Down Expand Up @@ -162,18 +137,17 @@ func handlePullRequestEvent(pc plugins.Agent, pre github.PullRequestEvent) error
pc.GitHubClient,
pc.OwnersClient,
pc.Logger,
pc.PluginConfig.BlunderbussFor(pre.Repo.Owner.Login, pre.Repo.Name),
pc.PluginConfig.Blunderbuss,
pre.Action,
&pre.PullRequest,
&pre.Repo,
)
}

func handlePullRequest(ghc githubClient, roc repoownersClient, log *logrus.Entry, config plugins.BlunderbussConfig, action github.PullRequestEventAction, pr *github.PullRequest, repo *github.Repo) error {
func handlePullRequest(ghc githubClient, roc repoownersClient, log *logrus.Entry, config plugins.Blunderbuss, action github.PullRequestEventAction, pr *github.PullRequest, repo *github.Repo) error {
if !(action == github.PullRequestActionOpened || action == github.PullRequestActionReadyForReview) || assign.CCRegexp.MatchString(pr.Body) {
return nil
}

if pr.Draft && config.IgnoreDrafts {
// ignore Draft PR when IgnoreDrafts is true
return nil
Expand Down Expand Up @@ -202,7 +176,7 @@ func handleGenericCommentEvent(pc plugins.Agent, ce github.GenericCommentEvent)
pc.GitHubClient,
pc.OwnersClient,
pc.Logger,
pc.PluginConfig.BlunderbussFor(ce.Repo.Owner.Login, ce.Repo.Name),
pc.PluginConfig.Blunderbuss,
ce.Action,
ce.IsPR,
ce.Number,
Expand All @@ -212,7 +186,7 @@ func handleGenericCommentEvent(pc plugins.Agent, ce github.GenericCommentEvent)
)
}

func handleGenericComment(ghc githubClient, roc repoownersClient, log *logrus.Entry, config plugins.BlunderbussConfig, action github.GenericCommentEventAction, isPR bool, prNumber int, issueState string, repo *github.Repo, body string) error {
func handleGenericComment(ghc githubClient, roc repoownersClient, log *logrus.Entry, config plugins.Blunderbuss, action github.GenericCommentEventAction, isPR bool, prNumber int, issueState string, repo *github.Repo, body string) error {
if action != github.GenericCommentActionCreated || !isPR || issueState == "closed" {
return nil
}
Expand Down
175 changes: 4 additions & 171 deletions prow/plugins/blunderbuss/blunderbuss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func TestHandlePullRequest(t *testing.T) {
pr := github.PullRequest{Number: 5, User: github.User{Login: "author"}, Body: tc.body, Draft: tc.draft}
repo := github.Repo{Owner: github.User{Login: "org"}, Name: "repo"}
fghc := newFakeGitHubClient(&pr, tc.filesChanged)
c := plugins.BlunderbussConfig{
c := plugins.Blunderbuss{
ReviewerCount: &tc.reviewerCount,
MaxReviewerCount: 0,
ExcludeApprovers: false,
Expand All @@ -659,70 +659,6 @@ func TestHandlePullRequest(t *testing.T) {
}
}

func TestHandlePullRequestShardedConfig(t *testing.T) {
froc := &fakeRepoownersClient{
foc: &fakeOwnersClient{
owners: map[string]string{
"a.go": "1",
},
leafReviewers: map[string]sets.String{
"a.go": sets.NewString("al"),
},
},
}

var tc = struct {
action github.PullRequestEventAction
body string
filesChanged []string
reviewerCount int
expectedRequested []string
draft bool
ignoreDrafts bool
ignoreAuthors []string
}{
action: github.PullRequestActionOpened,
filesChanged: []string{"a.go"},
draft: false,
ignoreDrafts: true,
reviewerCount: 1,
}

pr := github.PullRequest{Number: 5, User: github.User{Login: "author"}, Body: tc.body, Draft: tc.draft}
repo := github.Repo{Owner: github.User{Login: "org"}, Name: "repo"}
fghc := newFakeGitHubClient(&pr, tc.filesChanged)
c := &plugins.Configuration{
Blunderbuss: plugins.Blunderbuss{
BlunderbussConfig: plugins.BlunderbussConfig{
ReviewerCount: &tc.reviewerCount,
MaxReviewerCount: 0,
ExcludeApprovers: false,
IgnoreDrafts: tc.ignoreDrafts,
IgnoreAuthors: tc.ignoreAuthors,
},
Orgs: map[string]plugins.BlunderbussOrgConfig{
"org": {
Repos: map[string]plugins.BlunderbussRepoConfig{
"org/repo": {
BlunderbussConfig: plugins.BlunderbussConfig{
IgnoreAuthors: []string{"author"},
}}}}}}}
bc := c.BlunderbussFor(repo.Owner.Login, repo.Name)

if err := handlePullRequest(
fghc, froc, logrus.WithField("plugin", PluginName),
bc, tc.action, &pr, &repo,
); err != nil {
t.Fatalf("unexpected error from handle: %v", err)
}

sort.Strings(fghc.requested)
sort.Strings(tc.expectedRequested)
if !reflect.DeepEqual(fghc.requested, tc.expectedRequested) {
t.Fatalf("expected the requested reviewers to be %q, but got %q.", tc.expectedRequested, fghc.requested)
}
}

func TestHandleGenericComment(t *testing.T) {
froc := &fakeRepoownersClient{
foc: &fakeOwnersClient{
Expand Down Expand Up @@ -796,7 +732,7 @@ func TestHandleGenericComment(t *testing.T) {
pr := github.PullRequest{Number: 5, User: github.User{Login: "author"}}
fghc := newFakeGitHubClient(&pr, tc.filesChanged)
repo := github.Repo{Owner: github.User{Login: "org"}, Name: "repo"}
config := plugins.BlunderbussConfig{
config := plugins.Blunderbuss{
ReviewerCount: &tc.reviewerCount,
MaxReviewerCount: 0,
ExcludeApprovers: false,
Expand All @@ -818,108 +754,6 @@ func TestHandleGenericComment(t *testing.T) {
}
}

func TestHandleGenericCommentShardedConfig(t *testing.T) {
froc := &fakeRepoownersClient{
foc: &fakeOwnersClient{
owners: map[string]string{
"a.go": "1",
"b.go": "2",
},
leafReviewers: map[string]sets.String{
"a.go": sets.NewString("al"),
"b.go": sets.NewString("bob"),
"c.go": sets.NewString("sarah"),
"d.go": sets.NewString("busy-user"),
},
},
}

overrideOrgReviewerCount := 2
overrideRepoReviewerCount := 3
var testcases = []struct {
name string
orgConfig map[string]plugins.BlunderbussOrgConfig
expectedRequested int
}{
{
name: "overrides default config with org config",
orgConfig: map[string]plugins.BlunderbussOrgConfig{
"org": {
BlunderbussConfig: &plugins.BlunderbussConfig{
ReviewerCount: &overrideOrgReviewerCount,
MaxReviewerCount: overrideOrgReviewerCount,
}},
},
expectedRequested: 2,
},
{
name: "overrides default and org config with repo config",
orgConfig: map[string]plugins.BlunderbussOrgConfig{
"org": {
BlunderbussConfig: &plugins.BlunderbussConfig{
ReviewerCount: &overrideOrgReviewerCount,
MaxReviewerCount: overrideOrgReviewerCount,
},
Repos: map[string]plugins.BlunderbussRepoConfig{
"org/repo": {
BlunderbussConfig: plugins.BlunderbussConfig{
ReviewerCount: &overrideRepoReviewerCount,
MaxReviewerCount: overrideRepoReviewerCount,
}}}},
},
expectedRequested: 3,
},
{
name: "Uses org config with invalid repo config key",
orgConfig: map[string]plugins.BlunderbussOrgConfig{
"org": {
BlunderbussConfig: &plugins.BlunderbussConfig{
ReviewerCount: &overrideOrgReviewerCount,
MaxReviewerCount: overrideOrgReviewerCount,
},
Repos: map[string]plugins.BlunderbussRepoConfig{
"repo": {
BlunderbussConfig: plugins.BlunderbussConfig{
ReviewerCount: &overrideRepoReviewerCount,
MaxReviewerCount: overrideRepoReviewerCount,
}}}},
},
expectedRequested: 2,
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
pr := github.PullRequest{Number: 5, User: github.User{Login: "author"}}
fghc := newFakeGitHubClient(&pr, []string{"a.go", "b.go", "c.go", "d.go"})
defaultReviewerCount := 1
repo := github.Repo{Owner: github.User{Login: "org"}, Name: "repo"}

config := &plugins.Configuration{
Blunderbuss: plugins.Blunderbuss{
BlunderbussConfig: plugins.BlunderbussConfig{
IgnoreAuthors: []string{"bob"},
ReviewerCount: &defaultReviewerCount,
UseStatusAvailability: false,
},
Orgs: tc.orgConfig,
}}
bc := config.BlunderbussFor(repo.Owner.Login, repo.Name)

if err := handleGenericComment(
fghc, froc, logrus.WithField("plugin", PluginName), bc,
github.GenericCommentActionCreated, true, pr.Number, "open", &repo, "/auto-cc",
); err != nil {
t.Fatalf("unexpected error from handle: %v", err)
}

if tc.expectedRequested != len(fghc.requested) {
t.Fatalf("expected the requested reviewers to be %d, but got %d.", tc.expectedRequested, len(fghc.requested))
}
})
}
}

func TestHandleGenericCommentEvent(t *testing.T) {
pc := plugins.Agent{
PluginConfig: &plugins.Configuration{},
Expand Down Expand Up @@ -958,9 +792,8 @@ func TestHelpProvider(t *testing.T) {
name: "ReviewerCount specified",
config: &plugins.Configuration{
Blunderbuss: plugins.Blunderbuss{
BlunderbussConfig: plugins.BlunderbussConfig{
ReviewerCount: &[]int{2}[0],
}},
ReviewerCount: &[]int{2}[0],
},
},
enabledRepos: enabledRepos,
configInfoIncludes: []string{configString(2)},
Expand Down
Loading