fix(scheduling): strip quotes from cron schedule spec before parsing - #1686
Conversation
- Trim surrounding single and double quotes from scheduleSpec to handle values passed via Docker Compose or environment variables - Add test cases for quoted and unquoted cron specs and descriptors to ensure correct parsing
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe PR adds quote normalization to the schedule specification input in ChangesSchedule spec quote normalization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 12 |
| Duplication | 17 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1686 +/- ##
==========================================
+ Coverage 74.60% 74.79% +0.19%
==========================================
Files 59 59
Lines 9839 9949 +110
==========================================
+ Hits 7340 7441 +101
- Misses 2237 2243 +6
- Partials 262 265 +3
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
This PR implements input validation for values wrapped with quotations to Watchtower's schedule configuration option.
Problem
When users configure
WATCHTOWER_SCHEDULEin Docker Compose with quotes (e.g.,WATCHTOWER_SCHEDULE="0 0 2 * * *"), Docker Compose passes the literal quote characters as part of the environment variable value. The cron parser (robfig/cron/v3) then fails withstrconv.Atoi: parsing "\"0": invalid syntaxbecause it tries to parse"0as an integer. This is a common Docker Compose pattern and was not handled by Watchtower.Solution
Strip single and double quotes from the schedule specification string before passing it to the cron parser, following the same pattern already used for
DOCKER_API_VERSIONin the flags package. The fix is applied at the point of consumption in the scheduling code, protecting against quotes from any source (env var or CLI flag).Changes
internal/scheduling/scheduling.go-- Addedstrings.Trim(scheduleSpec,"')to strip wrapping quotes from the schedule spec before cron parsing, and added"strings"importinternal/scheduling/scheduling_test.go-- AddedTestRunUpgradesOnSchedule_QuotedScheduleSpecwith 6 test cases covering double-quoted cron, single-quoted cron, double-quoted descriptor, unquoted variants, and double-quoted invalid specsSummary by CodeRabbit
Release Notes
"0 0 2 * * *",'0 0 2 * * *', or@hourly).