Skip to content

Commit

Permalink
feat: add hide-unchanged-plan-comments option
Browse files Browse the repository at this point in the history
  • Loading branch information
tufitko committed Feb 24, 2023
1 parent c960b4d commit c370acc
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 42 deletions.
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`
```bash
atlantis server --hide-unchanged-plan-comments
# 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

0 comments on commit c370acc

Please sign in to comment.