Skip to content

Commit

Permalink
Merge pull request runatlantis#2699 from albertorm95/feat-change-plan…
Browse files Browse the repository at this point in the history
…-status

feat: PR check status to show summary e.g. `Plan: 1 to add, 0 to change, 1 to destroy`
  • Loading branch information
krrrr38 committed Jan 14, 2023
2 parents 33bc28f + d6d8977 commit e1103b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions server/events/command/project_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
// be executed for a project.
type ProjectContext struct {
CommandName Name
// CommandResult represent the Terraform outputs after the command execution.
CommandResult ProjectResult
// ApplyCmd is the command that users should run to apply this plan. If
// this is an apply then this will be empty.
ApplyCmd string
Expand Down
25 changes: 15 additions & 10 deletions server/events/commit_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ func (d *DefaultCommitStatusUpdater) UpdateCombined(repo models.Repo, pull model
var descripWords string
switch status {
case models.PendingCommitStatus:
descripWords = "in progress..."
descripWords = genProjectStatusDescription(cmdName.String(), "in progress...")
case models.FailedCommitStatus:
descripWords = "failed."
descripWords = genProjectStatusDescription(cmdName.String(), "failed.")
case models.SuccessCommitStatus:
descripWords = "succeeded."
descripWords = genProjectStatusDescription(cmdName.String(), "succeeded.")
}
descrip := fmt.Sprintf("%s %s", cases.Title(language.English).String(cmdName.String()), descripWords)
return d.Client.UpdateStatus(repo, pull, status, src, descrip, "")
return d.Client.UpdateStatus(repo, pull, status, src, descripWords, "")
}

func (d *DefaultCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName command.Name, numSuccess int, numTotal int) error {
Expand Down Expand Up @@ -89,15 +88,21 @@ func (d *DefaultCommitStatusUpdater) UpdateProject(ctx command.ProjectContext, c
var descripWords string
switch status {
case models.PendingCommitStatus:
descripWords = "in progress..."
descripWords = genProjectStatusDescription(cmdName.String(), "in progress...")
case models.FailedCommitStatus:
descripWords = "failed."
descripWords = genProjectStatusDescription(cmdName.String(), "failed.")
case models.SuccessCommitStatus:
descripWords = "succeeded."
if ctx.CommandResult.PlanSuccess != nil {
descripWords = ctx.CommandResult.PlanSuccess.Summary()
} else {
descripWords = genProjectStatusDescription(cmdName.String(), "succeeded.")
}
}
return d.Client.UpdateStatus(ctx.BaseRepo, ctx.Pull, status, src, descripWords, url)
}

descrip := fmt.Sprintf("%s %s", cases.Title(language.English).String(cmdName.String()), descripWords)
return d.Client.UpdateStatus(ctx.BaseRepo, ctx.Pull, status, src, descrip, url)
func genProjectStatusDescription(cmdName, description string) string {
return fmt.Sprintf("%s %s", cases.Title(language.English).String(cmdName), description)
}

func (d *DefaultCommitStatusUpdater) UpdatePreWorkflowHook(pull models.PullRequest, status models.CommitStatus, hookDescription string, runtimeDescription string, url string) error {
Expand Down
1 change: 1 addition & 0 deletions server/events/project_command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, c

// ensures we are differentiating between project level command and overall command
result := execute(ctx)
ctx.CommandResult = result

if result.Error != nil || result.Failure != "" {
if err := p.JobURLSetter.SetJobURLWithStatus(ctx, commandName, models.FailedCommitStatus); err != nil {
Expand Down

0 comments on commit e1103b6

Please sign in to comment.