Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[ORCA-559] Fix hide previous command logic (#37) #1549

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions server/events/markdown_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"github.com/runatlantis/atlantis/server/events/models"
)

const (
planCommandTitle = "Plan"
applyCommandTitle = "Apply"
policyCheckCommandTitle = "Policy Check"
approvePoliciesCommandTitle = "Approve Policies"
var (
planCommandTitle = models.PlanCommand.TitleString()
applyCommandTitle = models.ApplyCommand.TitleString()
policyCheckCommandTitle = models.PolicyCheckCommand.TitleString()
approvePoliciesCommandTitle = models.ApprovePoliciesCommand.TitleString()
// maxUnwrappedLines is the maximum number of lines the Terraform output
// can be before we wrap it in an expandable template.
maxUnwrappedLines = 12
Expand Down
6 changes: 6 additions & 0 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,12 @@ const (
// Adding more? Don't forget to update String() below
)

// TitleString returns the string representation in title form.
// ie. policy_check becomes Policy Check
func (c CommandName) TitleString() string {
return strings.Title(strings.ReplaceAll(strings.ToLower(c.String()), "_", " "))
}

// String returns the string representation of c.
func (c CommandName) String() string {
switch c {
Expand Down
4 changes: 2 additions & 2 deletions server/events/pull_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func (c *PullUpdater) updatePull(ctx *CommandContext, command PullCommand, res C
ctx.Log.Warn(res.Failure)
}

// HidePrevPlanComments will hide old comments left from previous plan runs to reduce
// HidePrevCommandComments will hide old comments left from previous runs to reduce
// clutter in a pull/merge request. This will not delete the comment, since the
// comment trail may be useful in auditing or backtracing problems.
if c.HidePrevPlanComments {
if err := c.VCSClient.HidePrevPlanComments(ctx.Pull.BaseRepo, ctx.Pull.Num); err != nil {
if err := c.VCSClient.HidePrevCommandComments(ctx.Pull.BaseRepo, ctx.Pull.Num, command.CommandName().TitleString()); err != nil {
ctx.Log.Err("unable to hide old comments: %s", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/events/vcs/azuredevops_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (g *AzureDevopsClient) CreateComment(repo models.Repo, pullNum int, comment
return nil
}

func (g *AzureDevopsClient) HidePrevPlanComments(repo models.Repo, pullNum int) error {
func (g *AzureDevopsClient) HidePrevCommandComments(repo models.Repo, pullNum int, command string) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion server/events/vcs/bitbucketcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (b *Client) CreateComment(repo models.Repo, pullNum int, comment string, co
return err
}

func (b *Client) HidePrevPlanComments(repo models.Repo, pullNum int) error {
func (b *Client) HidePrevCommandComments(repo models.Repo, pullNum int, command string) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion server/events/vcs/bitbucketserver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (b *Client) CreateComment(repo models.Repo, pullNum int, comment string, co
return nil
}

func (b *Client) HidePrevPlanComments(repo models.Repo, pullNum int) error {
func (b *Client) HidePrevCommandComments(repo models.Repo, pullNum int, command string) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion server/events/vcs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Client interface {
// relative to the repo root, e.g. parent/child/file.txt.
GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error)
CreateComment(repo models.Repo, pullNum int, comment string, command string) error
HidePrevPlanComments(repo models.Repo, pullNum int) error
HidePrevCommandComments(repo models.Repo, pullNum int, command string) error
PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error)
PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error)
// UpdateStatus updates the commit status to state for pull. src is the
Expand Down
4 changes: 2 additions & 2 deletions server/events/vcs/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (g *GithubClient) CreateComment(repo models.Repo, pullNum int, comment stri
return nil
}

func (g *GithubClient) HidePrevPlanComments(repo models.Repo, pullNum int) error {
func (g *GithubClient) HidePrevCommandComments(repo models.Repo, pullNum int, command string) error {
var allComments []*github.IssueComment
nextPage := 0
for {
Expand Down Expand Up @@ -205,7 +205,7 @@ func (g *GithubClient) HidePrevPlanComments(repo models.Repo, pullNum int) error
continue
}
firstLine := strings.ToLower(body[0])
if !strings.Contains(firstLine, models.PlanCommand.String()) {
if !strings.Contains(firstLine, strings.ToLower(command)) {
continue
}
var m struct {
Expand Down
6 changes: 4 additions & 2 deletions server/events/vcs/github_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestGithubClient_PaginatesComments(t *testing.T) {
Ok(t, err)
defer disableSSLVerification()()

err = client.HidePrevPlanComments(
err = client.HidePrevCommandComments(
models.Repo{
FullName: "owner/repo",
Owner: "owner",
Expand All @@ -227,6 +227,7 @@ func TestGithubClient_PaginatesComments(t *testing.T) {
},
},
123,
models.PlanCommand.TitleString(),
)
Ok(t, err)
Equals(t, 2, len(gotMinimizeCalls))
Expand Down Expand Up @@ -302,7 +303,7 @@ func TestGithubClient_HideOldComments(t *testing.T) {
Ok(t, err)
defer disableSSLVerification()()

err = client.HidePrevPlanComments(
err = client.HidePrevCommandComments(
models.Repo{
FullName: "owner/repo",
Owner: "owner",
Expand All @@ -315,6 +316,7 @@ func TestGithubClient_HideOldComments(t *testing.T) {
},
},
123,
models.PlanCommand.TitleString(),
)
Ok(t, err)
Equals(t, 3, len(gotMinimizeCalls))
Expand Down
2 changes: 1 addition & 1 deletion server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (g *GitlabClient) CreateComment(repo models.Repo, pullNum int, comment stri
return err
}

func (g *GitlabClient) HidePrevPlanComments(repo models.Repo, pullNum int) error {
func (g *GitlabClient) HidePrevCommandComments(repo models.Repo, pullNum int, command string) error {
return nil
}

Expand Down
28 changes: 16 additions & 12 deletions server/events/vcs/mocks/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/events/vcs/not_configured_vcs_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (a *NotConfiguredVCSClient) GetModifiedFiles(repo models.Repo, pull models.
func (a *NotConfiguredVCSClient) CreateComment(repo models.Repo, pullNum int, comment string, command string) error {
return a.err()
}
func (a *NotConfiguredVCSClient) HidePrevPlanComments(repo models.Repo, pullNum int) error {
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) {
Expand Down
4 changes: 2 additions & 2 deletions server/events/vcs/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (d *ClientProxy) CreateComment(repo models.Repo, pullNum int, comment strin
return d.clients[repo.VCSHost.Type].CreateComment(repo, pullNum, comment, command)
}

func (d *ClientProxy) HidePrevPlanComments(repo models.Repo, pullNum int) error {
return d.clients[repo.VCSHost.Type].HidePrevPlanComments(repo, pullNum)
func (d *ClientProxy) HidePrevCommandComments(repo models.Repo, pullNum int, command string) error {
return d.clients[repo.VCSHost.Type].HidePrevCommandComments(repo, pullNum, command)
}

func (d *ClientProxy) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) {
Expand Down