forked from zengchen1024/robot-gitee-review-trigger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
56 lines (44 loc) · 1.11 KB
/
job.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
package main
import (
"fmt"
ciparser "github.com/opensourceways/robot-gitee-review-trigger/ci-parser"
)
type jobConfig struct {
// CITable is the table for CI comment of PR.
CITable ciparser.CITable `json:"ci_table" required:"true"`
// JobSuccessStatus is the status desc when a single job is successful
JobSuccessStatus []string `json:"job_success_status" required:"true"`
}
func (c *jobConfig) validate() error {
if c == nil {
return nil
}
if err := c.CITable.Validate(); err != nil {
return err
}
if len(c.JobSuccessStatus) == 0 {
return fmt.Errorf("missing job_success_status")
}
return nil
}
func (c jobConfig) newCIParser() ciparser.CIParserImpl {
return ciparser.CIParserImpl{
CITable: c.CITable,
JobStatus: []ciparser.JobStatusDesc{
{
Desc: c.JobSuccessStatus,
Status: "success",
},
},
}
}
func (c jobConfig) isCISuccess(comment string, jobNumber int) (bool, error) {
if !c.CITable.IsCIComment(comment) {
return false, nil
}
status, err := ciparser.ParseCIComment(c.newCIParser(), comment)
if err != nil {
return false, err
}
return len(status) == jobNumber, nil
}