parseCoolDownFlag parses a cooldown duration string. Accepts day-suffix notation ("7d") or Go duration format ("168h", "0"). Returns 0 for "0", "0d", or "0h" (cooldown disabled).
(s string)
| 21 | // Accepts day-suffix notation ("7d") or Go duration format ("168h", "0"). |
| 22 | // Returns 0 for "0", "0d", or "0h" (cooldown disabled). |
| 23 | func parseCoolDownFlag(s string) (time.Duration, error) { |
| 24 | if daysStr, ok := strings.CutSuffix(s, "d"); ok { |
| 25 | days, err := strconv.Atoi(daysStr) |
| 26 | if err != nil || days < 0 { |
| 27 | return 0, fmt.Errorf("invalid cooldown value %q: expected a non-negative number of days (e.g. 7d)", s) |
| 28 | } |
| 29 | return time.Duration(days) * 24 * time.Hour, nil |
| 30 | } |
| 31 | d, err := time.ParseDuration(s) |
| 32 | if err != nil { |
| 33 | return 0, fmt.Errorf("invalid cooldown value %q: %w", s, err) |
| 34 | } |
| 35 | if d < 0 { |
| 36 | return 0, fmt.Errorf("invalid cooldown value %q: duration must be non-negative", s) |
| 37 | } |
| 38 | return d, nil |
| 39 | } |
| 40 | |
| 41 | // isExemptFromCoolDown returns true for repositories that bypass the cooldown period. |
| 42 | // Repositories under the "actions/" and "github/" namespaces are always updated immediately. |