refactor(governance): check escalation deadlines in their own function, keeping validate under the complexity limit (#1985)

This commit is contained in:
sam committed 2026-11-16 09:44:30 +11:00
1 parent dabe0b4f7c
commit 4bc0d54341
1 file changed
+13 -4
+13 -4
View File
@@ -410,10 +410,8 @@ func (s Settings) validate() error {
if s.AttemptsPerRun < minAttemptsPerRun || s.AttemptsPerRun > maxAttemptsPerRun { if s.AttemptsPerRun < minAttemptsPerRun || s.AttemptsPerRun > maxAttemptsPerRun {
return fmt.Errorf("attempts per run must be between %d and %d", minAttemptsPerRun, maxAttemptsPerRun) return fmt.Errorf("attempts per run must be between %d and %d", minAttemptsPerRun, maxAttemptsPerRun)
} }
for _, st := range s.Escalation { if err := validDeadlines(s.Escalation); err != nil {
if st.Deadline < minApprovalDeadline || st.Deadline > maxApprovalDeadline { return err
return fmt.Errorf("each escalation deadline must be between %s and %s", minApprovalDeadline, maxApprovalDeadline)
}
} }
if s.ActionsPerRun < 1 || s.ActionsPerRun > maxActionBudget || s.ActionsPerDay < s.ActionsPerRun || s.ActionsPerDay > maxActionBudget { 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) 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() 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 // 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. // is one of people, and that no one is on the path twice.
func (s Settings) knows(people []store.Person) error { func (s Settings) knows(people []store.Person) error {