From 2424d9a6dca365e3386debfa5b75c3e54951337a Mon Sep 17 00:00:00 2001 From: davidwin93 Date: Tue, 17 Oct 2023 09:40:10 -0600 Subject: [PATCH] refactor help text for MR comments Signed-off-by: davidwin93 --- pkg/comment_formatter/tfc_status_update.go | 31 ++++++++-------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/pkg/comment_formatter/tfc_status_update.go b/pkg/comment_formatter/tfc_status_update.go index 894081b..7c7dd9d 100644 --- a/pkg/comment_formatter/tfc_status_update.go +++ b/pkg/comment_formatter/tfc_status_update.go @@ -12,6 +12,13 @@ import ( "github.com/zapier/tfbuddy/pkg/vcs" ) +func getProperApplyText(rmd runstream.RunMetadata, wsName string) string { + if rmd.GetAutoMerge() && vcs.IsGlobalAutoMergeEnabled() { + return fmt.Sprintf(howToApplyFormatAutoMerge, wsName) + } else { + return fmt.Sprintf(howToApplyFormat, wsName) + } +} func FormatRunStatusCommentBody(tfc tfc_api.ApiClient, run *tfe.Run, rmd runstream.RunMetadata) (main, toplevel string, resolve bool) { wsName := run.Workspace.Name org := run.Workspace.Organization.Name @@ -33,11 +40,7 @@ func FormatRunStatusCommentBody(tfc tfc_api.ApiClient, run *tfe.Run, rmd runstre extraInfo = fmt.Sprintf(successPlanSummaryFormat, run.Apply.ResourceImports, run.Apply.ResourceAdditions, run.Apply.ResourceChanges, run.Apply.ResourceDestructions) if len(run.TargetAddrs) > 0 { extraInfo += needToApplyFullWorkSpace - if rmd.GetAutoMerge() && vcs.IsGlobalAutoMergeEnabled() { - extraInfo += fmt.Sprintf(howToApplyFormatAutoMerge, wsName) - } else { - extraInfo += fmt.Sprintf(howToApplyFormat, wsName) - } + extraInfo += getProperApplyText(rmd, wsName) } else { resolveDiscussion = true } @@ -59,11 +62,7 @@ func FormatRunStatusCommentBody(tfc tfc_api.ApiClient, run *tfe.Run, rmd runstre if len(run.TargetAddrs) > 0 { extraInfo += fmt.Sprintf(howToApplyFormatWithTarget, strings.Join(run.TargetAddrs, ","), wsName, strings.Join(run.TargetAddrs, ",")) } else { - if rmd.GetAutoMerge() && vcs.IsGlobalAutoMergeEnabled() { - extraInfo += fmt.Sprintf(howToApplyFormatAutoMerge, wsName) - } else { - extraInfo += fmt.Sprintf(howToApplyFormat, wsName) - } + extraInfo += getProperApplyText(rmd, wsName) } } case tfe.RunPlannedAndFinished: @@ -81,20 +80,12 @@ func FormatRunStatusCommentBody(tfc tfc_api.ApiClient, run *tfe.Run, rmd runstre if len(run.TargetAddrs) > 0 { extraInfo += fmt.Sprintf(howToApplyFormatWithTarget, strings.Join(run.TargetAddrs, ","), wsName, strings.Join(run.TargetAddrs, ",")) } else { - if rmd.GetAutoMerge() && vcs.IsGlobalAutoMergeEnabled() { - extraInfo += fmt.Sprintf(howToApplyFormatAutoMerge, wsName) - } else { - extraInfo += fmt.Sprintf(howToApplyFormat, wsName) - } + extraInfo += getProperApplyText(rmd, wsName) } } else { if len(run.TargetAddrs) > 0 { extraInfo += needToApplyFullWorkSpace - if rmd.GetAutoMerge() && vcs.IsGlobalAutoMergeEnabled() { - extraInfo += fmt.Sprintf(howToApplyFormatAutoMerge, wsName) - } else { - extraInfo += fmt.Sprintf(howToApplyFormat, wsName) - } + extraInfo += getProperApplyText(rmd, wsName) } else { resolveDiscussion = true }