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 }