Skip to content

[syncer] add dry run mode#7

Merged
capcom6 merged 1 commit intomasterfrom
syncer/dry-run-mode
May 5, 2026
Merged

[syncer] add dry run mode#7
capcom6 merged 1 commit intomasterfrom
syncer/dry-run-mode

Conversation

@capcom6
Copy link
Copy Markdown
Owner

@capcom6 capcom6 commented Apr 30, 2026

Summary by CodeRabbit

  • New Features

    • Added a --dry-run option to preview sync operations; file events are reported as "Would create/modify/remove" without making changes.
  • Improvements

    • Consistent path logging across sync events.
    • Upload logs now include file sizes when available for clearer transfer visibility.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

🤖 Pull request artifacts

Platform File
🐳 Docker GitHub Container Registry
🍎 Darwin arm64 sftp-sync_Darwin_arm64.tar.gz
🍎 Darwin x86_64 sftp-sync_Darwin_x86_64.tar.gz
🐧 Linux arm64 sftp-sync_Linux_arm64.tar.gz
🐧 Linux i386 sftp-sync_Linux_i386.tar.gz
🐧 Linux x86_64 sftp-sync_Linux_x86_64.tar.gz
🪟 Windows arm64 sftp-sync_Windows_arm64.zip
🪟 Windows i386 sftp-sync_Windows_i386.zip
🪟 Windows x86_64 sftp-sync_Windows_x86_64.zip

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 752aaba5-531f-4544-896c-ae2f1bee20c3

📥 Commits

Reviewing files that changed from the base of the PR and between a49f9a2 and ad23110.

📒 Files selected for processing (4)
  • internal/cli/commands/sync/config.go
  • internal/cli/commands/sync/sync.go
  • internal/syncer/syncer.go
  • main.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • main.go
  • internal/cli/commands/sync/config.go
  • internal/syncer/syncer.go
  • internal/cli/commands/sync/sync.go

Walkthrough

Adds a --dry-run CLI flag (global and passed into the sync command). When enabled, watcher events do not invoke the syncer and instead log “Would create/modify/remove ”. Syncer logging is standardized to use a fieldPath key and includes size when os.Stat succeeds.

Changes

Sync CLI + Dry-run + Logging

Layer / File(s) Summary
Data Shape
internal/cli/commands/sync/config.go
config gains a DryRun bool field; parseConfig default-inits and sets it from --dry-run.
CLI Wiring
main.go
Adds the --dry-run boolean flag to the sftp-sync command flags.
Control Flow / Dry-run Behavior
internal/cli/commands/sync/sync.go
Watcher event loop branches on cfg.DryRun: when true call new dryRunLog(ctx, event) which logs Would <action> with logger.Fields{"path": event.RelPath}; when false call syncer.Sync(ctx, event.AbsPath) as before. Also introduces the unexported dryRunLog helper.
Operational Logging
internal/syncer/syncer.go
Introduces fieldPath = "path" constant used consistently in logger.Fields; "Uploaded" log now builds a fields map with fieldPath: relPath and conditionally adds size from os.Stat(absPath) before logging.

Sequence Diagram

sequenceDiagram
    actor Watcher
    participant CLI
    participant Syncer
    participant Logger

    Watcher->>CLI: file event (create/modify/remove, rel+abs path)
    CLI->>CLI: check cfg.DryRun
    alt DryRun == true
        CLI->>Logger: log "Would <action>" with `path` (relPath)
    else DryRun == false
        CLI->>Syncer: Sync(ctx, absPath)
        Syncer->>Syncer: optional os.Stat(absPath) -> size
        Syncer->>Logger: log "Uploaded"/"Created"/"Removed" with `path`[, size]
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[syncer] add dry run mode' directly and clearly describes the main change: adding a dry run feature to the syncer component.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch syncer/dry-run-mode

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/syncer/syncer.go`:
- Around line 81-84: The call to os.Stat(absPath) in the syncer code can return
an error and leave info nil, so guard the result before calling info.Size():
check the error returned by os.Stat(absPath) (and that info != nil) and handle
the failure path (e.g., log the stat error with s.logger.Error/Info and use a
fallback size like 0 or skip logging size) before invoking info.Size() in the
s.logger.Info call; update the block around os.Stat(absPath), the info variable,
and the s.logger.Info(...) call to avoid a nil dereference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4e96bfb8-fdae-4b87-b0d6-bed81879e647

📥 Commits

Reviewing files that changed from the base of the PR and between 5f6bfd6 and dbe9a2e.

📒 Files selected for processing (4)
  • internal/cli/commands/sync/config.go
  • internal/cli/commands/sync/sync.go
  • internal/syncer/syncer.go
  • main.go

Comment thread internal/syncer/syncer.go Outdated
@capcom6 capcom6 force-pushed the syncer/dry-run-mode branch from a49f9a2 to ad23110 Compare May 5, 2026 03:53
@capcom6 capcom6 merged commit 5131d20 into master May 5, 2026
8 checks passed
@capcom6 capcom6 deleted the syncer/dry-run-mode branch May 5, 2026 07:02
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.

1 participant