1package constants 2 3import ( 4 "fmt" 5 6 "github.com/pkg/errors" 7 "github.com/satori/go.uuid" 8) 9 10const ( 11 StatusIntact = 1 12 StatusDownstreamOnly = 2 13 StatusModified = 3 14 StatusUpstream = 4 15 StatusForked = 5 16) 17 18const ( 19 JobStatusNotStarted = "Not Started" 20 JobStatusRunning = "Running" 21 JobStatusFailed = "Failed" 22 JobStatusComplete = "Completed" 23) 24 25var StatusToDisplay = map[int]string{ 26 StatusIntact: "Intact Projects", 27 StatusDownstreamOnly: "Downstream Only Projects", 28 StatusModified: "Modified Projects", 29 StatusUpstream: "Upstream Only Projects", 30 StatusForked: "Forked Projects", 31} 32 33type ProjectType int 34 35var Empty ProjectType = 0 36var DifferentialSpecific ProjectType = 1 37var Global ProjectType = 2 38 39var ProjectTypeToDisplay = map[ProjectType]string{ 40 Empty: "Empty", 41 DifferentialSpecific: "Differential Specific", 42 Global: "Global", 43} 44 45var displayToStatus map[string]int 46 47func makeDisplayToStatus() map[string]int { 48 return invertMap(StatusToDisplay) 49} 50 51func GetStatusEnum(displayStatus string) (int, error) { 52 if displayToStatus == nil { 53 displayToStatus = makeDisplayToStatus() 54 } 55 val, ok := displayToStatus[displayStatus] 56 if !ok { 57 return 0, errors.New( 58 fmt.Sprintf("No matching enum for %s", displayStatus), 59 ) 60 } 61 return val, nil 62} 63 64func invertMap(m map[int]string) map[string]int { 65 inverted := make(map[string]int, len(m)) 66 for k := range StatusToDisplay { 67 v := StatusToDisplay[k] 68 inverted[v] = k 69 } 70 return inverted 71} 72 73func NullUUID() uuid.UUID { 74 emptyBytes := make([]byte, 16) 75 u, _ := uuid.FromBytes(emptyBytes) 76 return u 77} 78