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

feat: add hide-unchanged-plan-comments option #3158

Merged
merged 2 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const (
EnableRegExpCmdFlag = "enable-regexp-cmd"
EnableDiffMarkdownFormat = "enable-diff-markdown-format"
ExecutableName = "executable-name"
HideUnchangedPlanComments = "hide-unchanged-plan-comments"
GHHostnameFlag = "gh-hostname"
GHTeamAllowlistFlag = "gh-team-allowlist"
GHTokenFlag = "gh-token"
Expand Down Expand Up @@ -531,6 +532,10 @@ var boolFlags = map[string]boolFlag{
description: "Enable websocket origin check",
defaultValue: false,
},
HideUnchangedPlanComments: {
description: "Remove no-changes plan comments from the pull request.",
defaultValue: false,
},
}
var intFlags = map[string]intFlag{
CheckoutDepthFlag: {
Expand Down
10 changes: 10 additions & 0 deletions runatlantis.io/docs/server-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,16 @@ and set `--autoplan-modules` to `false`.

This is useful when running multiple Atlantis servers against a single repository.

### `--hide-unchanged-plan-comments`
nitrocode marked this conversation as resolved.
Show resolved Hide resolved
```bash
atlantis server --hide-unchanged-plan-comments
nitrocode marked this conversation as resolved.
Show resolved Hide resolved
# or
ATLANTIS_HIDE_UNCHANGED_PLAN_COMMENTS=true
```
Remove no-changes plan comments from the pull request.

This is useful when you have many projects and want to keep the pull request clean from useless comments.

### `--gh-hostname`
```bash
atlantis server --gh-hostname="my.github.enterprise.com"
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
pullUpdater := &events.PullUpdater{
HidePrevPlanComments: false,
VCSClient: e2eVCSClient,
MarkdownRenderer: events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis"),
MarkdownRenderer: events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false),
}

autoMerger := &events.AutoMerger{
Expand Down
2 changes: 1 addition & 1 deletion server/events/command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func setup(t *testing.T, options ...func(testConfig *TestConfig)) *vcsmocks.Mock
pullUpdater = &events.PullUpdater{
HidePrevPlanComments: false,
VCSClient: vcsClient,
MarkdownRenderer: events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis"),
MarkdownRenderer: events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false),
}

autoMerger = &events.AutoMerger{
Expand Down
79 changes: 43 additions & 36 deletions server/events/markdown_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,30 @@ type MarkdownRenderer struct {
// gitlabSupportsCommonMark is true if the version of GitLab we're
// using supports the CommonMark markdown format.
// If we're not configured with a GitLab client, this will be false.
gitlabSupportsCommonMark bool
disableApplyAll bool
disableApply bool
disableMarkdownFolding bool
disableRepoLocking bool
enableDiffMarkdownFormat bool
markdownTemplates *template.Template
executableName string
gitlabSupportsCommonMark bool
disableApplyAll bool
disableApply bool
disableMarkdownFolding bool
disableRepoLocking bool
enableDiffMarkdownFormat bool
markdownTemplates *template.Template
executableName string
hideUnchangedPlanComments bool
}

// commonData is data that all responses have.
type commonData struct {
Command string
SubCommand string
Verbose bool
Log string
PlansDeleted bool
DisableApplyAll bool
DisableApply bool
DisableRepoLocking bool
EnableDiffMarkdownFormat bool
ExecutableName string
Command string
SubCommand string
Verbose bool
Log string
PlansDeleted bool
DisableApplyAll bool
DisableApply bool
DisableRepoLocking bool
EnableDiffMarkdownFormat bool
ExecutableName string
HideUnchangedPlanComments bool
}

// errData is data about an error response.
Expand Down Expand Up @@ -109,6 +111,7 @@ type projectResultTmplData struct {
RepoRelDir string
ProjectName string
Rendered string
NoChanges bool
}

// Initialize templates
Expand All @@ -121,6 +124,7 @@ func NewMarkdownRenderer(
enableDiffMarkdownFormat bool,
markdownTemplateOverridesDir string,
executableName string,
hideUnchangedPlanComments bool,
) *MarkdownRenderer {
var templates *template.Template
templates, _ = template.New("").Funcs(sprig.TxtFuncMap()).ParseFS(templatesFS, "templates/*.tmpl")
Expand All @@ -129,14 +133,15 @@ func NewMarkdownRenderer(
templates = overrides
}
return &MarkdownRenderer{
gitlabSupportsCommonMark: gitlabSupportsCommonMark,
disableApplyAll: disableApplyAll,
disableMarkdownFolding: disableMarkdownFolding,
disableApply: disableApply,
disableRepoLocking: disableRepoLocking,
enableDiffMarkdownFormat: enableDiffMarkdownFormat,
markdownTemplates: templates,
executableName: executableName,
gitlabSupportsCommonMark: gitlabSupportsCommonMark,
disableApplyAll: disableApplyAll,
disableMarkdownFolding: disableMarkdownFolding,
disableApply: disableApply,
disableRepoLocking: disableRepoLocking,
enableDiffMarkdownFormat: enableDiffMarkdownFormat,
markdownTemplates: templates,
executableName: executableName,
hideUnchangedPlanComments: hideUnchangedPlanComments,
}
}

Expand All @@ -145,16 +150,17 @@ func NewMarkdownRenderer(
func (m *MarkdownRenderer) Render(res command.Result, cmdName command.Name, subCmd, log string, verbose bool, vcsHost models.VCSHostType) string {
commandStr := cases.Title(language.English).String(strings.Replace(cmdName.String(), "_", " ", -1))
common := commonData{
Command: commandStr,
SubCommand: subCmd,
Verbose: verbose,
Log: log,
PlansDeleted: res.PlansDeleted,
DisableApplyAll: m.disableApplyAll || m.disableApply,
DisableApply: m.disableApply,
DisableRepoLocking: m.disableRepoLocking,
EnableDiffMarkdownFormat: m.enableDiffMarkdownFormat,
ExecutableName: m.executableName,
Command: commandStr,
SubCommand: subCmd,
Verbose: verbose,
Log: log,
PlansDeleted: res.PlansDeleted,
DisableApplyAll: m.disableApplyAll || m.disableApply,
DisableApply: m.disableApply,
DisableRepoLocking: m.disableRepoLocking,
EnableDiffMarkdownFormat: m.enableDiffMarkdownFormat,
ExecutableName: m.executableName,
HideUnchangedPlanComments: m.hideUnchangedPlanComments,
}

templates := m.markdownTemplates
Expand Down Expand Up @@ -197,6 +203,7 @@ func (m *MarkdownRenderer) renderProjectResults(results []command.ProjectResult,
} else {
resultData.Rendered = m.renderTemplateTrimSpace(templates.Lookup("planSuccessUnwrapped"), planSuccessData{PlanSuccess: *result.PlanSuccess, PlanWasDeleted: common.PlansDeleted, DisableApply: common.DisableApply, DisableRepoLocking: common.DisableRepoLocking, EnableDiffMarkdownFormat: common.EnableDiffMarkdownFormat})
}
resultData.NoChanges = result.PlanSuccess.NoChanges()
numPlanSuccesses++
} else if result.PolicyCheckSuccess != nil {
result.PolicyCheckSuccess.PolicyCheckOutput = strings.TrimSpace(result.PolicyCheckSuccess.PolicyCheckOutput)
Expand Down