Skip to content

Commit

Permalink
use constants instead of hardcoded values
Browse files Browse the repository at this point in the history
Signed-off-by: davidwin93 <[email protected]>
  • Loading branch information
davidwin93 committed Oct 24, 2023
1 parent cb5681c commit b2892d0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/comment_formatter/tfc_status_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func FormatRunStatusCommentBody(tfc tfc_api.ApiClient, run *tfe.Run, rmd runstre
case tfe.RunDiscarded:
// no extra info
case tfe.RunErrored:
if rmd.GetAction() == "plan" {
if rmd.GetAction() == runstream.PlanAction {
extraInfo += failedPlanSummaryFormat
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/runstream/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package runstream

const (
ApplyAction string = "apply"
PlanAction string = "plan"
)
2 changes: 1 addition & 1 deletion pkg/vcs/github/run_events_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (w *RunEventsWorker) postRunStatusComment(ctx context.Context, run *tfe.Run
if len(run.TargetAddrs) > 0 {
return
}
if rmd.GetAction() == "apply" {
if rmd.GetAction() == runstream.ApplyAction {
w.mergePRIfPossible(ctx, rmd)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/vcs/gitlab/mr_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (p *RunStatusUpdater) updateCommitStatusForRun(ctx context.Context, run *tf
// https://www.terraform.io/cloud-docs/api-docs/run#run-states
case tfe.RunPending:
// The initial status of a run once it has been created.
if rmd.GetAction() == "plan" {
if rmd.GetAction() == runstream.PlanAction {
p.updateStatus(ctx, gogitlab.Pending, "plan", rmd)
p.updateStatus(ctx, gogitlab.Failed, "apply", rmd)
} else {
Expand Down Expand Up @@ -79,7 +79,7 @@ func (p *RunStatusUpdater) updateCommitStatusForRun(ctx context.Context, run *tf
p.updateStatus(ctx, gogitlab.Pending, "apply", rmd)
} else {
// if the apply returns no changes we can still go ahead and merge if auto-merge is enabled
if len(run.TargetAddrs) == 0 && rmd.GetAction() == "apply" {
if len(run.TargetAddrs) == 0 && rmd.GetAction() == runstream.ApplyAction {
p.mergeMRIfPossible(ctx, rmd)
}
}
Expand Down

0 comments on commit b2892d0

Please sign in to comment.