Files
atlantis/server/github_status.go
2017-07-02 18:15:15 -07:00

65 lines
1.3 KiB
Go

package server
import (
"fmt"
"strings"
"github.com/hootsuite/atlantis/github"
"github.com/hootsuite/atlantis/models"
)
type Status int
const (
statusContext = "Atlantis"
Pending Status = iota
Success
Failure
Error
PlanStep = "plan"
ApplyStep = "apply"
)
type GithubStatus struct {
client *github.Client
}
func (s Status) String() string {
switch s {
case Pending:
return "pending"
case Success:
return "success"
case Failure:
return "failure"
case Error:
return "error"
}
return "error"
}
func (g *GithubStatus) Update(repo models.Repo, pull models.PullRequest, status Status, step string) error {
description := fmt.Sprintf("%s %s", strings.Title(step), strings.Title(status.String()))
return g.client.UpdateStatus(repo, pull, status.String(), description, statusContext)
}
func (g *GithubStatus) UpdatePathResult(ctx *CommandContext, pathResults []ProjectResult) error {
var statuses []Status
for _, p := range pathResults {
statuses = append(statuses, p.Status)
}
worst := g.worstStatus(statuses)
return g.Update(ctx.BaseRepo, ctx.Pull, worst, ctx.Command.commandType.String())
}
func (g *GithubStatus) worstStatus(ss []Status) Status {
worst := Success
for _, s := range ss {
if s > worst {
worst = s
}
}
return worst
}