/
deployment.go
72 lines (63 loc) · 1.4 KB
/
deployment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package common
import (
"fmt"
"github.com/google/go-github/github"
"github.com/satori/go.uuid"
)
type DeploymentState int
const (
DEPLOYMENT_PENDING DeploymentState = iota
RUNNING_PRECONDITIONS
RUNNING_PHASE
DEPLOYMENT_DONE
DEPLOYMENT_ERROR
)
func (state DeploymentState) String() string {
switch state {
case DEPLOYMENT_PENDING:
return "DEPLOYMENT_PENDING"
case RUNNING_PRECONDITIONS:
return "RUNNING_PRECONDITIONS"
case RUNNING_PHASE:
return "RUNNING_PHASE"
case DEPLOYMENT_DONE:
return "DEPLOYMENT_DONE"
case DEPLOYMENT_ERROR:
return "DEPLOYMENT_ERROR"
default:
return "UNKNOWN"
}
}
type DeploymentStatus struct {
State DeploymentState
Phase Phase
Error error
}
type Deployment interface {
UUID() uuid.UUID
Application() Application
Environment() string
Strategy() Strategy
GithubClient() (*github.Client, error)
Ref() string
SHA1() string
SetSHA1(string)
// Return the SHA1 if known, otherwise the ref
MostPreciseRef() string
// Users can tweak the operation of the deploy via flags, eg. a "force"
// flag to skip some checks.
Flags() map[string]interface{}
HasFlag(string) bool
Flag(string) interface{}
SetFlag(string, interface{})
IsForce() bool
Status() DeploymentStatus
}
func HumanDescriptionOfDeployment(deployment Deployment) string {
return fmt.Sprintf(
"%s to %s for %s",
deployment.Ref(),
deployment.Environment(),
deployment.Application().Name(),
)
}