-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathevaluate.go
More file actions
80 lines (72 loc) · 1.49 KB
/
evaluate.go
File metadata and controls
80 lines (72 loc) · 1.49 KB
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
73
74
75
76
77
78
79
80
package request
import (
"time"
"github.com/ActiveState/cli/internal/rtutils/ptr"
)
func Evaluate(organization, project string, expr []byte, atTime *time.Time, dynamic bool, target string) *evaluate {
eval := &evaluate{map[string]interface{}{
"organization": organization,
"project": project,
"expr": string(expr),
"target": target,
}}
var timestamp *string
if atTime != nil {
timestamp = ptr.To(atTime.Format(time.RFC3339))
}
if !dynamic {
eval.vars["atTime"] = timestamp
} else {
eval.vars["atTime"] = "dynamic"
}
return eval
}
type evaluate struct {
vars map[string]interface{}
}
func (b *evaluate) Query() string {
return `
query ($organization: String!, $project: String!, $expr: BuildExpr!, $atTime: AtTime, $target: String) {
project(organization: $organization, project: $project) {
... on Project {
evaluate(expr: $expr, atTime: $atTime, target: $target) {
... on Build {
__typename
status
}
... on Error {
__typename
message
}
... on ErrorWithSubErrors {
__typename
subErrors {
__typename
... on GenericSolveError {
message
isTransient
validationErrors {
error
jsonPath
}
}
... on RemediableSolveError {
message
isTransient
errorType
validationErrors {
error
jsonPath
}
}
}
}
}
}
}
}
`
}
func (b *evaluate) Vars() (map[string]interface{}, error) {
return b.vars, nil
}