From 62d3522d33a07b949a724c0db490ed2fb0eeb993 Mon Sep 17 00:00:00 2001 From: Mike Hume Date: Tue, 18 Feb 2020 01:43:39 -0800 Subject: [PATCH] Adding --fold-long-output flag to toggle wrapped default --- cmd/server.go | 89 ++++++++++++++++-------------- server/events/markdown_renderer.go | 5 ++ server/server.go | 2 + server/user_config.go | 1 + 4 files changed, 55 insertions(+), 42 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 5d97e56263..9211f9a577 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -36,48 +36,49 @@ import ( // 3. Add your flag's description etc. to the stringFlags, intFlags, or boolFlags slices. const ( // Flag names. - ADWebhookPasswordFlag = "azuredevops-webhook-password" // nolint: gosec - ADWebhookUserFlag = "azuredevops-webhook-user" - ADTokenFlag = "azuredevops-token" // nolint: gosec - ADUserFlag = "azuredevops-user" - AllowForkPRsFlag = "allow-fork-prs" - AllowRepoConfigFlag = "allow-repo-config" - AtlantisURLFlag = "atlantis-url" - AutomergeFlag = "automerge" - BitbucketBaseURLFlag = "bitbucket-base-url" - BitbucketTokenFlag = "bitbucket-token" - BitbucketUserFlag = "bitbucket-user" - BitbucketWebhookSecretFlag = "bitbucket-webhook-secret" - ConfigFlag = "config" - CheckoutStrategyFlag = "checkout-strategy" - DataDirFlag = "data-dir" - DefaultTFVersionFlag = "default-tf-version" - DisableApplyAllFlag = "disable-apply-all" - GHHostnameFlag = "gh-hostname" - GHTokenFlag = "gh-token" - GHUserFlag = "gh-user" - GHWebhookSecretFlag = "gh-webhook-secret" // nolint: gosec - GitlabHostnameFlag = "gitlab-hostname" - GitlabTokenFlag = "gitlab-token" - GitlabUserFlag = "gitlab-user" - GitlabWebhookSecretFlag = "gitlab-webhook-secret" // nolint: gosec - LogLevelFlag = "log-level" - PortFlag = "port" - RepoConfigFlag = "repo-config" - RepoConfigJSONFlag = "repo-config-json" - RepoWhitelistFlag = "repo-whitelist" - RequireApprovalFlag = "require-approval" - RequireMergeableFlag = "require-mergeable" - SilenceForkPRErrorsFlag = "silence-fork-pr-errors" - SilenceWhitelistErrorsFlag = "silence-whitelist-errors" - SlackTokenFlag = "slack-token" - SSLCertFileFlag = "ssl-cert-file" - SSLKeyFileFlag = "ssl-key-file" - TFDownloadURLFlag = "tf-download-url" - VCSStatusName = "vcs-status-name" - TFEHostnameFlag = "tfe-hostname" - TFETokenFlag = "tfe-token" - WriteGitCredsFlag = "write-git-creds" + ADWebhookPasswordFlag = "azuredevops-webhook-password" // nolint: gosec + ADWebhookUserFlag = "azuredevops-webhook-user" + ADTokenFlag = "azuredevops-token" // nolint: gosec + ADUserFlag = "azuredevops-user" + AllowForkPRsFlag = "allow-fork-prs" + AllowRepoConfigFlag = "allow-repo-config" + AtlantisURLFlag = "atlantis-url" + AutomergeFlag = "automerge" + BitbucketBaseURLFlag = "bitbucket-base-url" + BitbucketTokenFlag = "bitbucket-token" + BitbucketUserFlag = "bitbucket-user" + BitbucketWebhookSecretFlag = "bitbucket-webhook-secret" + ConfigFlag = "config" + CheckoutStrategyFlag = "checkout-strategy" + DataDirFlag = "data-dir" + DefaultTFVersionFlag = "default-tf-version" + DisableApplyAllFlag = "disable-apply-all" + DisableFoldingLongOutputFlag = "disable-folding-long-output" + GHHostnameFlag = "gh-hostname" + GHTokenFlag = "gh-token" + GHUserFlag = "gh-user" + GHWebhookSecretFlag = "gh-webhook-secret" // nolint: gosec + GitlabHostnameFlag = "gitlab-hostname" + GitlabTokenFlag = "gitlab-token" + GitlabUserFlag = "gitlab-user" + GitlabWebhookSecretFlag = "gitlab-webhook-secret" // nolint: gosec + LogLevelFlag = "log-level" + PortFlag = "port" + RepoConfigFlag = "repo-config" + RepoConfigJSONFlag = "repo-config-json" + RepoWhitelistFlag = "repo-whitelist" + RequireApprovalFlag = "require-approval" + RequireMergeableFlag = "require-mergeable" + SilenceForkPRErrorsFlag = "silence-fork-pr-errors" + SilenceWhitelistErrorsFlag = "silence-whitelist-errors" + SlackTokenFlag = "slack-token" + SSLCertFileFlag = "ssl-cert-file" + SSLKeyFileFlag = "ssl-key-file" + TFDownloadURLFlag = "tf-download-url" + VCSStatusName = "vcs-status-name" + TFEHostnameFlag = "tfe-hostname" + TFETokenFlag = "tfe-token" + WriteGitCredsFlag = "write-git-creds" // NOTE: Must manually set these as defaults in the setDefaults function. DefaultADBasicUser = "" @@ -268,6 +269,10 @@ var boolFlags = map[string]boolFlag{ description: "Silences the posting of whitelist error comments.", defaultValue: false, }, + DisableFoldingLongOutputFlag: { + description: "Toggle off folding atlantis output", + defaultValue: false, + }, WriteGitCredsFlag: { description: "Write out a .git-credentials file with the provider user and token to allow cloning private modules over HTTPS or SSH." + " This writes secrets to disk and should only be enabled in a secure environment.", diff --git a/server/events/markdown_renderer.go b/server/events/markdown_renderer.go index 6541868461..be9347b8d7 100644 --- a/server/events/markdown_renderer.go +++ b/server/events/markdown_renderer.go @@ -38,6 +38,7 @@ type MarkdownRenderer struct { // If we're not configured with a GitLab client, this will be false. GitlabSupportsCommonMark bool DisableApplyAll bool + DisableFoldingLongOutput bool } // commonData is data that all responses have. @@ -181,6 +182,10 @@ func (m *MarkdownRenderer) shouldUseWrappedTmpl(vcsHost models.VCSHostType, outp return false } + if m.DisableFoldingLongOutput { + return false + } + return strings.Count(output, "\n") > maxUnwrappedLines } diff --git a/server/server.go b/server/server.go index 7e49c55399..e2e330a9a6 100644 --- a/server/server.go +++ b/server/server.go @@ -231,7 +231,9 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { markdownRenderer := &events.MarkdownRenderer{ GitlabSupportsCommonMark: gitlabClient.SupportsCommonMark(), DisableApplyAll: userConfig.DisableApplyAll, + DisableFoldingLongOutput: userConfig.DisableFoldingLongOutput, } + boltdb, err := db.New(userConfig.DataDir) if err != nil { return nil, err diff --git a/server/user_config.go b/server/user_config.go index 5435078ea2..04c10e8ca9 100644 --- a/server/user_config.go +++ b/server/user_config.go @@ -21,6 +21,7 @@ type UserConfig struct { CheckoutStrategy string `mapstructure:"checkout-strategy"` DataDir string `mapstructure:"data-dir"` DisableApplyAll bool `mapstructure:"disable-apply-all"` + DisableFoldingLongOutput bool `mapstructure:"disable-folding-long-output"` GithubHostname string `mapstructure:"gh-hostname"` GithubToken string `mapstructure:"gh-token"` GithubUser string `mapstructure:"gh-user"`