refactor(governance): check escalation deadlines in their own function, keeping validate under the complexity limit (#1985)
This commit is contained in:
1 file changed
+13
-4
@@ -410,10 +410,8 @@ func (s Settings) validate() error {
|
||||
if s.AttemptsPerRun < minAttemptsPerRun || s.AttemptsPerRun > maxAttemptsPerRun {
|
||||
return fmt.Errorf("attempts per run must be between %d and %d", minAttemptsPerRun, maxAttemptsPerRun)
|
||||
}
|
||||
for _, st := range s.Escalation {
|
||||
if st.Deadline < minApprovalDeadline || st.Deadline > maxApprovalDeadline {
|
||||
return fmt.Errorf("each escalation deadline must be between %s and %s", minApprovalDeadline, maxApprovalDeadline)
|
||||
}
|
||||
if err := validDeadlines(s.Escalation); err != nil {
|
||||
return err
|
||||
}
|
||||
if s.ActionsPerRun < 1 || s.ActionsPerRun > maxActionBudget || s.ActionsPerDay < s.ActionsPerRun || s.ActionsPerDay > maxActionBudget {
|
||||
return fmt.Errorf("actions per run must be at least 1, and actions per day at least that and at most %d", maxActionBudget)
|
||||
@@ -421,6 +419,17 @@ func (s Settings) validate() error {
|
||||
return s.Timing.validate()
|
||||
}
|
||||
|
||||
// validDeadlines keeps each escalation step's deadline inside the range the
|
||||
// approval deadline takes.
|
||||
func validDeadlines(path []Step) error {
|
||||
for _, st := range path {
|
||||
if st.Deadline < minApprovalDeadline || st.Deadline > maxApprovalDeadline {
|
||||
return fmt.Errorf("each escalation deadline must be between %s and %s", minApprovalDeadline, maxApprovalDeadline)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// knows checks that the default owner and every person on the escalation path
|
||||
// is one of people, and that no one is on the path twice.
|
||||
func (s Settings) knows(people []store.Person) error {
|
||||
|
||||
Reference in new issue
Block a user