cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/ci.go
26lines · modecode
| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "regexp" |
| 6 | ) |
| 7 | |
| 8 | type CI struct { |
| 9 | Include []string `hcl:"include,optional" json:"include,omitempty"` |
| 10 | MaxCommits int `hcl:"maxCommits,optional" json:"maxCommits,omitempty"` |
| 11 | BaseBranch string `hcl:"baseBranch,optional" json:"baseBranch,omitempty"` |
| 12 | } |
| 13 | |
| 14 | func (ci CI) validate() error { |
| 15 | if ci.MaxCommits <= 0 { |
| 16 | return errors.New("maxCommits cannot be <= 0") |
| 17 | } |
| 18 | |
| 19 | for _, pattern := range ci.Include { |
| 20 | _, err := regexp.Compile(pattern) |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | } |
| 25 | return nil |
| 26 | } |
| 27 | |