diff --git a/server/events/command/project_context.go b/server/events/command/project_context.go index 139731d96d..f2d3a50b42 100644 --- a/server/events/command/project_context.go +++ b/server/events/command/project_context.go @@ -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 diff --git a/server/events/commit_status_updater.go b/server/events/commit_status_updater.go index dc8a07f239..ae69e76c5b 100644 --- a/server/events/commit_status_updater.go +++ b/server/events/commit_status_updater.go @@ -51,14 +51,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 { @@ -86,13 +85,19 @@ 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) } diff --git a/server/events/project_command_runner.go b/server/events/project_command_runner.go index 246fdae701..bbf570de2b 100644 --- a/server/events/project_command_runner.go +++ b/server/events/project_command_runner.go @@ -167,6 +167,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 {