Skip to content

fix(notify-upgrade): address command execution bugs and update migration docs - #2054

Merged
nicholas-fedor merged 2 commits into
mainfrom
fix/2041-notify-upgrade-fixes-and-documentation-updates
Jul 28, 2026
Merged

fix(notify-upgrade): address command execution bugs and update migration docs#2054
nicholas-fedor merged 2 commits into
mainfrom
fix/2041-notify-upgrade-fixes-and-documentation-updates

Conversation

@nicholas-fedor

@nicholas-fedor nicholas-fedor commented Jul 28, 2026

Copy link
Copy Markdown
Owner

The PR fixes the notify-upgrade subcommand so it works correctly without relying on the root command's skipped PreRun, and expands the migration tool documentation with complete usage instructions.

Problem

notify-upgrade is a Cobra subcommand and does not inherit PreRun from the root command. As a result, the command was missing critical setup: logging configuration was never applied, the current container ID was never resolved for copy instructions, and invalid legacy notification config caused a fatal exit instead of returning a clean error.

Solution

runNotifyUpgradeE now explicitly performs the setup steps it needs, using cmd.Root() for flag/env/config binding. Temp-file creation targets the working directory, container ID detection falls back to filesystem-based methods that do not require a Docker client, and a new BuildURLs helper returns errors for unknown legacy notification types instead of exiting the process.

Changes

  • Restored flag/env/config loading for notify-upgrade via cmd.Root().PersistentFlags() and appConfig.Load(cmd.Root(), nil)
  • Added flags.SetupLogging so --log-format, --log-level, and --no-color are honored
  • Replaced notifications.NewNotifier with the new notifications.BuildURLs to avoid logrus.Fatal on invalid legacy notification config
  • Replaced the never-populated currentWatchtowerContainerID check with local filesystem-based detection using container.GetContainerIDFromMountinfo and container.GetContainerIDFromCgroupFile
  • Changed temp-file creation to os.CreateTemp(".", ...)
  • Appended a trailing newline to the generated output file
  • Expanded docs/notifications/deprecations/migration-tool/index.md with usage guidance, per-service walkthroughs, file retrieval steps, and an automated migration script

Summary by CodeRabbit

  • New Features

    • Enhanced notify-upgrade migration to convert legacy notification settings into Shoutrrr URLs.
    • Generated URL output is now written to a temporary file in the working directory for easier retrieval.
  • Bug Fixes

    • Improved copy/instructions reliability by using a more robust container ID fallback.
    • Output formatting for the generated environment file is now more consistent.
  • Documentation

    • Expanded migration walkthroughs with single-use run examples for Email/SMTP, Gotify, Slack, and Microsoft Teams.
    • Added an automated migration script with clear retrieval, timing, and manual post-edit notes (e.g., Slack channel changes).

…ion docs

- Use Root().PersistentFlags for proper flag binding across command hierarchy
- Initialize logging via SetupLogging prior to config resolution
- Extract URL building into BuildURLs to avoid unnecessary notifier creation
- Create temporary output file in working directory
- Ensure output file includes trailing newline with Fprintln
- Add mountinfo-based container ID detection as fallback mechanism
- Overhaul migration tool documentation with comprehensive usage examples
@nicholas-fedor nicholas-fedor linked an issue Jul 28, 2026 that may be closed by this pull request
3 tasks
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 765076ce-4604-4c5a-93fc-0349ff642ef7

📥 Commits

Reviewing files that changed from the base of the PR and between 1a32a00 and f99ffec.

📒 Files selected for processing (2)
  • cmd/notify-upgrade.go
  • docs/notifications/deprecations/migration-tool/index.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/notifications/deprecations/migration-tool/index.md
  • cmd/notify-upgrade.go

📝 Walkthrough

Walkthrough

Changes

Notification migration

Layer / File(s) Summary
Legacy notification URL generation
pkg/notifications/notifier.go
Adds BuildURLs to copy configured URLs and generate Shoutrrr URLs from legacy notification types with returned errors.
notify-upgrade configuration and output
cmd/notify-upgrade.go
Loads root command configuration, uses BuildURLs, writes newline-terminated output in the working directory, and adds container ID fallbacks.
Migration usage and automation
docs/notifications/deprecations/migration-tool/index.md
Documents command usage, provider-specific migration steps, generated-file retrieval, and an automated migration script.

Sequence Diagram(s)

sequenceDiagram
  participant NotifyUpgrade
  participant RootConfig
  participant BuildURLs
  participant TempFile
  NotifyUpgrade->>RootConfig: load root flags, environment, aliases, and secrets
  RootConfig-->>NotifyUpgrade: cfg.Notify
  NotifyUpgrade->>BuildURLs: build notification URLs
  BuildURLs-->>NotifyUpgrade: Shoutrrr URL list
  NotifyUpgrade->>TempFile: write generated environment file
Loading

Possibly related issues

  • Repository issue 2041 — Covers the notify-upgrade invocation and file-copy instructions expanded in the migration documentation.

Possibly related PRs

  • nicholas-fedor/watchtower#1039 — Changes parsing into the notification fields consumed by this PR through root configuration loading.
  • nicholas-fedor/watchtower#1737 — Both changes handle legacy notification types in pkg/notifications/notifier.go; this PR adds URL generation while that PR adds deprecation handling.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main changes: notify-upgrade fixes and migration documentation updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 minor

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
CodeStyle 1 minor

View in Codacy

🟢 Metrics 10 complexity · 0 duplication

Metric Results
Complexity 10
Duplication 0

View in Codacy

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

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/notifications/notifier.go 0.00% 14 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2054      +/-   ##
==========================================
- Coverage   72.25%   72.17%   -0.08%     
==========================================
  Files         120      120              
  Lines       13318    13332      +14     
==========================================
  Hits         9623     9623              
- Misses       3271     3285      +14     
  Partials      424      424              
Files with missing lines Coverage Δ
pkg/notifications/notifier.go 83.98% <0.00%> (-5.42%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/notify-upgrade.go`:
- Around line 157-166: Update the runtime command generation associated with
container ID resolution in cmd/notify-upgrade.go (lines 157-166) to emit the
valid two-operand Docker copy form, using the resolved container ID and file
path as the source and ./watchtower-notifications.env as the destination. Update
each corresponding example in
docs/notifications/deprecations/migration-tool/index.md at lines 208-225,
280-290, 377-387, 464-474, and 545-555 to remove duplicated container prefixes
and use the same valid docker cp syntax.

In `@docs/notifications/deprecations/migration-tool/index.md`:
- Around line 312-320: Update the Docker CLI example’s
WATCHTOWER_NOTIFICATION_URL assignment to quote the complete -e argument,
preserving the SMTP URL and all existing parameters while preventing shell
interpretation of its & separators.
- Around line 603-613: Update the temporary path lookup after starting the
container with docker compose run so it waits for notify-upgrade output, using
log polling or follow mode with a bounded timeout. In the FILE handling flow,
distinguish a container failure from delayed or missing output, while preserving
cleanup through the existing CONTAINER trap.
- Around line 128-166: The migration examples currently advertise Slack channel
configuration that notify-upgrade does not preserve. Update the conversion path
used by slackTypeNotifier.GetURL to retain the configured SlackChannel instead
of replacing it with "webhook"; alternatively, remove the Slack channel options
from the Docker Compose and CLI examples and document the limitation.
- Line 607: Update the documented FILE assignment to remove non-portable grep -P
usage, replacing it with portable extended-regex or shell-native extraction that
still selects the latest watchtower-notif-urls-* path from docker logs. Preserve
the existing fallback behavior when no match is found.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 48338d19-1dea-41f0-847f-a416b4c0a005

📥 Commits

Reviewing files that changed from the base of the PR and between 0dbaa0d and 1a32a00.

📒 Files selected for processing (3)
  • cmd/notify-upgrade.go
  • docs/notifications/deprecations/migration-tool/index.md
  • pkg/notifications/notifier.go

Comment thread cmd/notify-upgrade.go
Comment thread docs/notifications/deprecations/migration-tool/index.md Outdated
Comment thread docs/notifications/deprecations/migration-tool/index.md
Comment thread docs/notifications/deprecations/migration-tool/index.md
Comment thread docs/notifications/deprecations/migration-tool/index.md Outdated
…ted slack channel

- Fix log output to show docker cp instead of cp for container file extraction
- Remove WATCHTOWER_NOTIFICATION_SLACK_CHANNEL from all configuration examples
- Correct docker cp command syntax in documentation copy instructions
- Add quotes around SMTP URL environment variable to preserve special characters
@nicholas-fedor
nicholas-fedor merged commit 6126f80 into main Jul 28, 2026
18 of 20 checks passed
@nicholas-fedor
nicholas-fedor deleted the fix/2041-notify-upgrade-fixes-and-documentation-updates branch July 28, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Missing instructions for notify-upgrade in Migration Tool docs

1 participant