From b5018de897cfe48c9c2b0ce44c35220c58bef267 Mon Sep 17 00:00:00 2001 From: Aayush Gupta <43479002+Aayyush@users.noreply.github.com> Date: Mon, 27 Sep 2021 14:28:17 -0700 Subject: [PATCH] Adding approval metadata to project command context [Pulling from upstream] (#116) * Pulling [#1827-Updating client interface and adding ApprovalStatus model] from master * Fix failing test --- .../events/events_controller_e2e_test.go | 4 ++- server/events/apply_requirement_handler.go | 2 +- server/events/models/models.go | 18 ++++++---- .../mocks/matchers/models_approvalstatus.go | 33 +++++++++++++++++++ server/events/vcs/azuredevops_client.go | 10 +++--- server/events/vcs/azuredevops_client_test.go | 4 +-- server/events/vcs/bitbucketcloud/client.go | 14 ++++---- .../events/vcs/bitbucketcloud/client_test.go | 4 +-- server/events/vcs/bitbucketserver/client.go | 16 +++++---- server/events/vcs/client.go | 2 +- server/events/vcs/github_client.go | 12 ++++--- server/events/vcs/github_client_test.go | 19 ++++++++--- server/events/vcs/gitlab_client.go | 10 +++--- server/events/vcs/instrumented_client.go | 6 ++-- .../mocks/matchers/models_approvalstatus.go | 33 +++++++++++++++++++ .../events/vcs/mocks/mock_IGithub_client.go | 8 ++--- server/events/vcs/mocks/mock_client.go | 8 ++--- .../events/vcs/not_configured_vcs_client.go | 4 +-- server/events/vcs/proxy.go | 2 +- .../audit_project_commands_wrapper_test.go | 4 ++- 20 files changed, 156 insertions(+), 57 deletions(-) create mode 100644 server/events/runtime/mocks/matchers/models_approvalstatus.go create mode 100644 server/events/vcs/mocks/matchers/models_approvalstatus.go diff --git a/server/controllers/events/events_controller_e2e_test.go b/server/controllers/events/events_controller_e2e_test.go index 4cd3cb061..1c17affa9 100644 --- a/server/controllers/events/events_controller_e2e_test.go +++ b/server/controllers/events/events_controller_e2e_test.go @@ -591,7 +591,9 @@ func TestGitHubWorkflowWithPolicyCheck(t *testing.T) { // Setup test dependencies. w := httptest.NewRecorder() When(githubClient.PullIsSQMergeable(AnyRepo(), matchers.AnyModelsPullRequest(), AnyStatus())).ThenReturn(true, nil) - When(githubClient.PullIsApproved(AnyRepo(), matchers.AnyModelsPullRequest())).ThenReturn(true, nil) + When(githubClient.PullIsApproved(AnyRepo(), matchers.AnyModelsPullRequest())).ThenReturn(models.ApprovalStatus{ + IsApproved: true, + }, nil) When(githubGetter.GetPullRequest(AnyRepo(), AnyInt())).ThenReturn(GitHubPullRequestParsed(headSHA), nil) When(vcsClient.GetModifiedFiles(AnyRepo(), matchers.AnyModelsPullRequest())).ThenReturn(c.ModifiedFiles, nil) diff --git a/server/events/apply_requirement_handler.go b/server/events/apply_requirement_handler.go index 13963bc72..d24794e6c 100644 --- a/server/events/apply_requirement_handler.go +++ b/server/events/apply_requirement_handler.go @@ -19,7 +19,7 @@ func (a *AggregateApplyRequirements) ValidateProject(repoDir string, ctx models. for _, req := range ctx.ApplyRequirements { switch req { case raw.ApprovedApplyRequirement: - if !ctx.PullReqStatus.Approved { + if !ctx.PullReqStatus.Approved.IsApproved { return "Pull request must be approved by at least one person other than the author before running apply.", nil } // this should come before mergeability check since mergeability is a superset of this check. diff --git a/server/events/models/models.go b/server/events/models/models.go index 8e41e1e5e..9dd894b54 100644 --- a/server/events/models/models.go +++ b/server/events/models/models.go @@ -38,12 +38,6 @@ const ( LogStreamingClearMsg = "\n-----Starting New Process-----" ) -type PullReqStatus struct { - Approved bool - Mergeable bool - SQLocked bool -} - // Repo is a VCS repository. type Repo struct { // FullName is the owner and repo name separated @@ -151,6 +145,18 @@ func NewRepo(vcsHostType VCSHostType, repoFullName string, cloneURL string, vcsU }, nil } +type PullReqStatus struct { + Approved ApprovalStatus + Mergeable bool + SQLocked bool +} + +type ApprovalStatus struct { + IsApproved bool + ApprovedBy string + Date time.Time +} + // PullRequest is a VCS pull request. // GitLab calls these Merge Requests. type PullRequest struct { diff --git a/server/events/runtime/mocks/matchers/models_approvalstatus.go b/server/events/runtime/mocks/matchers/models_approvalstatus.go new file mode 100644 index 000000000..01b76dd96 --- /dev/null +++ b/server/events/runtime/mocks/matchers/models_approvalstatus.go @@ -0,0 +1,33 @@ +// Code generated by pegomock. DO NOT EDIT. +package matchers + +import ( + "github.com/petergtz/pegomock" + "reflect" + + models "github.com/runatlantis/atlantis/server/events/models" +) + +func AnyModelsApprovalStatus() models.ApprovalStatus { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.ApprovalStatus))(nil)).Elem())) + var nullValue models.ApprovalStatus + return nullValue +} + +func EqModelsApprovalStatus(value models.ApprovalStatus) models.ApprovalStatus { + pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) + var nullValue models.ApprovalStatus + return nullValue +} + +func NotEqModelsApprovalStatus(value models.ApprovalStatus) models.ApprovalStatus { + pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) + var nullValue models.ApprovalStatus + return nullValue +} + +func ModelsApprovalStatusThat(matcher pegomock.ArgumentMatcher) models.ApprovalStatus { + pegomock.RegisterMatcher(matcher) + var nullValue models.ApprovalStatus + return nullValue +} diff --git a/server/events/vcs/azuredevops_client.go b/server/events/vcs/azuredevops_client.go index 2989544ab..2369048b4 100644 --- a/server/events/vcs/azuredevops_client.go +++ b/server/events/vcs/azuredevops_client.go @@ -136,7 +136,7 @@ func (g *AzureDevopsClient) HidePrevCommandComments(repo models.Repo, pullNum in // PullIsApproved returns true if the merge request was approved by another reviewer. // https://docs.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops#require-a-minimum-number-of-reviewers -func (g *AzureDevopsClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) { +func (g *AzureDevopsClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (approvalStatus models.ApprovalStatus, err error) { owner, project, repoName := SplitAzureDevopsRepoFullName(repo.FullName) opts := azuredevops.PullRequestGetOptions{ @@ -144,7 +144,7 @@ func (g *AzureDevopsClient) PullIsApproved(repo models.Repo, pull models.PullReq } adPull, _, err := g.Client.PullRequests.GetWithRepo(g.ctx, owner, project, repoName, pull.Num, &opts) if err != nil { - return false, errors.Wrap(err, "getting pull request") + return approvalStatus, errors.Wrap(err, "getting pull request") } for _, review := range adPull.Reviewers { @@ -157,11 +157,13 @@ func (g *AzureDevopsClient) PullIsApproved(repo models.Repo, pull models.PullReq } if review.GetVote() == azuredevops.VoteApproved || review.GetVote() == azuredevops.VoteApprovedWithSuggestions { - return true, nil + return models.ApprovalStatus{ + IsApproved: true, + }, nil } } - return false, nil + return approvalStatus, nil } // PullIsMergeable returns true if the merge request can be merged. diff --git a/server/events/vcs/azuredevops_client_test.go b/server/events/vcs/azuredevops_client_test.go index 0b30a7752..d7c40ee6c 100644 --- a/server/events/vcs/azuredevops_client_test.go +++ b/server/events/vcs/azuredevops_client_test.go @@ -495,7 +495,7 @@ func TestAzureDevopsClient_PullIsApproved(t *testing.T) { defer disableSSLVerification()() - actApproved, err := client.PullIsApproved(models.Repo{ + approvalStatus, err := client.PullIsApproved(models.Repo{ FullName: "owner/project/repo", Owner: "owner", Name: "repo", @@ -509,7 +509,7 @@ func TestAzureDevopsClient_PullIsApproved(t *testing.T) { Num: 1, }) Ok(t, err) - Equals(t, c.expApproved, actApproved) + Equals(t, c.expApproved, approvalStatus.IsApproved) }) } } diff --git a/server/events/vcs/bitbucketcloud/client.go b/server/events/vcs/bitbucketcloud/client.go index 9ba1ca41e..979fcdc56 100644 --- a/server/events/vcs/bitbucketcloud/client.go +++ b/server/events/vcs/bitbucketcloud/client.go @@ -105,28 +105,30 @@ func (b *Client) HidePrevCommandComments(repo models.Repo, pullNum int, command } // PullIsApproved returns true if the merge request was approved. -func (b *Client) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) { +func (b *Client) PullIsApproved(repo models.Repo, pull models.PullRequest) (approvalStatus models.ApprovalStatus, err error) { path := fmt.Sprintf("%s/2.0/repositories/%s/pullrequests/%d", b.BaseURL, repo.FullName, pull.Num) resp, err := b.makeRequest("GET", path, nil) if err != nil { - return false, err + return approvalStatus, err } var pullResp PullRequest if err := json.Unmarshal(resp, &pullResp); err != nil { - return false, errors.Wrapf(err, "Could not parse response %q", string(resp)) + return approvalStatus, errors.Wrapf(err, "Could not parse response %q", string(resp)) } if err := validator.New().Struct(pullResp); err != nil { - return false, errors.Wrapf(err, "API response %q was missing fields", string(resp)) + return approvalStatus, errors.Wrapf(err, "API response %q was missing fields", string(resp)) } authorUUID := *pullResp.Author.UUID for _, participant := range pullResp.Participants { // Bitbucket allows the author to approve their own pull request. This // defeats the purpose of approvals so we don't count that approval. if *participant.Approved && *participant.User.UUID != authorUUID { - return true, nil + return models.ApprovalStatus{ + IsApproved: true, + }, nil } } - return false, nil + return approvalStatus, nil } // PullIsMergeable returns true if the merge request has no conflicts and can be merged. diff --git a/server/events/vcs/bitbucketcloud/client_test.go b/server/events/vcs/bitbucketcloud/client_test.go index 0575e9e8e..b14c54894 100644 --- a/server/events/vcs/bitbucketcloud/client_test.go +++ b/server/events/vcs/bitbucketcloud/client_test.go @@ -202,14 +202,14 @@ func TestClient_PullIsApproved(t *testing.T) { repo, err := models.NewRepo(models.BitbucketServer, "owner/repo", "https://bitbucket.org/owner/repo.git", "user", "token") Ok(t, err) - approved, err := client.PullIsApproved(repo, models.PullRequest{ + approvalStatus, err := client.PullIsApproved(repo, models.PullRequest{ Num: 1, HeadBranch: "branch", Author: "author", BaseRepo: repo, }) Ok(t, err) - Equals(t, c.exp, approved) + Equals(t, c.exp, approvalStatus.IsApproved) }) } } diff --git a/server/events/vcs/bitbucketserver/client.go b/server/events/vcs/bitbucketserver/client.go index 27af85354..fa23c3d07 100644 --- a/server/events/vcs/bitbucketserver/client.go +++ b/server/events/vcs/bitbucketserver/client.go @@ -161,29 +161,31 @@ func (b *Client) postComment(repo models.Repo, pullNum int, comment string) erro } // PullIsApproved returns true if the merge request was approved. -func (b *Client) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) { +func (b *Client) PullIsApproved(repo models.Repo, pull models.PullRequest) (approvalStatus models.ApprovalStatus, err error) { projectKey, err := b.GetProjectKey(repo.Name, repo.SanitizedCloneURL) if err != nil { - return false, err + return approvalStatus, err } path := fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos/%s/pull-requests/%d", b.BaseURL, projectKey, repo.Name, pull.Num) resp, err := b.makeRequest("GET", path, nil) if err != nil { - return false, err + return approvalStatus, err } var pullResp PullRequest if err := json.Unmarshal(resp, &pullResp); err != nil { - return false, errors.Wrapf(err, "Could not parse response %q", string(resp)) + return approvalStatus, errors.Wrapf(err, "Could not parse response %q", string(resp)) } if err := validator.New().Struct(pullResp); err != nil { - return false, errors.Wrapf(err, "API response %q was missing fields", string(resp)) + return approvalStatus, errors.Wrapf(err, "API response %q was missing fields", string(resp)) } for _, reviewer := range pullResp.Reviewers { if *reviewer.Approved { - return true, nil + return models.ApprovalStatus{ + IsApproved: true, + }, nil } } - return false, nil + return approvalStatus, nil } // PullIsMergeable returns true if the merge request has no conflicts and can be merged. diff --git a/server/events/vcs/client.go b/server/events/vcs/client.go index 0f49cc89d..711e55820 100644 --- a/server/events/vcs/client.go +++ b/server/events/vcs/client.go @@ -26,7 +26,7 @@ type Client interface { GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error) CreateComment(repo models.Repo, pullNum int, comment string, command string) error HidePrevCommandComments(repo models.Repo, pullNum int, command string) error - PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) + PullIsApproved(repo models.Repo, pull models.PullRequest) (models.ApprovalStatus, error) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error) // UpdateStatus updates the commit status to state for pull. src is the // source of this status. This should be relatively static across runs, diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 330a76d99..34b89d91b 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -254,7 +254,7 @@ func (g *GithubClient) HidePrevCommandComments(repo models.Repo, pullNum int, co } // PullIsApproved returns true if the pull request was approved. -func (g *GithubClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) { +func (g *GithubClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (approvalStatus models.ApprovalStatus, err error) { nextPage := 0 for { opts := github.ListOptions{ @@ -266,11 +266,15 @@ func (g *GithubClient) PullIsApproved(repo models.Repo, pull models.PullRequest) g.logger.Debug("GET /repos/%v/%v/pulls/%d/reviews", repo.Owner, repo.Name, pull.Num) pageReviews, resp, err := g.client.PullRequests.ListReviews(g.ctx, repo.Owner, repo.Name, pull.Num, &opts) if err != nil { - return false, errors.Wrap(err, "getting reviews") + return approvalStatus, errors.Wrap(err, "getting reviews") } for _, review := range pageReviews { if review != nil && review.GetState() == "APPROVED" { - return true, nil + return models.ApprovalStatus{ + IsApproved: true, + ApprovedBy: *review.User.Login, + Date: *review.SubmittedAt, + }, nil } } if resp.NextPage == 0 { @@ -278,7 +282,7 @@ func (g *GithubClient) PullIsApproved(repo models.Repo, pull models.PullRequest) } nextPage = resp.NextPage } - return false, nil + return approvalStatus, nil } // PullIsMergeable returns true if the pull request is mergeable. diff --git a/server/events/vcs/github_client_test.go b/server/events/vcs/github_client_test.go index 02a1a0190..02ddcd6c8 100644 --- a/server/events/vcs/github_client_test.go +++ b/server/events/vcs/github_client_test.go @@ -10,6 +10,7 @@ import ( "net/url" "strings" "testing" + "time" "github.com/google/go-github/v31/github" "github.com/runatlantis/atlantis/server/events/models" @@ -415,7 +416,7 @@ func TestGithubClient_PullIsApproved(t *testing.T) { }, "body": "Here is the body for the review.", "commit_id": "ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091", - "state": "CHANGES_REQUESTED", + "state": "APPROVED", "html_url": "https://github.com/octocat/Hello-World/pull/12#pullrequestreview-%d", "pull_request_url": "https://api.github.com/repos/octocat/Hello-World/pulls/12", "_links": { @@ -425,7 +426,8 @@ func TestGithubClient_PullIsApproved(t *testing.T) { "pull_request": { "href": "https://api.github.com/repos/octocat/Hello-World/pulls/12" } - } + }, + "submitted_at": "2019-11-17T17:43:43Z" } ]` firstResp := fmt.Sprintf(respTemplate, 80, 80, 80) @@ -456,7 +458,7 @@ func TestGithubClient_PullIsApproved(t *testing.T) { Ok(t, err) defer disableSSLVerification()() - approved, err := client.PullIsApproved(models.Repo{ + approvalStatus, err := client.PullIsApproved(models.Repo{ FullName: "owner/repo", Owner: "owner", Name: "repo", @@ -470,7 +472,16 @@ func TestGithubClient_PullIsApproved(t *testing.T) { Num: 1, }) Ok(t, err) - Equals(t, false, approved) + + timeOfApproval, err := time.Parse("2006-01-02T15:04:05Z", "2019-11-17T17:43:43Z") + Ok(t, err) + + expApprovalStatus := models.ApprovalStatus{ + IsApproved: true, + ApprovedBy: "octocat", + Date: timeOfApproval, + } + Equals(t, expApprovalStatus, approvalStatus) } func TestGithubClient_PullIsMergeable(t *testing.T) { diff --git a/server/events/vcs/gitlab_client.go b/server/events/vcs/gitlab_client.go index dffab011a..e3acdbe1a 100644 --- a/server/events/vcs/gitlab_client.go +++ b/server/events/vcs/gitlab_client.go @@ -153,15 +153,17 @@ func (g *GitlabClient) HidePrevCommandComments(repo models.Repo, pullNum int, co } // PullIsApproved returns true if the merge request was approved. -func (g *GitlabClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) { +func (g *GitlabClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (approvalStatus models.ApprovalStatus, err error) { approvals, _, err := g.Client.MergeRequests.GetMergeRequestApprovals(repo.FullName, pull.Num) if err != nil { - return false, err + return approvalStatus, err } if approvals.ApprovalsLeft > 0 { - return false, nil + return approvalStatus, nil } - return true, nil + return models.ApprovalStatus{ + IsApproved: true, + }, nil } // PullIsMergeable returns true if the merge request can be merged. diff --git a/server/events/vcs/instrumented_client.go b/server/events/vcs/instrumented_client.go index d61b2ecd9..d0441624c 100644 --- a/server/events/vcs/instrumented_client.go +++ b/server/events/vcs/instrumented_client.go @@ -251,7 +251,7 @@ func (c *InstrumentedClient) HidePrevCommandComments(repo models.Repo, pullNum i return nil } -func (c *InstrumentedClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) { +func (c *InstrumentedClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (models.ApprovalStatus, error) { scope := c.StatsScope.Scope("pull_is_approved") logger := c.Logger.WithHistory(fmtLogSrc(repo, pull.Num)...) @@ -261,7 +261,7 @@ func (c *InstrumentedClient) PullIsApproved(repo models.Repo, pull models.PullRe executionSuccess := scope.NewCounter(metrics.ExecutionSuccessMetric) executionError := scope.NewCounter(metrics.ExecutionErrorMetric) - approved, err := c.Client.PullIsApproved(repo, pull) + approvalStatus, err := c.Client.PullIsApproved(repo, pull) if err != nil { executionError.Inc() @@ -270,7 +270,7 @@ func (c *InstrumentedClient) PullIsApproved(repo models.Repo, pull models.PullRe executionSuccess.Inc() } - return approved, err + return approvalStatus, err } func (c *InstrumentedClient) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error) { diff --git a/server/events/vcs/mocks/matchers/models_approvalstatus.go b/server/events/vcs/mocks/matchers/models_approvalstatus.go new file mode 100644 index 000000000..01b76dd96 --- /dev/null +++ b/server/events/vcs/mocks/matchers/models_approvalstatus.go @@ -0,0 +1,33 @@ +// Code generated by pegomock. DO NOT EDIT. +package matchers + +import ( + "github.com/petergtz/pegomock" + "reflect" + + models "github.com/runatlantis/atlantis/server/events/models" +) + +func AnyModelsApprovalStatus() models.ApprovalStatus { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.ApprovalStatus))(nil)).Elem())) + var nullValue models.ApprovalStatus + return nullValue +} + +func EqModelsApprovalStatus(value models.ApprovalStatus) models.ApprovalStatus { + pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) + var nullValue models.ApprovalStatus + return nullValue +} + +func NotEqModelsApprovalStatus(value models.ApprovalStatus) models.ApprovalStatus { + pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) + var nullValue models.ApprovalStatus + return nullValue +} + +func ModelsApprovalStatusThat(matcher pegomock.ArgumentMatcher) models.ApprovalStatus { + pegomock.RegisterMatcher(matcher) + var nullValue models.ApprovalStatus + return nullValue +} diff --git a/server/events/vcs/mocks/mock_IGithub_client.go b/server/events/vcs/mocks/mock_IGithub_client.go index cc891194b..1a153d842 100644 --- a/server/events/vcs/mocks/mock_IGithub_client.go +++ b/server/events/vcs/mocks/mock_IGithub_client.go @@ -208,17 +208,17 @@ func (mock *MockIGithubClient) MergePull(_param0 models.PullRequest, _param1 mod return ret0 } -func (mock *MockIGithubClient) PullIsApproved(_param0 models.Repo, _param1 models.PullRequest) (bool, error) { +func (mock *MockIGithubClient) PullIsApproved(_param0 models.Repo, _param1 models.PullRequest) (models.ApprovalStatus, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockIGithubClient().") } params := []pegomock.Param{_param0, _param1} - result := pegomock.GetGenericMockFrom(mock).Invoke("PullIsApproved", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool + 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].(bool) + ret0 = result[0].(models.ApprovalStatus) } if result[1] != nil { ret1 = result[1].(error) diff --git a/server/events/vcs/mocks/mock_client.go b/server/events/vcs/mocks/mock_client.go index a34218fcf..38123421b 100644 --- a/server/events/vcs/mocks/mock_client.go +++ b/server/events/vcs/mocks/mock_client.go @@ -131,17 +131,17 @@ func (mock *MockClient) MergePull(_param0 models.PullRequest, _param1 models.Pul return ret0 } -func (mock *MockClient) PullIsApproved(_param0 models.Repo, _param1 models.PullRequest) (bool, error) { +func (mock *MockClient) PullIsApproved(_param0 models.Repo, _param1 models.PullRequest) (models.ApprovalStatus, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } params := []pegomock.Param{_param0, _param1} - result := pegomock.GetGenericMockFrom(mock).Invoke("PullIsApproved", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool + 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].(bool) + ret0 = result[0].(models.ApprovalStatus) } if result[1] != nil { ret1 = result[1].(error) diff --git a/server/events/vcs/not_configured_vcs_client.go b/server/events/vcs/not_configured_vcs_client.go index 3f8556765..7780b1ef0 100644 --- a/server/events/vcs/not_configured_vcs_client.go +++ b/server/events/vcs/not_configured_vcs_client.go @@ -35,8 +35,8 @@ func (a *NotConfiguredVCSClient) CreateComment(repo models.Repo, pullNum int, co func (a *NotConfiguredVCSClient) HidePrevCommandComments(repo models.Repo, pullNum int, command string) error { return nil } -func (a *NotConfiguredVCSClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) { - return false, a.err() +func (a *NotConfiguredVCSClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (models.ApprovalStatus, error) { + return models.ApprovalStatus{}, a.err() } func (a *NotConfiguredVCSClient) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error) { return false, a.err() diff --git a/server/events/vcs/proxy.go b/server/events/vcs/proxy.go index c14563a46..5a9ed0313 100644 --- a/server/events/vcs/proxy.go +++ b/server/events/vcs/proxy.go @@ -64,7 +64,7 @@ func (d *ClientProxy) HidePrevCommandComments(repo models.Repo, pullNum int, com return d.clients[repo.VCSHost.Type].HidePrevCommandComments(repo, pullNum, command) } -func (d *ClientProxy) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) { +func (d *ClientProxy) PullIsApproved(repo models.Repo, pull models.PullRequest) (models.ApprovalStatus, error) { return d.clients[repo.VCSHost.Type].PullIsApproved(repo, pull) } diff --git a/server/lyft/decorators/audit_project_commands_wrapper_test.go b/server/lyft/decorators/audit_project_commands_wrapper_test.go index 57eb56835..c45caad3c 100644 --- a/server/lyft/decorators/audit_project_commands_wrapper_test.go +++ b/server/lyft/decorators/audit_project_commands_wrapper_test.go @@ -70,7 +70,9 @@ func TestAuditProjectCommandsWrapper(t *testing.T) { }, Workspace: "default", PullReqStatus: models.PullReqStatus{ - Approved: false, + Approved: models.ApprovalStatus{ + IsApproved: true, + }, }, RepoRelDir: ".", Tags: map[string]string{