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

Fix service team reviews #10200

Merged
merged 3 commits into from
Mar 14, 2024
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
9 changes: 8 additions & 1 deletion .ci/magician/cmd/mock_github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
*/
package cmd

import "magician/github"
import (
"errors"

"magician/github"
)

type mockGithub struct {
pullRequest github.PullRequest
Expand Down Expand Up @@ -53,6 +57,9 @@ func (m *mockGithub) GetPullRequestPreviousReviewers(prNumber string) ([]github.

func (m *mockGithub) GetTeamMembers(organization, team string) ([]github.User, error) {
m.calledMethods["GetTeamMembers"] = append(m.calledMethods["GetTeamMembers"], []any{organization, team})
if team == "" {
return nil, errors.New("No team members set")
}
return m.teamMembers[team], nil
}

Expand Down
26 changes: 24 additions & 2 deletions .ci/magician/cmd/mock_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
"sort"
"strings"

"golang.org/x/exp/maps"
)

type ParameterList []any
Expand All @@ -37,7 +42,24 @@ type mockRunner struct {
dirStack *list.List
}

func sortedEnvString(env map[string]string) string {
keys := maps.Keys(env)
sort.Strings(keys)
kvs := make([]string, len(keys))
for i, k := range keys {
kvs[i] = fmt.Sprintf("%s:%s", k, env[k])
}
return fmt.Sprintf("map[%s]", strings.Join(kvs, " "))
}

func NewMockRunner() MockRunner {
diffProcessorEnv := map[string]string{
"NEW_REF": "auto-pr-123456",
"OLD_REF": "auto-pr-123456-old",
"PATH": os.Getenv("PATH"),
"GOPATH": os.Getenv("GOPATH"),
"HOME": os.Getenv("HOME"),
}
return &mockRunner{
calledMethods: make(map[string][]ParameterList),
cmdResults: map[string]string{
Expand All @@ -47,7 +69,7 @@ func NewMockRunner() MockRunner {
"/mock/dir/magic-modules/.ci/magician git [clone -b auto-pr-123456 https://modular-magician:*******@github.com/modular-magician/terraform-provider-google-beta /mock/dir/tpgb] map[]": "",
"/mock/dir/magic-modules git [diff HEAD origin/main tools/missing-test-detector] map[]": "",
"/mock/dir/magic-modules/tools/diff-processor bin/diff-processor [breaking-changes] map[]": "",
"/mock/dir/magic-modules/tools/diff-processor make [build] map[NEW_REF:auto-pr-123456 OLD_REF:auto-pr-123456-old]": "",
"/mock/dir/magic-modules/tools/diff-processor make [build] " + sortedEnvString(diffProcessorEnv): "",
"/mock/dir/magic-modules/tools/diff-processor bin/diff-processor [add-labels 123456] map[GITHUB_TOKEN_MAGIC_MODULES:*******]": "",
"/mock/dir/magic-modules/tools/missing-test-detector go [mod edit -replace google/provider/new=/mock/dir/tpgb] map[]": "",
"/mock/dir/magic-modules/tools/missing-test-detector go [mod edit -replace google/provider/old=/mock/dir/tpgbold] map[]": "",
Expand Down Expand Up @@ -128,7 +150,7 @@ func (mr *mockRunner) PopDir() error {

func (mr *mockRunner) Run(name string, args []string, env map[string]string) (string, error) {
mr.calledMethods["Run"] = append(mr.calledMethods["Run"], ParameterList{mr.cwd, name, args, env})
cmd := fmt.Sprintf("%s %s %v %v", mr.cwd, name, args, env)
cmd := fmt.Sprintf("%s %s %v %s", mr.cwd, name, args, sortedEnvString(env))
if result, ok := mr.cmdResults[cmd]; ok {
return result, nil
}
Expand Down
2 changes: 1 addition & 1 deletion .ci/magician/cmd/request_service_reviewers.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func execRequestServiceReviewers(prNumber string, gh GithubClient, enrolledTeams
continue
}
teamCount += 1
if labelData, ok := enrolledTeams[label.Name]; ok {
if labelData, ok := enrolledTeams[label.Name]; ok && labelData.Team != "" {
githubTeamsSet[labelData.Team] = struct{}{}
}
}
Expand Down
Loading