|
| 1 | +package handlers |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/sourcegraph/sourcegraph/lib/errors" |
| 5 | +) |
| 6 | + |
| 7 | +type Config struct { |
| 8 | + Spec Spec `json:"spec"` |
| 9 | +} |
| 10 | + |
| 11 | +type Spec struct { |
| 12 | + Mover MoverSpec `json:"mover,omitempty"` |
| 13 | +} |
| 14 | + |
| 15 | +type MoverSpec struct { |
| 16 | + Rules []RuleSpec `json:"rules"` |
| 17 | +} |
| 18 | + |
| 19 | +type RuleSpec struct { |
| 20 | + // Src is the identifier of the source team. Only issues from this team will be evaluated for this rule. |
| 21 | + Src SrcSpec `json:"src"` |
| 22 | + // Dst is the identifier of the destination team. Issues that match the rule will be moved to this team. |
| 23 | + Dst DstSpec `json:"dst"` |
| 24 | +} |
| 25 | + |
| 26 | +type SrcSpec struct { |
| 27 | + // TeamID is the identifier of the team that the issue must be in for the rule to match. |
| 28 | + // Use the keyword 'Any Issue' to match any source team. |
| 29 | + TeamID string `json:"teamId,omitempty"` |
| 30 | + // Labels is a list of labels that must be present on the issue for the rule to match. |
| 31 | + Labels []string `json:"labels"` |
| 32 | +} |
| 33 | + |
| 34 | +type DstSpec struct { |
| 35 | + TeamID string `json:"teamId,omitempty"` |
| 36 | +} |
| 37 | + |
| 38 | +func (c *Config) Validate() error { |
| 39 | + return c.Spec.Validate() |
| 40 | +} |
| 41 | + |
| 42 | +func (s *Spec) Validate() error { |
| 43 | + return s.Mover.Validate() |
| 44 | +} |
| 45 | + |
| 46 | +func (s *MoverSpec) Validate() error { |
| 47 | + var errs errors.MultiError |
| 48 | + if len(s.Rules) == 0 { |
| 49 | + errs = errors.Append(errs, errors.New("rules must contain at least one rule")) |
| 50 | + } |
| 51 | + for _, r := range s.Rules { |
| 52 | + if err := r.Validate(); err != nil { |
| 53 | + errs = errors.Append(errs, err) |
| 54 | + } |
| 55 | + } |
| 56 | + return errs |
| 57 | +} |
| 58 | + |
| 59 | +func (rs RuleSpec) Validate() error { |
| 60 | + var errs errors.MultiError |
| 61 | + if rs.Src.TeamID == "" { |
| 62 | + errs = errors.Append(errs, errors.Newf("src.teamId must be set, or use %d to match any issues", WildcardTeamID)) |
| 63 | + } |
| 64 | + if len(rs.Src.Labels) == 0 { |
| 65 | + errs = errors.Append(errs, errors.New("src.labels must contain at least one label")) |
| 66 | + } |
| 67 | + if rs.Dst.TeamID == "" { |
| 68 | + errs = errors.Append(errs, errors.New("dst.teamId must be set")) |
| 69 | + } |
| 70 | + return errs |
| 71 | +} |
0 commit comments