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

Add flag for disabling markdown formatting #960

Merged
merged 2 commits into from
Mar 29, 2020
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
5 changes: 5 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
DataDirFlag = "data-dir"
DefaultTFVersionFlag = "default-tf-version"
DisableApplyAllFlag = "disable-apply-all"
DisableMarkdownFoldingFlag = "disable-markdown-folding"
GHHostnameFlag = "gh-hostname"
GHTokenFlag = "gh-token"
GHUserFlag = "gh-user"
Expand Down Expand Up @@ -273,6 +274,10 @@ var boolFlags = map[string]boolFlag{
description: "Silences the posting of whitelist error comments.",
defaultValue: false,
},
DisableMarkdownFoldingFlag: {
description: "Toggle off folding in markdown 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.",
Expand Down
1 change: 1 addition & 0 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var testFlags = map[string]interface{}{
DataDirFlag: "/path",
DefaultTFVersionFlag: "v0.11.0",
DisableApplyAllFlag: true,
DisableMarkdownFoldingFlag: true,
GHHostnameFlag: "ghhostname",
GHTokenFlag: "token",
GHUserFlag: "user",
Expand Down
5 changes: 5 additions & 0 deletions server/events/markdown_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type MarkdownRenderer struct {
// If we're not configured with a GitLab client, this will be false.
GitlabSupportsCommonMark bool
DisableApplyAll bool
DisableMarkdownFolding bool
}

// commonData is data that all responses have.
Expand Down Expand Up @@ -172,6 +173,10 @@ func (m *MarkdownRenderer) renderProjectResults(results []models.ProjectResult,
// load. Some VCS providers or versions of VCS providers don't support this
// syntax.
func (m *MarkdownRenderer) shouldUseWrappedTmpl(vcsHost models.VCSHostType, output string) bool {
if m.DisableMarkdownFolding {
return false
}

// Bitbucket Cloud and Server don't support the folding markdown syntax.
if vcsHost == models.BitbucketServer || vcsHost == models.BitbucketCloud {
return false
Expand Down
18 changes: 18 additions & 0 deletions server/events/markdown_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,24 @@ $$$
}
}

// Test that if folding is disabled that it's not used.
func TestRenderProjectResults_DisableFolding(t *testing.T) {
mr := events.MarkdownRenderer{
DisableMarkdownFolding: true,
}

rendered := mr.Render(events.CommandResult{
ProjectResults: []models.ProjectResult{
{
RepoRelDir: ".",
Workspace: "default",
Error: errors.New(strings.Repeat("line\n", 13)),
},
},
}, models.PlanCommand, "log", false, models.Github)
Equals(t, false, strings.Contains(rendered, "<details>"))
}

// Test that if the output is longer than 12 lines, it gets wrapped on the right
// VCS hosts during an error.
func TestRenderProjectResults_WrappedErr(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
markdownRenderer := &events.MarkdownRenderer{
GitlabSupportsCommonMark: gitlabClient.SupportsCommonMark(),
DisableApplyAll: userConfig.DisableApplyAll,
DisableMarkdownFolding: userConfig.DisableMarkdownFolding,
}

boltdb, err := db.New(userConfig.DataDir)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions server/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type UserConfig struct {
CheckoutStrategy string `mapstructure:"checkout-strategy"`
DataDir string `mapstructure:"data-dir"`
DisableApplyAll bool `mapstructure:"disable-apply-all"`
DisableMarkdownFolding bool `mapstructure:"disable-markdown-folding"`
GithubHostname string `mapstructure:"gh-hostname"`
GithubToken string `mapstructure:"gh-token"`
GithubUser string `mapstructure:"gh-user"`
Expand Down