Skip to content

Commit

Permalink
refactor help text for MR comments
Browse files Browse the repository at this point in the history
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
  • Loading branch information
davidwin93 committed Oct 17, 2023
1 parent 33d3d6d commit 2424d9a
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions pkg/comment_formatter/tfc_status_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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:
Expand All @@ -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
}
Expand Down

0 comments on commit 2424d9a

Please sign in to comment.