diff --git a/cmd/server.go b/cmd/server.go index 0bb589411e..9a29005ad3 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -99,6 +99,7 @@ const ( GiteaUserFlag = "gitea-user" GiteaWebhookSecretFlag = "gitea-webhook-secret" // nolint: gosec GiteaPageSizeFlag = "gitea-page-size" + GitlabGroupAllowlistFlag = "gitlab-group-allowlist" GitlabHostnameFlag = "gitlab-hostname" GitlabTokenFlag = "gitlab-token" GitlabUserFlag = "gitlab-user" @@ -344,6 +345,17 @@ var stringFlags = map[string]stringFlag{ "This means that an attacker could spoof calls to Atlantis and cause it to perform malicious actions. " + "Should be specified via the ATLANTIS_GITEA_WEBHOOK_SECRET environment variable.", }, + GitlabGroupAllowlistFlag: { + description: "Comma separated list of key-value pairs representing the GitLab groups and the operations that " + + "the members of a particular group are allowed to perform. " + + "The format is {group}:{command},{group}:{command}. " + + "Valid values for 'command' are 'plan', 'apply' and '*', e.g. 'myorg/dev:plan,myorg/ops:apply,myorg/devops:*'" + + "This example gives the users from the 'myorg/dev' GitLab group the permissions to execute the 'plan' command, " + + "the 'myorg/ops' group the permissions to execute the 'apply' command, " + + "and allows the 'myorg/devops' group to perform any operation. If this argument is not provided, the default value (*:*) " + + "will be used and the default behavior will be to not check permissions " + + "and to allow users from any group to perform any operation.", + }, GitlabHostnameFlag: { description: "Hostname of your GitLab Enterprise installation. If using gitlab.com, no need to set.", defaultValue: DefaultGitlabHostname, diff --git a/cmd/server_test.go b/cmd/server_test.go index 5402b28ce5..08b5ba220c 100644 --- a/cmd/server_test.go +++ b/cmd/server_test.go @@ -99,6 +99,7 @@ var testFlags = map[string]interface{}{ GiteaUserFlag: "gitea-user", GiteaWebhookSecretFlag: "gitea-secret", GiteaPageSizeFlag: 30, + GitlabGroupAllowlistFlag: "", GitlabHostnameFlag: "gitlab-hostname", GitlabTokenFlag: "gitlab-token", GitlabUserFlag: "gitlab-user", diff --git a/runatlantis.io/docs/server-configuration.md b/runatlantis.io/docs/server-configuration.md index 1fd17cbfdc..8ff77224a0 100644 --- a/runatlantis.io/docs/server-configuration.md +++ b/runatlantis.io/docs/server-configuration.md @@ -768,6 +768,20 @@ based on the organization or user that triggered the webhook. This means that an attacker could spoof calls to Atlantis and cause it to perform malicious actions. ::: +### `--gitlab-group-allowlist` + ```bash + atlantis server --gitlab-group-allowlist="myorg/mygroup:plan, myorg/secteam:apply, myorg/devops:apply, myorg/devops:import" + # or + ATLANTIS_GITLAB_GROUP_ALLOWLIST="myorg/mygroup:plan, myorg/secteam:apply, myorg/devops:apply, myorg/devops:import" + ``` + Comma-separated list of GitLab groups and permission pairs. + + By default, any group can plan and apply. + + ::: warning NOTE + Atlantis needs to be able to view the listed group members, inaccessible or non-existent groups are silently ignored. + ::: + ### `--gitlab-hostname` ```bash diff --git a/runatlantis.io/docs/server-side-repo-config.md b/runatlantis.io/docs/server-side-repo-config.md index c8a32744ac..f51880c42c 100644 --- a/runatlantis.io/docs/server-side-repo-config.md +++ b/runatlantis.io/docs/server-side-repo-config.md @@ -591,12 +591,12 @@ mode: on_apply ### Policies -| Key | Type | Default | Required | Description | -|------------------------|-----------------|---------|-----------|----------------------------------------------------------| -| conftest_version | string | none | no | conftest version to run all policy sets | -| owners | Owners(#Owners) | none | yes | owners that can approve failing policies | -| approve_count | int | 1 | no | number of approvals required to bypass failing policies. | -| policy_sets | []PolicySet | none | yes | set of policies to run on a plan output | +| Key | Type | Default | Required | Description | +|------------------------|-----------------|---------|-----------|---------------------------------------------------------| +| conftest_version | string | none | no | conftest version to run all policy sets | +| owners | Owners(#Owners) | none | yes | owners that can approve failing policies | +| approve_count | int | 1 | no | number of approvals required to bypass failing policies | +| policy_sets | []PolicySet | none | yes | set of policies to run on a plan output | ### Owners diff --git a/server/core/config/valid/policies.go b/server/core/config/valid/policies.go index 6aee54179c..718338d05b 100644 --- a/server/core/config/valid/policies.go +++ b/server/core/config/valid/policies.go @@ -1,6 +1,7 @@ package valid import ( + "slices" "strings" version "github.com/hashicorp/go-version" @@ -67,3 +68,16 @@ func (o *PolicyOwners) IsOwner(username string, userTeams []string) bool { return false } + +// Return all owner teams from all policy sets +func (p *PolicySets) AllTeams() []string { + teams := p.Owners.Teams + for _, policySet := range p.PolicySets { + for _, team := range policySet.Owners.Teams { + if !slices.Contains(teams, team) { + teams = append(teams, team) + } + } + } + return teams +} diff --git a/server/core/config/valid/policies_test.go b/server/core/config/valid/policies_test.go index c575a4585a..5147dd8686 100644 --- a/server/core/config/valid/policies_test.go +++ b/server/core/config/valid/policies_test.go @@ -120,3 +120,66 @@ func TestPoliciesConfig_IsOwners(t *testing.T) { }) } } + +func TestPoliciesConfig_AllTeams(t *testing.T) { + cases := []struct { + description string + input valid.PolicySets + expResult []string + }{ + { + description: "has only top-level team owner", + input: valid.PolicySets{ + Owners: valid.PolicyOwners{ + Teams: []string{ + "team1", + }, + }, + }, + expResult: []string{"team1"}, + }, + { + description: "has only policy-level team owner", + input: valid.PolicySets{ + PolicySets: []valid.PolicySet{ + { + Name: "policy1", + Owners: valid.PolicyOwners{ + Teams: []string{ + "team2", + }, + }, + }, + }, + }, + expResult: []string{"team2"}, + }, + { + description: "has both top-level and policy-level team owners", + input: valid.PolicySets{ + Owners: valid.PolicyOwners{ + Teams: []string{ + "team1", + }, + }, + PolicySets: []valid.PolicySet{ + { + Name: "policy1", + Owners: valid.PolicyOwners{ + Teams: []string{ + "team2", + }, + }, + }, + }, + }, + expResult: []string{"team1", "team2"}, + }, + } + for _, c := range cases { + t.Run(c.description, func(t *testing.T) { + result := c.input.AllTeams() + Equals(t, c.expResult, result) + }) + } +} diff --git a/server/events/command_runner.go b/server/events/command_runner.go index 14cdbce146..aef51cb9ac 100644 --- a/server/events/command_runner.go +++ b/server/events/command_runner.go @@ -128,7 +128,8 @@ type DefaultCommandRunner struct { PreWorkflowHooksCommandRunner PreWorkflowHooksCommandRunner PostWorkflowHooksCommandRunner PostWorkflowHooksCommandRunner PullStatusFetcher PullStatusFetcher - TeamAllowlistChecker *TeamAllowlistChecker + GitHubTeamAllowlistChecker *TeamAllowlistChecker + GitLabGroupAllowlistChecker *TeamAllowlistChecker VarFileAllowlistChecker *VarFileAllowlistChecker CommitStatusUpdater CommitStatusUpdater } @@ -240,15 +241,27 @@ func (c *DefaultCommandRunner) commentUserDoesNotHavePermissions(baseRepo models // checkUserPermissions checks if the user has permissions to execute the command func (c *DefaultCommandRunner) checkUserPermissions(repo models.Repo, user models.User, cmdName string) (bool, error) { - if c.TeamAllowlistChecker == nil || !c.TeamAllowlistChecker.HasRules() { + var teamAllowListChecker *TeamAllowlistChecker + + switch repo.VCSHost.Type { + case models.Github: + teamAllowListChecker = c.GitHubTeamAllowlistChecker + case models.Gitlab: + teamAllowListChecker = c.GitLabGroupAllowlistChecker + default: + // allowlist restriction is not supported + return true, nil + } + + if teamAllowListChecker == nil || !teamAllowListChecker.HasRules() { // allowlist restriction is not enabled return true, nil } - teams, err := c.VCSClient.GetTeamNamesForUser(repo, user) + teams, err := c.VCSClient.GetTeamNamesForUser(c.Logger, repo, user) if err != nil { return false, err } - ok := c.TeamAllowlistChecker.IsCommandAllowedForAnyTeam(teams, cmdName) + ok := teamAllowListChecker.IsCommandAllowedForAnyTeam(teams, cmdName) if !ok { return false, nil } diff --git a/server/events/command_runner_test.go b/server/events/command_runner_test.go index 8acea27b98..c495d15582 100644 --- a/server/events/command_runner_test.go +++ b/server/events/command_runner_test.go @@ -303,7 +303,7 @@ func TestRunCommentCommand_TeamAllowListChecker(t *testing.T) { t.Run("nil checker", func(t *testing.T) { vcsClient := setup(t) // by default these are false so don't need to reset - ch.TeamAllowlistChecker = nil + ch.GitHubTeamAllowlistChecker = nil var pull github.PullRequest modelPull := models.PullRequest{ BaseRepo: testdata.GithubRepo, @@ -313,7 +313,7 @@ func TestRunCommentCommand_TeamAllowListChecker(t *testing.T) { When(eventParsing.ParseGithubPull(Any[logging.SimpleLogging](), Eq(&pull))).ThenReturn(modelPull, modelPull.BaseRepo, testdata.GithubRepo, nil) ch.RunCommentCommand(testdata.GithubRepo, nil, nil, testdata.User, testdata.Pull.Num, &events.CommentCommand{Name: command.Plan}) - vcsClient.VerifyWasCalled(Never()).GetTeamNamesForUser(testdata.GithubRepo, testdata.User) + vcsClient.VerifyWasCalled(Never()).GetTeamNamesForUser(Any[logging.SimpleLogging](), Any[models.Repo](), Any[models.User]()) vcsClient.VerifyWasCalledOnce().CreateComment( Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(modelPull.Num), Eq("Ran Plan for 0 projects:"), Eq("plan")) }) @@ -321,7 +321,7 @@ func TestRunCommentCommand_TeamAllowListChecker(t *testing.T) { t.Run("no rules", func(t *testing.T) { vcsClient := setup(t) // by default these are false so don't need to reset - ch.TeamAllowlistChecker = &events.TeamAllowlistChecker{} + ch.GitHubTeamAllowlistChecker = &events.TeamAllowlistChecker{} var pull github.PullRequest modelPull := models.PullRequest{ BaseRepo: testdata.GithubRepo, @@ -331,7 +331,7 @@ func TestRunCommentCommand_TeamAllowListChecker(t *testing.T) { When(eventParsing.ParseGithubPull(Any[logging.SimpleLogging](), Eq(&pull))).ThenReturn(modelPull, modelPull.BaseRepo, testdata.GithubRepo, nil) ch.RunCommentCommand(testdata.GithubRepo, nil, nil, testdata.User, testdata.Pull.Num, &events.CommentCommand{Name: command.Plan}) - vcsClient.VerifyWasCalled(Never()).GetTeamNamesForUser(testdata.GithubRepo, testdata.User) + vcsClient.VerifyWasCalled(Never()).GetTeamNamesForUser(Any[logging.SimpleLogging](), Any[models.Repo](), Any[models.User]()) vcsClient.VerifyWasCalledOnce().CreateComment( Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(modelPull.Num), Eq("Ran Plan for 0 projects:"), Eq("plan")) }) diff --git a/server/events/mocks/mock_custom_step_runner.go b/server/events/mocks/mock_custom_step_runner.go index 8805706322..0fe61e0d5e 100644 --- a/server/events/mocks/mock_custom_step_runner.go +++ b/server/events/mocks/mock_custom_step_runner.go @@ -30,19 +30,19 @@ func (mock *MockCustomStepRunner) Run(ctx command.ProjectContext, cmd string, pa if mock == nil { panic("mock must not be nil. Use myMock := NewMockCustomStepRunner().") } - params := []pegomock.Param{ctx, cmd, path, envs, streamOutput, postProcessOutput} - result := pegomock.GetGenericMockFrom(mock).Invoke("Run", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) + _params := []pegomock.Param{ctx, cmd, path, envs, streamOutput, postProcessOutput} + _result := pegomock.GetGenericMockFrom(mock).Invoke("Run", _params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 string + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(string) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockCustomStepRunner) VerifyWasCalledOnce() *VerifierMockCustomStepRunner { @@ -83,8 +83,8 @@ type VerifierMockCustomStepRunner struct { } func (verifier *VerifierMockCustomStepRunner) Run(ctx command.ProjectContext, cmd string, path string, envs map[string]string, streamOutput bool, postProcessOutput valid.PostProcessRunOutputOption) *MockCustomStepRunner_Run_OngoingVerification { - params := []pegomock.Param{ctx, cmd, path, envs, streamOutput, postProcessOutput} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) + _params := []pegomock.Param{ctx, cmd, path, envs, streamOutput, postProcessOutput} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", _params, verifier.timeout) return &MockCustomStepRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -99,31 +99,43 @@ func (c *MockCustomStepRunner_Run_OngoingVerification) GetCapturedArguments() (c } func (c *MockCustomStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []string, _param2 []string, _param3 []map[string]string, _param4 []bool, _param5 []valid.PostProcessRunOutputOption) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } - _param1 = make([]string, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(string) + if len(_params) > 1 { + _param1 = make([]string, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(string) + } } - _param2 = make([]string, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(string) + if len(_params) > 2 { + _param2 = make([]string, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(string) + } } - _param3 = make([]map[string]string, len(c.methodInvocations)) - for u, param := range params[3] { - _param3[u] = param.(map[string]string) + if len(_params) > 3 { + _param3 = make([]map[string]string, len(c.methodInvocations)) + for u, param := range _params[3] { + _param3[u] = param.(map[string]string) + } } - _param4 = make([]bool, len(c.methodInvocations)) - for u, param := range params[4] { - _param4[u] = param.(bool) + if len(_params) > 4 { + _param4 = make([]bool, len(c.methodInvocations)) + for u, param := range _params[4] { + _param4[u] = param.(bool) + } } - _param5 = make([]valid.PostProcessRunOutputOption, len(c.methodInvocations)) - for u, param := range params[5] { - _param5[u] = param.(valid.PostProcessRunOutputOption) + if len(_params) > 5 { + _param5 = make([]valid.PostProcessRunOutputOption, len(c.methodInvocations)) + for u, param := range _params[5] { + _param5[u] = param.(valid.PostProcessRunOutputOption) + } } } return diff --git a/server/events/mocks/mock_env_step_runner.go b/server/events/mocks/mock_env_step_runner.go index bfc7f97a57..a2fae7124e 100644 --- a/server/events/mocks/mock_env_step_runner.go +++ b/server/events/mocks/mock_env_step_runner.go @@ -29,19 +29,19 @@ func (mock *MockEnvStepRunner) Run(ctx command.ProjectContext, cmd string, value if mock == nil { panic("mock must not be nil. Use myMock := NewMockEnvStepRunner().") } - params := []pegomock.Param{ctx, cmd, value, path, envs} - result := pegomock.GetGenericMockFrom(mock).Invoke("Run", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) + _params := []pegomock.Param{ctx, cmd, value, path, envs} + _result := pegomock.GetGenericMockFrom(mock).Invoke("Run", _params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 string + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(string) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockEnvStepRunner) VerifyWasCalledOnce() *VerifierMockEnvStepRunner { @@ -82,8 +82,8 @@ type VerifierMockEnvStepRunner struct { } func (verifier *VerifierMockEnvStepRunner) Run(ctx command.ProjectContext, cmd string, value string, path string, envs map[string]string) *MockEnvStepRunner_Run_OngoingVerification { - params := []pegomock.Param{ctx, cmd, value, path, envs} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) + _params := []pegomock.Param{ctx, cmd, value, path, envs} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", _params, verifier.timeout) return &MockEnvStepRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -98,27 +98,37 @@ func (c *MockEnvStepRunner_Run_OngoingVerification) GetCapturedArguments() (comm } func (c *MockEnvStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []string, _param2 []string, _param3 []string, _param4 []map[string]string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } - _param1 = make([]string, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(string) + if len(_params) > 1 { + _param1 = make([]string, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(string) + } } - _param2 = make([]string, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(string) + if len(_params) > 2 { + _param2 = make([]string, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(string) + } } - _param3 = make([]string, len(c.methodInvocations)) - for u, param := range params[3] { - _param3[u] = param.(string) + if len(_params) > 3 { + _param3 = make([]string, len(c.methodInvocations)) + for u, param := range _params[3] { + _param3[u] = param.(string) + } } - _param4 = make([]map[string]string, len(c.methodInvocations)) - for u, param := range params[4] { - _param4[u] = param.(map[string]string) + if len(_params) > 4 { + _param4 = make([]map[string]string, len(c.methodInvocations)) + for u, param := range _params[4] { + _param4[u] = param.(map[string]string) + } } } return diff --git a/server/events/mocks/mock_job_message_sender.go b/server/events/mocks/mock_job_message_sender.go index 380cd22674..76f7d59a75 100644 --- a/server/events/mocks/mock_job_message_sender.go +++ b/server/events/mocks/mock_job_message_sender.go @@ -29,8 +29,8 @@ func (mock *MockJobMessageSender) Send(ctx command.ProjectContext, msg string, o if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobMessageSender().") } - params := []pegomock.Param{ctx, msg, operationComplete} - pegomock.GetGenericMockFrom(mock).Invoke("Send", params, []reflect.Type{}) + _params := []pegomock.Param{ctx, msg, operationComplete} + pegomock.GetGenericMockFrom(mock).Invoke("Send", _params, []reflect.Type{}) } func (mock *MockJobMessageSender) VerifyWasCalledOnce() *VerifierMockJobMessageSender { @@ -71,8 +71,8 @@ type VerifierMockJobMessageSender struct { } func (verifier *VerifierMockJobMessageSender) Send(ctx command.ProjectContext, msg string, operationComplete bool) *MockJobMessageSender_Send_OngoingVerification { - params := []pegomock.Param{ctx, msg, operationComplete} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Send", params, verifier.timeout) + _params := []pegomock.Param{ctx, msg, operationComplete} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Send", _params, verifier.timeout) return &MockJobMessageSender_Send_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -87,19 +87,25 @@ func (c *MockJobMessageSender_Send_OngoingVerification) GetCapturedArguments() ( } func (c *MockJobMessageSender_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []string, _param2 []bool) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } - _param1 = make([]string, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(string) + if len(_params) > 1 { + _param1 = make([]string, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(string) + } } - _param2 = make([]bool, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(bool) + if len(_params) > 2 { + _param2 = make([]bool, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(bool) + } } } return diff --git a/server/events/mocks/mock_job_url_setter.go b/server/events/mocks/mock_job_url_setter.go index 427e081f27..6455c4a201 100644 --- a/server/events/mocks/mock_job_url_setter.go +++ b/server/events/mocks/mock_job_url_setter.go @@ -30,15 +30,15 @@ func (mock *MockJobURLSetter) SetJobURLWithStatus(ctx command.ProjectContext, cm if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobURLSetter().") } - params := []pegomock.Param{ctx, cmdName, status, res} - result := pegomock.GetGenericMockFrom(mock).Invoke("SetJobURLWithStatus", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(error) + _params := []pegomock.Param{ctx, cmdName, status, res} + _result := pegomock.GetGenericMockFrom(mock).Invoke("SetJobURLWithStatus", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(error) } } - return ret0 + return _ret0 } func (mock *MockJobURLSetter) VerifyWasCalledOnce() *VerifierMockJobURLSetter { @@ -79,8 +79,8 @@ type VerifierMockJobURLSetter struct { } func (verifier *VerifierMockJobURLSetter) SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, res *command.ProjectResult) *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification { - params := []pegomock.Param{ctx, cmdName, status, res} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SetJobURLWithStatus", params, verifier.timeout) + _params := []pegomock.Param{ctx, cmdName, status, res} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SetJobURLWithStatus", _params, verifier.timeout) return &MockJobURLSetter_SetJobURLWithStatus_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -95,23 +95,31 @@ func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetCapturedAr } func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []*command.ProjectResult) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } - _param1 = make([]command.Name, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(command.Name) + if len(_params) > 1 { + _param1 = make([]command.Name, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(command.Name) + } } - _param2 = make([]models.CommitStatus, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(models.CommitStatus) + if len(_params) > 2 { + _param2 = make([]models.CommitStatus, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(models.CommitStatus) + } } - _param3 = make([]*command.ProjectResult, len(c.methodInvocations)) - for u, param := range params[3] { - _param3[u] = param.(*command.ProjectResult) + if len(_params) > 3 { + _param3 = make([]*command.ProjectResult, len(c.methodInvocations)) + for u, param := range _params[3] { + _param3[u] = param.(*command.ProjectResult) + } } } return diff --git a/server/events/mocks/mock_lock_url_generator.go b/server/events/mocks/mock_lock_url_generator.go index bb3f40a49a..6e581d65ea 100644 --- a/server/events/mocks/mock_lock_url_generator.go +++ b/server/events/mocks/mock_lock_url_generator.go @@ -28,15 +28,15 @@ func (mock *MockLockURLGenerator) GenerateLockURL(lockID string) string { if mock == nil { panic("mock must not be nil. Use myMock := NewMockLockURLGenerator().") } - params := []pegomock.Param{lockID} - result := pegomock.GetGenericMockFrom(mock).Invoke("GenerateLockURL", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) - var ret0 string - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) + _params := []pegomock.Param{lockID} + _result := pegomock.GetGenericMockFrom(mock).Invoke("GenerateLockURL", _params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) + var _ret0 string + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(string) } } - return ret0 + return _ret0 } func (mock *MockLockURLGenerator) VerifyWasCalledOnce() *VerifierMockLockURLGenerator { @@ -77,8 +77,8 @@ type VerifierMockLockURLGenerator struct { } func (verifier *VerifierMockLockURLGenerator) GenerateLockURL(lockID string) *MockLockURLGenerator_GenerateLockURL_OngoingVerification { - params := []pegomock.Param{lockID} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GenerateLockURL", params, verifier.timeout) + _params := []pegomock.Param{lockID} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GenerateLockURL", _params, verifier.timeout) return &MockLockURLGenerator_GenerateLockURL_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -93,11 +93,13 @@ func (c *MockLockURLGenerator_GenerateLockURL_OngoingVerification) GetCapturedAr } func (c *MockLockURLGenerator_GenerateLockURL_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]string, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(string) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]string, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(string) + } } } return diff --git a/server/events/mocks/mock_project_command_builder.go b/server/events/mocks/mock_project_command_builder.go index 6a68f048b6..4395759917 100644 --- a/server/events/mocks/mock_project_command_builder.go +++ b/server/events/mocks/mock_project_command_builder.go @@ -30,133 +30,133 @@ func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } - params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApplyCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []command.ProjectContext - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]command.ProjectContext) + _params := []pegomock.Param{ctx, comment} + _result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApplyCommands", _params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []command.ProjectContext + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]command.ProjectContext) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, comment *events.CommentCommand) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } - params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApprovePoliciesCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []command.ProjectContext - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]command.ProjectContext) + _params := []pegomock.Param{ctx, comment} + _result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApprovePoliciesCommands", _params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []command.ProjectContext + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]command.ProjectContext) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } - params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildAutoplanCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []command.ProjectContext - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]command.ProjectContext) + _params := []pegomock.Param{ctx} + _result := pegomock.GetGenericMockFrom(mock).Invoke("BuildAutoplanCommands", _params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []command.ProjectContext + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]command.ProjectContext) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockProjectCommandBuilder) BuildImportCommands(ctx *command.Context, comment *events.CommentCommand) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } - params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildImportCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []command.ProjectContext - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]command.ProjectContext) + _params := []pegomock.Param{ctx, comment} + _result := pegomock.GetGenericMockFrom(mock).Invoke("BuildImportCommands", _params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []command.ProjectContext + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]command.ProjectContext) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *events.CommentCommand) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } - params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildPlanCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []command.ProjectContext - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]command.ProjectContext) + _params := []pegomock.Param{ctx, comment} + _result := pegomock.GetGenericMockFrom(mock).Invoke("BuildPlanCommands", _params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []command.ProjectContext + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]command.ProjectContext) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockProjectCommandBuilder) BuildStateRmCommands(ctx *command.Context, comment *events.CommentCommand) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } - params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildStateRmCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []command.ProjectContext - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]command.ProjectContext) + _params := []pegomock.Param{ctx, comment} + _result := pegomock.GetGenericMockFrom(mock).Invoke("BuildStateRmCommands", _params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []command.ProjectContext + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]command.ProjectContext) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, comment *events.CommentCommand) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } - params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildVersionCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []command.ProjectContext - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]command.ProjectContext) + _params := []pegomock.Param{ctx, comment} + _result := pegomock.GetGenericMockFrom(mock).Invoke("BuildVersionCommands", _params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []command.ProjectContext + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]command.ProjectContext) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockProjectCommandBuilder) VerifyWasCalledOnce() *VerifierMockProjectCommandBuilder { @@ -197,8 +197,8 @@ type VerifierMockProjectCommandBuilder struct { } func (verifier *VerifierMockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification { - params := []pegomock.Param{ctx, comment} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildApplyCommands", params, verifier.timeout) + _params := []pegomock.Param{ctx, comment} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildApplyCommands", _params, verifier.timeout) return &MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -213,23 +213,27 @@ func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetCa } func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]*command.Context, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(*command.Context) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]*command.Context, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(*command.Context) + } } - _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(*events.CommentCommand) + if len(_params) > 1 { + _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(*events.CommentCommand) + } } } return } func (verifier *VerifierMockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification { - params := []pegomock.Param{ctx, comment} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildApprovePoliciesCommands", params, verifier.timeout) + _params := []pegomock.Param{ctx, comment} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildApprovePoliciesCommands", _params, verifier.timeout) return &MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -244,23 +248,27 @@ func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerificat } func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]*command.Context, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(*command.Context) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]*command.Context, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(*command.Context) + } } - _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(*events.CommentCommand) + if len(_params) > 1 { + _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(*events.CommentCommand) + } } } return } func (verifier *VerifierMockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification { - params := []pegomock.Param{ctx} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildAutoplanCommands", params, verifier.timeout) + _params := []pegomock.Param{ctx} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildAutoplanCommands", _params, verifier.timeout) return &MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -275,19 +283,21 @@ func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) Ge } func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]*command.Context, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(*command.Context) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]*command.Context, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(*command.Context) + } } } return } func (verifier *VerifierMockProjectCommandBuilder) BuildImportCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildImportCommands_OngoingVerification { - params := []pegomock.Param{ctx, comment} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildImportCommands", params, verifier.timeout) + _params := []pegomock.Param{ctx, comment} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildImportCommands", _params, verifier.timeout) return &MockProjectCommandBuilder_BuildImportCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -302,23 +312,27 @@ func (c *MockProjectCommandBuilder_BuildImportCommands_OngoingVerification) GetC } func (c *MockProjectCommandBuilder_BuildImportCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]*command.Context, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(*command.Context) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]*command.Context, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(*command.Context) + } } - _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(*events.CommentCommand) + if len(_params) > 1 { + _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(*events.CommentCommand) + } } } return } func (verifier *VerifierMockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification { - params := []pegomock.Param{ctx, comment} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildPlanCommands", params, verifier.timeout) + _params := []pegomock.Param{ctx, comment} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildPlanCommands", _params, verifier.timeout) return &MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -333,23 +347,27 @@ func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetCap } func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]*command.Context, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(*command.Context) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]*command.Context, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(*command.Context) + } } - _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(*events.CommentCommand) + if len(_params) > 1 { + _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(*events.CommentCommand) + } } } return } func (verifier *VerifierMockProjectCommandBuilder) BuildStateRmCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildStateRmCommands_OngoingVerification { - params := []pegomock.Param{ctx, comment} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildStateRmCommands", params, verifier.timeout) + _params := []pegomock.Param{ctx, comment} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildStateRmCommands", _params, verifier.timeout) return &MockProjectCommandBuilder_BuildStateRmCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -364,23 +382,27 @@ func (c *MockProjectCommandBuilder_BuildStateRmCommands_OngoingVerification) Get } func (c *MockProjectCommandBuilder_BuildStateRmCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]*command.Context, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(*command.Context) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]*command.Context, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(*command.Context) + } } - _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(*events.CommentCommand) + if len(_params) > 1 { + _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(*events.CommentCommand) + } } } return } func (verifier *VerifierMockProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification { - params := []pegomock.Param{ctx, comment} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildVersionCommands", params, verifier.timeout) + _params := []pegomock.Param{ctx, comment} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildVersionCommands", _params, verifier.timeout) return &MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -395,15 +417,19 @@ func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) Get } func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]*command.Context, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(*command.Context) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]*command.Context, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(*command.Context) + } } - _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(*events.CommentCommand) + if len(_params) > 1 { + _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(*events.CommentCommand) + } } } return diff --git a/server/events/mocks/mock_project_command_runner.go b/server/events/mocks/mock_project_command_runner.go index be42228cd1..dc30989b45 100644 --- a/server/events/mocks/mock_project_command_runner.go +++ b/server/events/mocks/mock_project_command_runner.go @@ -29,105 +29,105 @@ func (mock *MockProjectCommandRunner) Apply(ctx command.ProjectContext) command. if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } - params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Apply", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var ret0 command.ProjectResult - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(command.ProjectResult) + _params := []pegomock.Param{ctx} + _result := pegomock.GetGenericMockFrom(mock).Invoke("Apply", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var _ret0 command.ProjectResult + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(command.ProjectResult) } } - return ret0 + return _ret0 } func (mock *MockProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } - params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("ApprovePolicies", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var ret0 command.ProjectResult - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(command.ProjectResult) + _params := []pegomock.Param{ctx} + _result := pegomock.GetGenericMockFrom(mock).Invoke("ApprovePolicies", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var _ret0 command.ProjectResult + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(command.ProjectResult) } } - return ret0 + return _ret0 } func (mock *MockProjectCommandRunner) Import(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } - params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Import", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var ret0 command.ProjectResult - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(command.ProjectResult) + _params := []pegomock.Param{ctx} + _result := pegomock.GetGenericMockFrom(mock).Invoke("Import", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var _ret0 command.ProjectResult + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(command.ProjectResult) } } - return ret0 + return _ret0 } func (mock *MockProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } - params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Plan", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var ret0 command.ProjectResult - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(command.ProjectResult) + _params := []pegomock.Param{ctx} + _result := pegomock.GetGenericMockFrom(mock).Invoke("Plan", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var _ret0 command.ProjectResult + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(command.ProjectResult) } } - return ret0 + return _ret0 } func (mock *MockProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } - params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("PolicyCheck", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var ret0 command.ProjectResult - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(command.ProjectResult) + _params := []pegomock.Param{ctx} + _result := pegomock.GetGenericMockFrom(mock).Invoke("PolicyCheck", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var _ret0 command.ProjectResult + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(command.ProjectResult) } } - return ret0 + return _ret0 } func (mock *MockProjectCommandRunner) StateRm(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } - params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("StateRm", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var ret0 command.ProjectResult - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(command.ProjectResult) + _params := []pegomock.Param{ctx} + _result := pegomock.GetGenericMockFrom(mock).Invoke("StateRm", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var _ret0 command.ProjectResult + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(command.ProjectResult) } } - return ret0 + return _ret0 } func (mock *MockProjectCommandRunner) Version(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } - params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Version", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var ret0 command.ProjectResult - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(command.ProjectResult) + _params := []pegomock.Param{ctx} + _result := pegomock.GetGenericMockFrom(mock).Invoke("Version", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var _ret0 command.ProjectResult + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(command.ProjectResult) } } - return ret0 + return _ret0 } func (mock *MockProjectCommandRunner) VerifyWasCalledOnce() *VerifierMockProjectCommandRunner { @@ -168,8 +168,8 @@ type VerifierMockProjectCommandRunner struct { } func (verifier *VerifierMockProjectCommandRunner) Apply(ctx command.ProjectContext) *MockProjectCommandRunner_Apply_OngoingVerification { - params := []pegomock.Param{ctx} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Apply", params, verifier.timeout) + _params := []pegomock.Param{ctx} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Apply", _params, verifier.timeout) return &MockProjectCommandRunner_Apply_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -184,19 +184,21 @@ func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetCapturedArgument } func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } } return } func (verifier *VerifierMockProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) *MockProjectCommandRunner_ApprovePolicies_OngoingVerification { - params := []pegomock.Param{ctx} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ApprovePolicies", params, verifier.timeout) + _params := []pegomock.Param{ctx} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ApprovePolicies", _params, verifier.timeout) return &MockProjectCommandRunner_ApprovePolicies_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -211,19 +213,21 @@ func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetCaptur } func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } } return } func (verifier *VerifierMockProjectCommandRunner) Import(ctx command.ProjectContext) *MockProjectCommandRunner_Import_OngoingVerification { - params := []pegomock.Param{ctx} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Import", params, verifier.timeout) + _params := []pegomock.Param{ctx} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Import", _params, verifier.timeout) return &MockProjectCommandRunner_Import_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -238,19 +242,21 @@ func (c *MockProjectCommandRunner_Import_OngoingVerification) GetCapturedArgumen } func (c *MockProjectCommandRunner_Import_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } } return } func (verifier *VerifierMockProjectCommandRunner) Plan(ctx command.ProjectContext) *MockProjectCommandRunner_Plan_OngoingVerification { - params := []pegomock.Param{ctx} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Plan", params, verifier.timeout) + _params := []pegomock.Param{ctx} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Plan", _params, verifier.timeout) return &MockProjectCommandRunner_Plan_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -265,19 +271,21 @@ func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetCapturedArguments } func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } } return } func (verifier *VerifierMockProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) *MockProjectCommandRunner_PolicyCheck_OngoingVerification { - params := []pegomock.Param{ctx} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PolicyCheck", params, verifier.timeout) + _params := []pegomock.Param{ctx} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PolicyCheck", _params, verifier.timeout) return &MockProjectCommandRunner_PolicyCheck_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -292,19 +300,21 @@ func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetCapturedAr } func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } } return } func (verifier *VerifierMockProjectCommandRunner) StateRm(ctx command.ProjectContext) *MockProjectCommandRunner_StateRm_OngoingVerification { - params := []pegomock.Param{ctx} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "StateRm", params, verifier.timeout) + _params := []pegomock.Param{ctx} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "StateRm", _params, verifier.timeout) return &MockProjectCommandRunner_StateRm_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -319,19 +329,21 @@ func (c *MockProjectCommandRunner_StateRm_OngoingVerification) GetCapturedArgume } func (c *MockProjectCommandRunner_StateRm_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } } return } func (verifier *VerifierMockProjectCommandRunner) Version(ctx command.ProjectContext) *MockProjectCommandRunner_Version_OngoingVerification { - params := []pegomock.Param{ctx} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Version", params, verifier.timeout) + _params := []pegomock.Param{ctx} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Version", _params, verifier.timeout) return &MockProjectCommandRunner_Version_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -346,11 +358,13 @@ func (c *MockProjectCommandRunner_Version_OngoingVerification) GetCapturedArgume } func (c *MockProjectCommandRunner_Version_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } } return diff --git a/server/events/mocks/mock_step_runner.go b/server/events/mocks/mock_step_runner.go index fdfd95aa7c..92c1510d65 100644 --- a/server/events/mocks/mock_step_runner.go +++ b/server/events/mocks/mock_step_runner.go @@ -29,19 +29,19 @@ func (mock *MockStepRunner) Run(ctx command.ProjectContext, extraArgs []string, if mock == nil { panic("mock must not be nil. Use myMock := NewMockStepRunner().") } - params := []pegomock.Param{ctx, extraArgs, path, envs} - result := pegomock.GetGenericMockFrom(mock).Invoke("Run", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) + _params := []pegomock.Param{ctx, extraArgs, path, envs} + _result := pegomock.GetGenericMockFrom(mock).Invoke("Run", _params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 string + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(string) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockStepRunner) VerifyWasCalledOnce() *VerifierMockStepRunner { @@ -82,8 +82,8 @@ type VerifierMockStepRunner struct { } func (verifier *VerifierMockStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) *MockStepRunner_Run_OngoingVerification { - params := []pegomock.Param{ctx, extraArgs, path, envs} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) + _params := []pegomock.Param{ctx, extraArgs, path, envs} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", _params, verifier.timeout) return &MockStepRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -98,23 +98,31 @@ func (c *MockStepRunner_Run_OngoingVerification) GetCapturedArguments() (command } func (c *MockStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 [][]string, _param2 []string, _param3 []map[string]string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]command.ProjectContext, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(command.ProjectContext) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(command.ProjectContext) + } } - _param1 = make([][]string, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.([]string) + if len(_params) > 1 { + _param1 = make([][]string, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.([]string) + } } - _param2 = make([]string, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(string) + if len(_params) > 2 { + _param2 = make([]string, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(string) + } } - _param3 = make([]map[string]string, len(c.methodInvocations)) - for u, param := range params[3] { - _param3[u] = param.(map[string]string) + if len(_params) > 3 { + _param3 = make([]map[string]string, len(c.methodInvocations)) + for u, param := range _params[3] { + _param3[u] = param.(map[string]string) + } } } return diff --git a/server/events/mocks/mock_webhooks_sender.go b/server/events/mocks/mock_webhooks_sender.go index 48a3dcd576..b0f9d368e3 100644 --- a/server/events/mocks/mock_webhooks_sender.go +++ b/server/events/mocks/mock_webhooks_sender.go @@ -30,15 +30,15 @@ func (mock *MockWebhooksSender) Send(log logging.SimpleLogging, res webhooks.App if mock == nil { panic("mock must not be nil. Use myMock := NewMockWebhooksSender().") } - params := []pegomock.Param{log, res} - result := pegomock.GetGenericMockFrom(mock).Invoke("Send", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(error) + _params := []pegomock.Param{log, res} + _result := pegomock.GetGenericMockFrom(mock).Invoke("Send", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(error) } } - return ret0 + return _ret0 } func (mock *MockWebhooksSender) VerifyWasCalledOnce() *VerifierMockWebhooksSender { @@ -79,8 +79,8 @@ type VerifierMockWebhooksSender struct { } func (verifier *VerifierMockWebhooksSender) Send(log logging.SimpleLogging, res webhooks.ApplyResult) *MockWebhooksSender_Send_OngoingVerification { - params := []pegomock.Param{log, res} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Send", params, verifier.timeout) + _params := []pegomock.Param{log, res} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Send", _params, verifier.timeout) return &MockWebhooksSender_Send_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -95,15 +95,19 @@ func (c *MockWebhooksSender_Send_OngoingVerification) GetCapturedArguments() (lo } func (c *MockWebhooksSender_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []webhooks.ApplyResult) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } } - _param1 = make([]webhooks.ApplyResult, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(webhooks.ApplyResult) + if len(_params) > 1 { + _param1 = make([]webhooks.ApplyResult, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(webhooks.ApplyResult) + } } } return diff --git a/server/events/project_command_runner.go b/server/events/project_command_runner.go index 153269c7e2..ce71765290 100644 --- a/server/events/project_command_runner.go +++ b/server/events/project_command_runner.go @@ -203,6 +203,7 @@ type DefaultProjectCommandRunner struct { VcsClient vcs.Client Locker ProjectLocker LockURLGenerator LockURLGenerator + Logger logging.SimpleLogging InitStepRunner StepRunner PlanStepRunner StepRunner ShowStepRunner StepRunner @@ -345,7 +346,7 @@ func (p *DefaultProjectCommandRunner) doApprovePolicies(ctx command.ProjectConte // Only query the users team membership if any teams have been configured as owners on any policy set(s). if policySetCfg.HasTeamOwners() { // A convenient way to access vcsClient. Not sure if best way. - userTeams, err := p.VcsClient.GetTeamNamesForUser(ctx.Pull.BaseRepo, ctx.User) + userTeams, err := p.VcsClient.GetTeamNamesForUser(p.Logger, ctx.Pull.BaseRepo, ctx.User) if err != nil { ctx.Log.Err("unable to get team membership for user: %s", err) return nil, "", err diff --git a/server/events/project_command_runner_test.go b/server/events/project_command_runner_test.go index d241d44569..6d2a9f450b 100644 --- a/server/events/project_command_runner_test.go +++ b/server/events/project_command_runner_test.go @@ -1276,7 +1276,7 @@ func TestDefaultProjectCommandRunner_ApprovePolicies(t *testing.T) { } modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num, Author: testdata.User.Username} - When(runner.VcsClient.GetTeamNamesForUser(testdata.GithubRepo, testdata.User)).ThenReturn(c.userTeams, nil) + When(runner.VcsClient.GetTeamNamesForUser(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.User))).ThenReturn(c.userTeams, nil) ctx := command.ProjectContext{ User: testdata.User, Log: logging.NewNoopLogger(t), diff --git a/server/events/team_allowlist_checker.go b/server/events/team_allowlist_checker.go index 01e7bed73c..e635cf3427 100644 --- a/server/events/team_allowlist_checker.go +++ b/server/events/team_allowlist_checker.go @@ -71,3 +71,29 @@ func (checker *TeamAllowlistChecker) IsCommandAllowedForAnyTeam(teams []string, } return false } + +// AllTeams returns all teams listed in the rule for a command +func (checker *TeamAllowlistChecker) AllTeamsForCommand(command string) []string { + var teamNames []string + for _, rule := range checker.rules { + for key, value := range rule { + if strings.EqualFold(value, command) { + teamNames = append(teamNames, key) + } + } + } + return teamNames +} + +// AllTeams returns all teams listed in the rule for all commands +func (checker *TeamAllowlistChecker) AllTeams() []string { + var teamNames []string + for _, rule := range checker.rules { + for key := range rule { + + teamNames = append(teamNames, key) + + } + } + return teamNames +} diff --git a/server/events/team_allowlist_checker_test.go b/server/events/team_allowlist_checker_test.go index b389b49ae0..0a062eaecf 100644 --- a/server/events/team_allowlist_checker_test.go +++ b/server/events/team_allowlist_checker_test.go @@ -41,3 +41,11 @@ func TestIsCommandAllowedForAnyTeam(t *testing.T) { Equals(t, true, checker.IsCommandAllowedForAnyTeam(teams, `unlock`)) Equals(t, false, checker.IsCommandAllowedForAnyTeam(teams, `noop`)) } + +func TestAllTeamsForCommand(t *testing.T) { + allowlist := `bob:plan, dave:apply, connie:plan, connie:apply` + checker, err := events.NewTeamAllowlistChecker(allowlist) + Ok(t, err) + Equals(t, []string{"bob", "connie"}, checker.AllTeamsForCommand(`plan`)) + Equals(t, []string{"dave", "connie"}, checker.AllTeamsForCommand(`apply`)) +} diff --git a/server/events/vcs/azuredevops_client.go b/server/events/vcs/azuredevops_client.go index 1d115d28e9..b3123d11c6 100644 --- a/server/events/vcs/azuredevops_client.go +++ b/server/events/vcs/azuredevops_client.go @@ -391,7 +391,7 @@ func SplitAzureDevopsRepoFullName(repoFullName string) (owner string, project st } // GetTeamNamesForUser returns the names of the teams or groups that the user belongs to (in the organization the repository belongs to). -func (g *AzureDevopsClient) GetTeamNamesForUser(repo models.Repo, user models.User) ([]string, error) { //nolint: revive +func (g *AzureDevopsClient) GetTeamNamesForUser(_ logging.SimpleLogging, _ models.Repo, _ models.User) ([]string, error) { //nolint: revive return nil, nil } diff --git a/server/events/vcs/bitbucketcloud/client.go b/server/events/vcs/bitbucketcloud/client.go index a0dcfd7161..7d3bc088b4 100644 --- a/server/events/vcs/bitbucketcloud/client.go +++ b/server/events/vcs/bitbucketcloud/client.go @@ -264,7 +264,7 @@ func (b *Client) makeRequest(method string, path string, reqBody io.Reader) ([]b } // GetTeamNamesForUser returns the names of the teams or groups that the user belongs to (in the organization the repository belongs to). -func (b *Client) GetTeamNamesForUser(_ models.Repo, _ models.User) ([]string, error) { +func (b *Client) GetTeamNamesForUser(_ logging.SimpleLogging, _ models.Repo, _ models.User) ([]string, error) { return nil, nil } diff --git a/server/events/vcs/bitbucketserver/client.go b/server/events/vcs/bitbucketserver/client.go index 69dbbde518..4d916e5d7b 100644 --- a/server/events/vcs/bitbucketserver/client.go +++ b/server/events/vcs/bitbucketserver/client.go @@ -348,7 +348,7 @@ func (b *Client) makeRequest(method string, path string, reqBody io.Reader) ([]b } // GetTeamNamesForUser returns the names of the teams or groups that the user belongs to (in the organization the repository belongs to). -func (b *Client) GetTeamNamesForUser(_ models.Repo, _ models.User) ([]string, error) { +func (b *Client) GetTeamNamesForUser(_ logging.SimpleLogging, _ models.Repo, _ models.User) ([]string, error) { return nil, nil } diff --git a/server/events/vcs/client.go b/server/events/vcs/client.go index b6ad7cb9cd..8b3a6f9093 100644 --- a/server/events/vcs/client.go +++ b/server/events/vcs/client.go @@ -42,7 +42,7 @@ type Client interface { DiscardReviews(repo models.Repo, pull models.PullRequest) error MergePull(logger logging.SimpleLogging, pull models.PullRequest, pullOptions models.PullRequestOptions) error MarkdownPullLink(pull models.PullRequest) (string, error) - GetTeamNamesForUser(repo models.Repo, user models.User) ([]string, error) + GetTeamNamesForUser(logger logging.SimpleLogging, repo models.Repo, user models.User) ([]string, error) // GetFileContent a repository file content from VCS (which support fetch a single file from repository) // The first return value indicates whether the repo contains a file or not diff --git a/server/events/vcs/gitea/client.go b/server/events/vcs/gitea/client.go index f9deb2cb74..f749f3ad35 100644 --- a/server/events/vcs/gitea/client.go +++ b/server/events/vcs/gitea/client.go @@ -413,7 +413,7 @@ func (c *GiteaClient) MarkdownPullLink(pull models.PullRequest) (string, error) } // GetTeamNamesForUser returns the names of the teams or groups that the user belongs to (in the organization the repository belongs to). -func (c *GiteaClient) GetTeamNamesForUser(repo models.Repo, user models.User) ([]string, error) { +func (c *GiteaClient) GetTeamNamesForUser(_ logging.SimpleLogging, _ models.Repo, _ models.User) ([]string, error) { // TODO: implement return nil, errors.New("GetTeamNamesForUser not (yet) implemented for Gitea client") } diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index a561833e6f..5e5239b246 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -687,7 +687,8 @@ func (g *GithubClient) MarkdownPullLink(pull models.PullRequest) (string, error) // GetTeamNamesForUser returns the names of the teams or groups that the user belongs to (in the organization the repository belongs to). // https://docs.github.com/en/graphql/reference/objects#organization -func (g *GithubClient) GetTeamNamesForUser(repo models.Repo, user models.User) ([]string, error) { +func (g *GithubClient) GetTeamNamesForUser(logger logging.SimpleLogging, repo models.Repo, user models.User) ([]string, error) { + logger.Debug("Getting GitHub team names for user '%s'", user) orgName := repo.Owner variables := map[string]interface{}{ "orgName": githubv4.String(orgName), diff --git a/server/events/vcs/github_client_test.go b/server/events/vcs/github_client_test.go index 44ad33a1c4..de03857dab 100644 --- a/server/events/vcs/github_client_test.go +++ b/server/events/vcs/github_client_test.go @@ -1336,11 +1336,13 @@ func TestGithubClient_GetTeamNamesForUser(t *testing.T) { Ok(t, err) defer disableSSLVerification()() - teams, err := client.GetTeamNamesForUser(models.Repo{ - Owner: "testrepo", - }, models.User{ - Username: "testuser", - }) + teams, err := client.GetTeamNamesForUser( + logger, + models.Repo{ + Owner: "testrepo", + }, models.User{ + Username: "testuser", + }) Ok(t, err) Equals(t, []string{"Frontend Developers", "frontend-developers", "Employees", "employees"}, teams) } diff --git a/server/events/vcs/gitlab_client.go b/server/events/vcs/gitlab_client.go index 289b1a0d8a..14f2776290 100644 --- a/server/events/vcs/gitlab_client.go +++ b/server/events/vcs/gitlab_client.go @@ -45,6 +45,11 @@ type GitlabClient struct { PollingInterval time.Duration // PollingInterval is the total duration for which to poll, where applicable. PollingTimeout time.Duration + + // configuredTeams are teams whose membership we might want to check + // the gitlab list groups for a user, so instead of looping over every possible group when running GetTeamNamesForUser, + // we only use those we know we might need + configuredTeams []string } // commonMarkSupported is a version constraint that is true when this version of @@ -56,11 +61,12 @@ var commonMarkSupported = MustConstraint(">=11.1") var gitlabClientUnderTest = false // NewGitlabClient returns a valid GitLab client. -func NewGitlabClient(hostname string, token string, logger logging.SimpleLogging) (*GitlabClient, error) { +func NewGitlabClient(hostname string, token string, logger logging.SimpleLogging, configuredTeams []string) (*GitlabClient, error) { logger.Debug("Creating new GitLab client for %s", hostname) client := &GitlabClient{ PollingInterval: time.Second, PollingTimeout: time.Second * 30, + configuredTeams: configuredTeams, } // Create the client differently depending on the base URL. @@ -625,9 +631,40 @@ func MustConstraint(constraint string) version.Constraints { return c } -// GetTeamNamesForUser returns the names of the teams or groups that the user belongs to (in the organization the repository belongs to). -func (g *GitlabClient) GetTeamNamesForUser(_ models.Repo, _ models.User) ([]string, error) { - return nil, nil +// GetTeamNamesForUser returns the names of the GitLab groups that the user belongs to. +// The user membership is checked in each group from configuredTeams, groups +// that the Atlantis user doesn't have access to are silently ignored. +func (g *GitlabClient) GetTeamNamesForUser(logger logging.SimpleLogging, _ models.Repo, user models.User) ([]string, error) { + logger.Debug("Getting GitLab group names for user '%s'", user) + + var teamNames []string + + users, resp, err := g.Client.Users.ListUsers(&gitlab.ListUsersOptions{Username: &user.Username}) + if resp.StatusCode == http.StatusNotFound { + return teamNames, nil + } + if err != nil { + return nil, errors.Wrapf(err, "GET /users returned: %d", resp.StatusCode) + } else if len(users) == 0 { + return nil, errors.Wrap(err, "GET /users returned no user") + } else if len(users) > 1 { + // Theoretically impossible, just being extra safe + return nil, errors.Wrap(err, "GET /users returned more than 1 user") + } + userID := users[0].ID + for _, groupName := range g.configuredTeams { + membership, resp, err := g.Client.GroupMembers.GetGroupMember(groupName, userID) + if resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusForbidden { + continue + } + if err != nil { + return nil, errors.Wrapf(err, "GET /groups/%s/members/%d returned: %d", groupName, userID, resp.StatusCode) + } + if resp.StatusCode == http.StatusOK && membership.State == "active" { + teamNames = append(teamNames, groupName) + } + } + return teamNames, nil } // GetFileContent a repository file content from VCS (which support fetch a single file from repository) diff --git a/server/events/vcs/gitlab_client_test.go b/server/events/vcs/gitlab_client_test.go index cef424bcb0..9f43129434 100644 --- a/server/events/vcs/gitlab_client_test.go +++ b/server/events/vcs/gitlab_client_test.go @@ -66,7 +66,7 @@ func TestNewGitlabClient_BaseURL(t *testing.T) { for _, c := range cases { t.Run(c.Hostname, func(t *testing.T) { log := logging.NewNoopLogger(t) - client, err := NewGitlabClient(c.Hostname, "token", log) + client, err := NewGitlabClient(c.Hostname, "token", log, nil) Ok(t, err) Equals(t, c.ExpBaseURL, client.Client.BaseURL().String()) }) @@ -672,7 +672,7 @@ func TestGitlabClient_MarkdownPullLink(t *testing.T) { logger := logging.NewNoopLogger(t) gitlabClientUnderTest = true defer func() { gitlabClientUnderTest = false }() - client, err := NewGitlabClient("gitlab.com", "token", logger) + client, err := NewGitlabClient("gitlab.com", "token", logger, nil) Ok(t, err) pull := models.PullRequest{Num: 1} s, _ := client.MarkdownPullLink(pull) @@ -824,7 +824,7 @@ func TestGitlabClient_HideOldComments(t *testing.T) { } } -func TestGithubClient_GetPullLabels(t *testing.T) { +func TestGitlabClient_GetPullLabels(t *testing.T) { logger := logging.NewNoopLogger(t) mergeSuccessWithLabel, err := os.ReadFile("testdata/gitlab-merge-success-with-label.json") Ok(t, err) @@ -861,7 +861,7 @@ func TestGithubClient_GetPullLabels(t *testing.T) { Equals(t, []string{"work in progress"}, labels) } -func TestGithubClient_GetPullLabels_EmptyResponse(t *testing.T) { +func TestGitlabClient_GetPullLabels_EmptyResponse(t *testing.T) { logger := logging.NewNoopLogger(t) pipelineSuccess, err := os.ReadFile("testdata/gitlab-pipeline-success.json") Ok(t, err) @@ -895,3 +895,52 @@ func TestGithubClient_GetPullLabels_EmptyResponse(t *testing.T) { Ok(t, err) Equals(t, 0, len(labels)) } + +// GetTeamNamesForUser returns the names of the GitLab groups that the user belongs to. +func TestGitlabClient_GetTeamNamesForUser(t *testing.T) { + logger := logging.NewNoopLogger(t) + + groupMembershipSuccess, err := os.ReadFile("testdata/gitlab-group-membership-success.json") + Ok(t, err) + + userSuccess, err := os.ReadFile("testdata/gitlab-user-success.json") + Ok(t, err) + + configuredTeams := []string{"someorg/group1", "someorg/group2", "someorg/group3", "someorg/group4"} + testServer := httptest.NewServer( + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.RequestURI { + case "/api/v4/users?username=testuser": + w.WriteHeader(http.StatusOK) + w.Write(userSuccess) // nolint: errcheck + case "/api/v4/groups/someorg%2Fgroup1/members/123", "/api/v4/groups/someorg%2Fgroup2/members/123": + w.WriteHeader(http.StatusOK) + w.Write(groupMembershipSuccess) // nolint: errcheck + case "/api/v4/groups/someorg%2Fgroup3/members/123": + http.Error(w, "forbidden", http.StatusForbidden) + case "/api/v4/groups/someorg%2Fgroup4/members/123": + http.Error(w, "not found", http.StatusNotFound) + default: + t.Errorf("got unexpected request at %q", r.RequestURI) + http.Error(w, "not found", http.StatusNotFound) + } + })) + internalClient, err := gitlab.NewClient("token", gitlab.WithBaseURL(testServer.URL)) + Ok(t, err) + client := &GitlabClient{ + Client: internalClient, + Version: nil, + configuredTeams: configuredTeams, + } + + teams, err := client.GetTeamNamesForUser( + logger, + models.Repo{ + Owner: "someorg", + }, models.User{ + Username: "testuser", + }) + + Ok(t, err) + Equals(t, []string{"someorg/group1", "someorg/group2"}, teams) +} diff --git a/server/events/vcs/mocks/mock_client.go b/server/events/vcs/mocks/mock_client.go index ffa37fe8cb..afc0d5c139 100644 --- a/server/events/vcs/mocks/mock_client.go +++ b/server/events/vcs/mocks/mock_client.go @@ -30,261 +30,261 @@ func (mock *MockClient) CreateComment(logger logging.SimpleLogging, repo models. if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, repo, pullNum, comment, command} - result := pegomock.GetGenericMockFrom(mock).Invoke("CreateComment", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(error) + _params := []pegomock.Param{logger, repo, pullNum, comment, command} + _result := pegomock.GetGenericMockFrom(mock).Invoke("CreateComment", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(error) } } - return ret0 + return _ret0 } func (mock *MockClient) DiscardReviews(repo models.Repo, pull models.PullRequest) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{repo, pull} - result := pegomock.GetGenericMockFrom(mock).Invoke("DiscardReviews", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(error) + _params := []pegomock.Param{repo, pull} + _result := pegomock.GetGenericMockFrom(mock).Invoke("DiscardReviews", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(error) } } - return ret0 + return _ret0 } func (mock *MockClient) GetCloneURL(logger logging.SimpleLogging, VCSHostType models.VCSHostType, repo string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, VCSHostType, repo} - result := pegomock.GetGenericMockFrom(mock).Invoke("GetCloneURL", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) + _params := []pegomock.Param{logger, VCSHostType, repo} + _result := pegomock.GetGenericMockFrom(mock).Invoke("GetCloneURL", _params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 string + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(string) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockClient) GetFileContent(logger logging.SimpleLogging, pull models.PullRequest, fileName string) (bool, []byte, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, pull, fileName} - result := pegomock.GetGenericMockFrom(mock).Invoke("GetFileContent", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*[]byte)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool - var ret1 []byte - var ret2 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(bool) + _params := []pegomock.Param{logger, pull, fileName} + _result := pegomock.GetGenericMockFrom(mock).Invoke("GetFileContent", _params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*[]byte)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 bool + var _ret1 []byte + var _ret2 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(bool) } - if result[1] != nil { - ret1 = result[1].([]byte) + if _result[1] != nil { + _ret1 = _result[1].([]byte) } - if result[2] != nil { - ret2 = result[2].(error) + if _result[2] != nil { + _ret2 = _result[2].(error) } } - return ret0, ret1, ret2 + return _ret0, _ret1, _ret2 } func (mock *MockClient) GetModifiedFiles(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) ([]string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, repo, pull} - result := pegomock.GetGenericMockFrom(mock).Invoke("GetModifiedFiles", params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]string) + _params := []pegomock.Param{logger, repo, pull} + _result := pegomock.GetGenericMockFrom(mock).Invoke("GetModifiedFiles", _params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []string + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]string) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockClient) GetPullLabels(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) ([]string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, repo, pull} - result := pegomock.GetGenericMockFrom(mock).Invoke("GetPullLabels", params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]string) + _params := []pegomock.Param{logger, repo, pull} + _result := pegomock.GetGenericMockFrom(mock).Invoke("GetPullLabels", _params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []string + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]string) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } -func (mock *MockClient) GetTeamNamesForUser(repo models.Repo, user models.User) ([]string, error) { +func (mock *MockClient) GetTeamNamesForUser(logger logging.SimpleLogging, repo models.Repo, user models.User) ([]string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{repo, user} - result := pegomock.GetGenericMockFrom(mock).Invoke("GetTeamNamesForUser", params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]string) + _params := []pegomock.Param{logger, repo, user} + _result := pegomock.GetGenericMockFrom(mock).Invoke("GetTeamNamesForUser", _params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 []string + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].([]string) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockClient) HidePrevCommandComments(logger logging.SimpleLogging, repo models.Repo, pullNum int, command string, dir string) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, repo, pullNum, command, dir} - result := pegomock.GetGenericMockFrom(mock).Invoke("HidePrevCommandComments", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(error) + _params := []pegomock.Param{logger, repo, pullNum, command, dir} + _result := pegomock.GetGenericMockFrom(mock).Invoke("HidePrevCommandComments", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(error) } } - return ret0 + return _ret0 } func (mock *MockClient) MarkdownPullLink(pull models.PullRequest) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{pull} - result := pegomock.GetGenericMockFrom(mock).Invoke("MarkdownPullLink", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) + _params := []pegomock.Param{pull} + _result := pegomock.GetGenericMockFrom(mock).Invoke("MarkdownPullLink", _params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 string + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(string) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockClient) MergePull(logger logging.SimpleLogging, pull models.PullRequest, pullOptions models.PullRequestOptions) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, pull, pullOptions} - result := pegomock.GetGenericMockFrom(mock).Invoke("MergePull", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(error) + _params := []pegomock.Param{logger, pull, pullOptions} + _result := pegomock.GetGenericMockFrom(mock).Invoke("MergePull", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(error) } } - return ret0 + return _ret0 } func (mock *MockClient) PullIsApproved(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) (models.ApprovalStatus, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, repo, pull} - result := pegomock.GetGenericMockFrom(mock).Invoke("PullIsApproved", params, []reflect.Type{reflect.TypeOf((*models.ApprovalStatus)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 models.ApprovalStatus - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(models.ApprovalStatus) + _params := []pegomock.Param{logger, repo, pull} + _result := pegomock.GetGenericMockFrom(mock).Invoke("PullIsApproved", _params, []reflect.Type{reflect.TypeOf((*models.ApprovalStatus)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 models.ApprovalStatus + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(models.ApprovalStatus) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockClient) PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string) (bool, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, repo, pull, vcsstatusname} - result := pegomock.GetGenericMockFrom(mock).Invoke("PullIsMergeable", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(bool) + _params := []pegomock.Param{logger, repo, pull, vcsstatusname} + _result := pegomock.GetGenericMockFrom(mock).Invoke("PullIsMergeable", _params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 bool + var _ret1 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(bool) } - if result[1] != nil { - ret1 = result[1].(error) + if _result[1] != nil { + _ret1 = _result[1].(error) } } - return ret0, ret1 + return _ret0, _ret1 } func (mock *MockClient) ReactToComment(logger logging.SimpleLogging, repo models.Repo, pullNum int, commentID int64, reaction string) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, repo, pullNum, commentID, reaction} - result := pegomock.GetGenericMockFrom(mock).Invoke("ReactToComment", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(error) + _params := []pegomock.Param{logger, repo, pullNum, commentID, reaction} + _result := pegomock.GetGenericMockFrom(mock).Invoke("ReactToComment", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(error) } } - return ret0 + return _ret0 } func (mock *MockClient) SupportsSingleFileDownload(repo models.Repo) bool { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{repo} - result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsSingleFileDownload", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) - var ret0 bool - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(bool) + _params := []pegomock.Param{repo} + _result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsSingleFileDownload", _params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) + var _ret0 bool + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(bool) } } - return ret0 + return _ret0 } func (mock *MockClient) UpdateStatus(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } - params := []pegomock.Param{logger, repo, pull, state, src, description, url} - result := pegomock.GetGenericMockFrom(mock).Invoke("UpdateStatus", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(error) + _params := []pegomock.Param{logger, repo, pull, state, src, description, url} + _result := pegomock.GetGenericMockFrom(mock).Invoke("UpdateStatus", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var _ret0 error + if len(_result) != 0 { + if _result[0] != nil { + _ret0 = _result[0].(error) } } - return ret0 + return _ret0 } func (mock *MockClient) VerifyWasCalledOnce() *VerifierMockClient { @@ -325,8 +325,8 @@ type VerifierMockClient struct { } func (verifier *VerifierMockClient) CreateComment(logger logging.SimpleLogging, repo models.Repo, pullNum int, comment string, command string) *MockClient_CreateComment_OngoingVerification { - params := []pegomock.Param{logger, repo, pullNum, comment, command} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CreateComment", params, verifier.timeout) + _params := []pegomock.Param{logger, repo, pullNum, comment, command} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CreateComment", _params, verifier.timeout) return &MockClient_CreateComment_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -341,35 +341,45 @@ func (c *MockClient_CreateComment_OngoingVerification) GetCapturedArguments() (l } func (c *MockClient_CreateComment_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.Repo, _param2 []int, _param3 []string, _param4 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.Repo) - } - _param2 = make([]int, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(int) - } - _param3 = make([]string, len(c.methodInvocations)) - for u, param := range params[3] { - _param3[u] = param.(string) - } - _param4 = make([]string, len(c.methodInvocations)) - for u, param := range params[4] { - _param4[u] = param.(string) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.Repo) + } + } + if len(_params) > 2 { + _param2 = make([]int, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(int) + } + } + if len(_params) > 3 { + _param3 = make([]string, len(c.methodInvocations)) + for u, param := range _params[3] { + _param3[u] = param.(string) + } + } + if len(_params) > 4 { + _param4 = make([]string, len(c.methodInvocations)) + for u, param := range _params[4] { + _param4[u] = param.(string) + } } } return } func (verifier *VerifierMockClient) DiscardReviews(repo models.Repo, pull models.PullRequest) *MockClient_DiscardReviews_OngoingVerification { - params := []pegomock.Param{repo, pull} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DiscardReviews", params, verifier.timeout) + _params := []pegomock.Param{repo, pull} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DiscardReviews", _params, verifier.timeout) return &MockClient_DiscardReviews_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -384,23 +394,27 @@ func (c *MockClient_DiscardReviews_OngoingVerification) GetCapturedArguments() ( } func (c *MockClient_DiscardReviews_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.PullRequest) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(models.Repo) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(models.Repo) + } } - _param1 = make([]models.PullRequest, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.PullRequest) + if len(_params) > 1 { + _param1 = make([]models.PullRequest, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.PullRequest) + } } } return } func (verifier *VerifierMockClient) GetCloneURL(logger logging.SimpleLogging, VCSHostType models.VCSHostType, repo string) *MockClient_GetCloneURL_OngoingVerification { - params := []pegomock.Param{logger, VCSHostType, repo} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetCloneURL", params, verifier.timeout) + _params := []pegomock.Param{logger, VCSHostType, repo} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetCloneURL", _params, verifier.timeout) return &MockClient_GetCloneURL_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -415,27 +429,33 @@ func (c *MockClient_GetCloneURL_OngoingVerification) GetCapturedArguments() (log } func (c *MockClient_GetCloneURL_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.VCSHostType, _param2 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.VCSHostType, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.VCSHostType) - } - _param2 = make([]string, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(string) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.VCSHostType, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.VCSHostType) + } + } + if len(_params) > 2 { + _param2 = make([]string, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(string) + } } } return } func (verifier *VerifierMockClient) GetFileContent(logger logging.SimpleLogging, pull models.PullRequest, fileName string) *MockClient_GetFileContent_OngoingVerification { - params := []pegomock.Param{logger, pull, fileName} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetFileContent", params, verifier.timeout) + _params := []pegomock.Param{logger, pull, fileName} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetFileContent", _params, verifier.timeout) return &MockClient_GetFileContent_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -450,27 +470,33 @@ func (c *MockClient_GetFileContent_OngoingVerification) GetCapturedArguments() ( } func (c *MockClient_GetFileContent_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.PullRequest, _param2 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.PullRequest, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.PullRequest) - } - _param2 = make([]string, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(string) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.PullRequest, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.PullRequest) + } + } + if len(_params) > 2 { + _param2 = make([]string, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(string) + } } } return } func (verifier *VerifierMockClient) GetModifiedFiles(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) *MockClient_GetModifiedFiles_OngoingVerification { - params := []pegomock.Param{logger, repo, pull} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetModifiedFiles", params, verifier.timeout) + _params := []pegomock.Param{logger, repo, pull} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetModifiedFiles", _params, verifier.timeout) return &MockClient_GetModifiedFiles_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -485,27 +511,33 @@ func (c *MockClient_GetModifiedFiles_OngoingVerification) GetCapturedArguments() } func (c *MockClient_GetModifiedFiles_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.Repo, _param2 []models.PullRequest) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.Repo) - } - _param2 = make([]models.PullRequest, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(models.PullRequest) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.Repo) + } + } + if len(_params) > 2 { + _param2 = make([]models.PullRequest, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(models.PullRequest) + } } } return } func (verifier *VerifierMockClient) GetPullLabels(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) *MockClient_GetPullLabels_OngoingVerification { - params := []pegomock.Param{logger, repo, pull} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetPullLabels", params, verifier.timeout) + _params := []pegomock.Param{logger, repo, pull} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetPullLabels", _params, verifier.timeout) return &MockClient_GetPullLabels_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -520,27 +552,33 @@ func (c *MockClient_GetPullLabels_OngoingVerification) GetCapturedArguments() (l } func (c *MockClient_GetPullLabels_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.Repo, _param2 []models.PullRequest) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.Repo) - } - _param2 = make([]models.PullRequest, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(models.PullRequest) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.Repo) + } + } + if len(_params) > 2 { + _param2 = make([]models.PullRequest, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(models.PullRequest) + } } } return } -func (verifier *VerifierMockClient) GetTeamNamesForUser(repo models.Repo, user models.User) *MockClient_GetTeamNamesForUser_OngoingVerification { - params := []pegomock.Param{repo, user} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetTeamNamesForUser", params, verifier.timeout) +func (verifier *VerifierMockClient) GetTeamNamesForUser(logger logging.SimpleLogging, repo models.Repo, user models.User) *MockClient_GetTeamNamesForUser_OngoingVerification { + _params := []pegomock.Param{logger, repo, user} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetTeamNamesForUser", _params, verifier.timeout) return &MockClient_GetTeamNamesForUser_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -549,29 +587,39 @@ type MockClient_GetTeamNamesForUser_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockClient_GetTeamNamesForUser_OngoingVerification) GetCapturedArguments() (models.Repo, models.User) { - repo, user := c.GetAllCapturedArguments() - return repo[len(repo)-1], user[len(user)-1] +func (c *MockClient_GetTeamNamesForUser_OngoingVerification) GetCapturedArguments() (logging.SimpleLogging, models.Repo, models.User) { + logger, repo, user := c.GetAllCapturedArguments() + return logger[len(logger)-1], repo[len(repo)-1], user[len(user)-1] } -func (c *MockClient_GetTeamNamesForUser_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.User) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(models.Repo) +func (c *MockClient_GetTeamNamesForUser_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.Repo, _param2 []models.User) { + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.Repo) + } } - _param1 = make([]models.User, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.User) + if len(_params) > 2 { + _param2 = make([]models.User, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(models.User) + } } } return } func (verifier *VerifierMockClient) HidePrevCommandComments(logger logging.SimpleLogging, repo models.Repo, pullNum int, command string, dir string) *MockClient_HidePrevCommandComments_OngoingVerification { - params := []pegomock.Param{logger, repo, pullNum, command, dir} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HidePrevCommandComments", params, verifier.timeout) + _params := []pegomock.Param{logger, repo, pullNum, command, dir} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HidePrevCommandComments", _params, verifier.timeout) return &MockClient_HidePrevCommandComments_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -586,35 +634,45 @@ func (c *MockClient_HidePrevCommandComments_OngoingVerification) GetCapturedArgu } func (c *MockClient_HidePrevCommandComments_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.Repo, _param2 []int, _param3 []string, _param4 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.Repo) - } - _param2 = make([]int, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(int) - } - _param3 = make([]string, len(c.methodInvocations)) - for u, param := range params[3] { - _param3[u] = param.(string) - } - _param4 = make([]string, len(c.methodInvocations)) - for u, param := range params[4] { - _param4[u] = param.(string) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.Repo) + } + } + if len(_params) > 2 { + _param2 = make([]int, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(int) + } + } + if len(_params) > 3 { + _param3 = make([]string, len(c.methodInvocations)) + for u, param := range _params[3] { + _param3[u] = param.(string) + } + } + if len(_params) > 4 { + _param4 = make([]string, len(c.methodInvocations)) + for u, param := range _params[4] { + _param4[u] = param.(string) + } } } return } func (verifier *VerifierMockClient) MarkdownPullLink(pull models.PullRequest) *MockClient_MarkdownPullLink_OngoingVerification { - params := []pegomock.Param{pull} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MarkdownPullLink", params, verifier.timeout) + _params := []pegomock.Param{pull} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MarkdownPullLink", _params, verifier.timeout) return &MockClient_MarkdownPullLink_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -629,19 +687,21 @@ func (c *MockClient_MarkdownPullLink_OngoingVerification) GetCapturedArguments() } func (c *MockClient_MarkdownPullLink_OngoingVerification) GetAllCapturedArguments() (_param0 []models.PullRequest) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]models.PullRequest, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(models.PullRequest) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]models.PullRequest, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(models.PullRequest) + } } } return } func (verifier *VerifierMockClient) MergePull(logger logging.SimpleLogging, pull models.PullRequest, pullOptions models.PullRequestOptions) *MockClient_MergePull_OngoingVerification { - params := []pegomock.Param{logger, pull, pullOptions} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MergePull", params, verifier.timeout) + _params := []pegomock.Param{logger, pull, pullOptions} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MergePull", _params, verifier.timeout) return &MockClient_MergePull_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -656,27 +716,33 @@ func (c *MockClient_MergePull_OngoingVerification) GetCapturedArguments() (loggi } func (c *MockClient_MergePull_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.PullRequest, _param2 []models.PullRequestOptions) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.PullRequest, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.PullRequest) - } - _param2 = make([]models.PullRequestOptions, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(models.PullRequestOptions) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.PullRequest, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.PullRequest) + } + } + if len(_params) > 2 { + _param2 = make([]models.PullRequestOptions, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(models.PullRequestOptions) + } } } return } func (verifier *VerifierMockClient) PullIsApproved(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) *MockClient_PullIsApproved_OngoingVerification { - params := []pegomock.Param{logger, repo, pull} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PullIsApproved", params, verifier.timeout) + _params := []pegomock.Param{logger, repo, pull} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PullIsApproved", _params, verifier.timeout) return &MockClient_PullIsApproved_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -691,27 +757,33 @@ func (c *MockClient_PullIsApproved_OngoingVerification) GetCapturedArguments() ( } func (c *MockClient_PullIsApproved_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.Repo, _param2 []models.PullRequest) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.Repo) - } - _param2 = make([]models.PullRequest, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(models.PullRequest) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.Repo) + } + } + if len(_params) > 2 { + _param2 = make([]models.PullRequest, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(models.PullRequest) + } } } return } func (verifier *VerifierMockClient) PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string) *MockClient_PullIsMergeable_OngoingVerification { - params := []pegomock.Param{logger, repo, pull, vcsstatusname} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PullIsMergeable", params, verifier.timeout) + _params := []pegomock.Param{logger, repo, pull, vcsstatusname} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PullIsMergeable", _params, verifier.timeout) return &MockClient_PullIsMergeable_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -726,31 +798,39 @@ func (c *MockClient_PullIsMergeable_OngoingVerification) GetCapturedArguments() } func (c *MockClient_PullIsMergeable_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.Repo, _param2 []models.PullRequest, _param3 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.Repo) - } - _param2 = make([]models.PullRequest, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(models.PullRequest) - } - _param3 = make([]string, len(c.methodInvocations)) - for u, param := range params[3] { - _param3[u] = param.(string) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.Repo) + } + } + if len(_params) > 2 { + _param2 = make([]models.PullRequest, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(models.PullRequest) + } + } + if len(_params) > 3 { + _param3 = make([]string, len(c.methodInvocations)) + for u, param := range _params[3] { + _param3[u] = param.(string) + } } } return } func (verifier *VerifierMockClient) ReactToComment(logger logging.SimpleLogging, repo models.Repo, pullNum int, commentID int64, reaction string) *MockClient_ReactToComment_OngoingVerification { - params := []pegomock.Param{logger, repo, pullNum, commentID, reaction} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ReactToComment", params, verifier.timeout) + _params := []pegomock.Param{logger, repo, pullNum, commentID, reaction} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ReactToComment", _params, verifier.timeout) return &MockClient_ReactToComment_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -765,35 +845,45 @@ func (c *MockClient_ReactToComment_OngoingVerification) GetCapturedArguments() ( } func (c *MockClient_ReactToComment_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.Repo, _param2 []int, _param3 []int64, _param4 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.Repo) - } - _param2 = make([]int, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(int) - } - _param3 = make([]int64, len(c.methodInvocations)) - for u, param := range params[3] { - _param3[u] = param.(int64) - } - _param4 = make([]string, len(c.methodInvocations)) - for u, param := range params[4] { - _param4[u] = param.(string) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.Repo) + } + } + if len(_params) > 2 { + _param2 = make([]int, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(int) + } + } + if len(_params) > 3 { + _param3 = make([]int64, len(c.methodInvocations)) + for u, param := range _params[3] { + _param3[u] = param.(int64) + } + } + if len(_params) > 4 { + _param4 = make([]string, len(c.methodInvocations)) + for u, param := range _params[4] { + _param4[u] = param.(string) + } } } return } func (verifier *VerifierMockClient) SupportsSingleFileDownload(repo models.Repo) *MockClient_SupportsSingleFileDownload_OngoingVerification { - params := []pegomock.Param{repo} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsSingleFileDownload", params, verifier.timeout) + _params := []pegomock.Param{repo} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsSingleFileDownload", _params, verifier.timeout) return &MockClient_SupportsSingleFileDownload_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -808,19 +898,21 @@ func (c *MockClient_SupportsSingleFileDownload_OngoingVerification) GetCapturedA } func (c *MockClient_SupportsSingleFileDownload_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(models.Repo) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(models.Repo) + } } } return } func (verifier *VerifierMockClient) UpdateStatus(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) *MockClient_UpdateStatus_OngoingVerification { - params := []pegomock.Param{logger, repo, pull, state, src, description, url} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateStatus", params, verifier.timeout) + _params := []pegomock.Param{logger, repo, pull, state, src, description, url} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateStatus", _params, verifier.timeout) return &MockClient_UpdateStatus_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -835,35 +927,49 @@ func (c *MockClient_UpdateStatus_OngoingVerification) GetCapturedArguments() (lo } func (c *MockClient_UpdateStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []logging.SimpleLogging, _param1 []models.Repo, _param2 []models.PullRequest, _param3 []models.CommitStatus, _param4 []string, _param5 []string, _param6 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) - for u, param := range params[0] { - _param0[u] = param.(logging.SimpleLogging) - } - _param1 = make([]models.Repo, len(c.methodInvocations)) - for u, param := range params[1] { - _param1[u] = param.(models.Repo) - } - _param2 = make([]models.PullRequest, len(c.methodInvocations)) - for u, param := range params[2] { - _param2[u] = param.(models.PullRequest) - } - _param3 = make([]models.CommitStatus, len(c.methodInvocations)) - for u, param := range params[3] { - _param3[u] = param.(models.CommitStatus) - } - _param4 = make([]string, len(c.methodInvocations)) - for u, param := range params[4] { - _param4[u] = param.(string) - } - _param5 = make([]string, len(c.methodInvocations)) - for u, param := range params[5] { - _param5[u] = param.(string) - } - _param6 = make([]string, len(c.methodInvocations)) - for u, param := range params[6] { - _param6[u] = param.(string) + _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(_params) > 0 { + if len(_params) > 0 { + _param0 = make([]logging.SimpleLogging, len(c.methodInvocations)) + for u, param := range _params[0] { + _param0[u] = param.(logging.SimpleLogging) + } + } + if len(_params) > 1 { + _param1 = make([]models.Repo, len(c.methodInvocations)) + for u, param := range _params[1] { + _param1[u] = param.(models.Repo) + } + } + if len(_params) > 2 { + _param2 = make([]models.PullRequest, len(c.methodInvocations)) + for u, param := range _params[2] { + _param2[u] = param.(models.PullRequest) + } + } + if len(_params) > 3 { + _param3 = make([]models.CommitStatus, len(c.methodInvocations)) + for u, param := range _params[3] { + _param3[u] = param.(models.CommitStatus) + } + } + if len(_params) > 4 { + _param4 = make([]string, len(c.methodInvocations)) + for u, param := range _params[4] { + _param4[u] = param.(string) + } + } + if len(_params) > 5 { + _param5 = make([]string, len(c.methodInvocations)) + for u, param := range _params[5] { + _param5[u] = param.(string) + } + } + if len(_params) > 6 { + _param6 = make([]string, len(c.methodInvocations)) + for u, param := range _params[6] { + _param6[u] = param.(string) + } } } return diff --git a/server/events/vcs/not_configured_vcs_client.go b/server/events/vcs/not_configured_vcs_client.go index 6fd7a731cb..e73e52900d 100644 --- a/server/events/vcs/not_configured_vcs_client.go +++ b/server/events/vcs/not_configured_vcs_client.go @@ -60,7 +60,7 @@ func (a *NotConfiguredVCSClient) MarkdownPullLink(_ models.PullRequest) (string, func (a *NotConfiguredVCSClient) err() error { return fmt.Errorf("atlantis was not configured to support repos from %s", a.Host.String()) } -func (a *NotConfiguredVCSClient) GetTeamNamesForUser(_ models.Repo, _ models.User) ([]string, error) { +func (a *NotConfiguredVCSClient) GetTeamNamesForUser(_ logging.SimpleLogging, _ models.Repo, _ models.User) ([]string, error) { return nil, a.err() } diff --git a/server/events/vcs/proxy.go b/server/events/vcs/proxy.go index cd67b84c90..cfa43ab150 100644 --- a/server/events/vcs/proxy.go +++ b/server/events/vcs/proxy.go @@ -97,8 +97,8 @@ func (d *ClientProxy) MarkdownPullLink(pull models.PullRequest) (string, error) return d.clients[pull.BaseRepo.VCSHost.Type].MarkdownPullLink(pull) } -func (d *ClientProxy) GetTeamNamesForUser(repo models.Repo, user models.User) ([]string, error) { - return d.clients[repo.VCSHost.Type].GetTeamNamesForUser(repo, user) +func (d *ClientProxy) GetTeamNamesForUser(logger logging.SimpleLogging, repo models.Repo, user models.User) ([]string, error) { + return d.clients[repo.VCSHost.Type].GetTeamNamesForUser(logger, repo, user) } func (d *ClientProxy) GetFileContent(logger logging.SimpleLogging, pull models.PullRequest, fileName string) (bool, []byte, error) { diff --git a/server/events/vcs/testdata/gitlab-group-membership-success.json b/server/events/vcs/testdata/gitlab-group-membership-success.json new file mode 100644 index 0000000000..897c4438ad --- /dev/null +++ b/server/events/vcs/testdata/gitlab-group-membership-success.json @@ -0,0 +1,22 @@ +{ + "access_level": 50, + "created_at": "2023-11-28T01:23:45.789Z", + "created_by": { + "id": 456, + "username": "someone", + "name": "Someone", + "state": "active", + "locked": false, + "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/456/avatar.png", + "web_url": "https://gitlab.com/someone" + }, + "expires_at": null, + "id": 123, + "username": "testuser", + "name": "Test User", + "state": "active", + "locked": false, + "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/123/avatar.png", + "web_url": "https://gitlab.com/testuser", + "membership_state": "active" +} diff --git a/server/events/vcs/testdata/gitlab-user-success.json b/server/events/vcs/testdata/gitlab-user-success.json new file mode 100644 index 0000000000..0b87fc9e12 --- /dev/null +++ b/server/events/vcs/testdata/gitlab-user-success.json @@ -0,0 +1,11 @@ +[ + { + "id": 123, + "username": "testuser", + "name": "Test User", + "state": "active", + "locked": false, + "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/123/avatar.png", + "web_url": "https://gitlab.com/testuser" + } +] diff --git a/server/server.go b/server/server.go index 4a0e5aa738..45d2306bcf 100644 --- a/server/server.go +++ b/server/server.go @@ -265,10 +265,14 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { githubClient = vcs.NewInstrumentedGithubClient(rawGithubClient, statsScope, logger) } + gitlabGroupAllowlistChecker, err := events.NewTeamAllowlistChecker(userConfig.GitlabGroupAllowlist) + if err != nil { + return nil, err + } if userConfig.GitlabUser != "" { supportedVCSHosts = append(supportedVCSHosts, models.Gitlab) var err error - gitlabClient, err = vcs.NewGitlabClient(userConfig.GitlabHostname, userConfig.GitlabToken, logger) + gitlabClient, err = vcs.NewGitlabClient(userConfig.GitlabHostname, userConfig.GitlabToken, logger, gitlabGroupAllowlistChecker.AllTeams()) if err != nil { return nil, err } @@ -650,6 +654,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { VcsClient: vcsClient, Locker: projectLocker, LockURLGenerator: router, + Logger: logger, InitStepRunner: &runtime.InitStepRunner{ TerraformExecutor: terraformClient, DefaultTFVersion: defaultTfVersion, @@ -810,6 +815,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { if err != nil { return nil, err } + varFileAllowlistChecker, err := events.NewVarFileAllowlistChecker(userConfig.VarFileAllowlist) if err != nil { return nil, err @@ -837,7 +843,8 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { PreWorkflowHooksCommandRunner: preWorkflowHooksCommandRunner, PostWorkflowHooksCommandRunner: postWorkflowHooksCommandRunner, PullStatusFetcher: backend, - TeamAllowlistChecker: githubTeamAllowlistChecker, + GitHubTeamAllowlistChecker: githubTeamAllowlistChecker, + GitLabGroupAllowlistChecker: gitlabGroupAllowlistChecker, VarFileAllowlistChecker: varFileAllowlistChecker, CommitStatusUpdater: commitStatusUpdater, } diff --git a/server/user_config.go b/server/user_config.go index 91ed090ac6..7e73748bb2 100644 --- a/server/user_config.go +++ b/server/user_config.go @@ -65,6 +65,7 @@ type UserConfig struct { GiteaWebhookSecret string `mapstructure:"gitea-webhook-secret"` GiteaPageSize int `mapstructure:"gitea-page-size"` GitlabHostname string `mapstructure:"gitlab-hostname"` + GitlabGroupAllowlist string `mapstructure:"gitlab-group-allowlist"` GitlabToken string `mapstructure:"gitlab-token"` GitlabUser string `mapstructure:"gitlab-user"` GitlabWebhookSecret string `mapstructure:"gitlab-webhook-secret"`