From 4bc0d543413d7e77be1a19f9be61042ed0fe2dab Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 16 Nov 2026 09:44:30 +1100 Subject: [PATCH] refactor(governance): check escalation deadlines in their own function, keeping validate under the complexity limit (#1985) --- modules/governance/governance.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/governance/governance.go b/modules/governance/governance.go index f2b4c6a82..a17ddbb68 100644 --- a/modules/governance/governance.go +++ b/modules/governance/governance.go @@ -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 {