Skip to content

Add patch-only update mode - #28

Merged
inayayousfi merged 8 commits into
mainfrom
4-patch-only
May 9, 2026
Merged

Add patch-only update mode#28
inayayousfi merged 8 commits into
mainfrom
4-patch-only

Conversation

@inayayousfi

@inayayousfi inayayousfi commented Apr 5, 2026

Copy link
Copy Markdown
Owner

Closes #4

Summary by CodeRabbit

  • New Features

    • Added a --patch-only command-line flag to restrict dependency updates to patch versions only.
  • Bug Fixes / Improvements

    • Clarified messaging for dependencies that are not updated (now reports they "won't update").
    • In patch-only mode, non-patch version changes are skipped and non-semver dependencies emit a warning instead of being updated.
  • Tests / Chores

    • CI/test targets updated to include a patch-only test run.
    • Added a small runtime test dependency.

@coderabbitai

coderabbitai Bot commented Apr 5, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@ZiedYousfi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 4 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e73ed58d-9aff-4661-b7d9-9239090bb499

📥 Commits

Reviewing files that changed from the base of the PR and between 5ff3ef1 and 623bd65.

📒 Files selected for processing (4)
  • main.go
  • npm.go
  • npm_test.go
  • test_js/package.json
📝 Walkthrough

Walkthrough

Added a PatchOnly boolean to the exported Context and a --patch-only CLI flag; npm update flow now can compute and apply latest patch-only updates, suppresses non-patch semver updates in patch-only mode, and adjusted non-update log wording. Makefile/test fixtures updated to exercise patch-only mode.

Changes

Patch-only feature

Layer / File(s) Summary
Data Shape
ctx.go
Add PatchOnly bool field to exported Context and initialize global Ctx.PatchOnly = false.
CLI Wiring
main.go
Add --patch-only boolean flag bound to Ctx.PatchOnly (default false) and help text “Only update patch versions”.
Core Logic — NPM registry fetch
npm.go (getOtherNPMPackageVersions)
Add helper to fetch available versions from npm registry (returns keys from response time map).
Core Logic — Patch selection
npm.go (getLatestPatchNPMPackageVersion)
Add helper that filters versions to patch-level semver changes vs current version and returns newest patch candidate.
Core Logic — Update flow
npm.go (updateDependencies)
When Ctx.PatchOnly is true and dependency is semver, attempt to compute a patch-only candidate and use it as update target; change early-log wording from “already up to date” to “won’t update”.
Core Logic — Classification
npm.go (classifyDependencyUpdate)
In patch-only mode, force shouldUpdate=false for semver changes that are not patches; for non-semver deps, emit warning and return (SemverChangeNone, false).
Wiring / Helpers moved
npm.go
Logger/printing helpers (outputLogger, formatDependencyDiff, printDependencyUpdates) relocated within file without behavioral change.
Tests / Targets / Fixtures
Makefile, test_js/package.json
Add testjspatch target to run test_js with --patch-only; update all and .PHONY. Add left-pad@^1.1.2 dependency to test_js/package.json to exercise npm updates.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI (main)
    participant Ctx as Context
    participant NPM as NPM logic
    participant Registry as NPM Registry
    participant Log as Logger

    CLI->>Ctx: parse flags (--patch-only -> PatchOnly)
    Ctx->>NPM: pass context with PatchOnly
    NPM->>Registry: get package versions (getOtherNPMPackageVersions)
    Registry-->>NPM: return versions
    NPM->>NPM: compute latest patch candidate (getLatestPatchNPMPackageVersion)
    alt Patch candidate found & should apply
        NPM->>Log: record planned update
        NPM->>NPM: apply update
    else No patch candidate
        NPM->>Log: "won't update" / warn
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hop through flags and version tracks,
Patch-only carrots in my pack.
Small hops forward, tidy and bright,
I nibble bugs and sleep at night. 🥕

🚥 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 'Add patch-only update mode' clearly and concisely summarizes the main change—introduction of a new feature that allows updating packages by patch version only.
Linked Issues check ✅ Passed The PR implements the core requirement from issue #4: a --patch-only flag enabling patch-only updates with registry lookup for newer patch releases across npm dependencies.
Out of Scope Changes check ✅ Passed All changes directly support the patch-only update feature: CLI flag wiring, Context struct extension, npm update logic, patch filtering helpers, and test infrastructure for validation.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 4-patch-only

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@npm.go`:
- Around line 206-208: The conditional in the gate uses a redundant disjunct;
update the check in the function that uses Ctx.PatchOnly so it simply reads: if
Ctx.PatchOnly && changeType != SemverChangePatch { return changeType, false }
(remove the always-covered changeType == SemverChangeRevision part). Then add
unit tests in TestClassifyDependencyUpdate that set Ctx.PatchOnly = true and
assert behavior for a major/minor update (blocked), a patch update (allowed),
and a revision/no-op (blocked) to cover the gate and prevent regressions;
reference Ctx.PatchOnly, SemverChangePatch, SemverChangeRevision, and
TestClassifyDependencyUpdate when making changes.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 95fedc01-edd2-438c-a908-f3ce8456077e

📥 Commits

Reviewing files that changed from the base of the PR and between 9c5a68e and ae477c4.

📒 Files selected for processing (3)
  • ctx.go
  • main.go
  • npm.go

Comment thread npm.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
npm.go (1)

203-216: ⚠️ Potential issue | 🟠 Major

--patch-only is bypassed for non-semver version specs.

At Line 216, non-semver differences still return shouldUpdate=true, so --patch-only can update workspace:*, file:, dist-tags, etc. That breaks patch-only semantics.

💡 Proposed fix
 func classifyDependencyUpdate(currentVersion DependencyVersion, latestVersion DependencyVersion) (SemverChange, bool) {
 	if currentVersion.HasSemver && latestVersion.HasSemver {
 		changeType := currentVersion.Semver.ChangeType(latestVersion.Semver)
 		if Ctx.PatchOnly && changeType != SemverChangePatch {
 			return changeType, false
 		}
 		return changeType, changeType != SemverChangeNone && changeType != SemverChangeDowngrade
 	}
 
 	if currentVersion.String() == latestVersion.String() {
 		return SemverChangeNone, false
 	}
+	if Ctx.PatchOnly {
+		// Cannot safely classify as patch-only when either side is non-semver.
+		return SemverChangeInvalid, false
+	}
 
 	return SemverChangeInvalid, true
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@npm.go` around lines 203 - 216, The function classifyDependencyUpdate allows
non-semver changes (e.g., workspace:*, file:, dist-tags) to be marked
shouldUpdate=true even when Ctx.PatchOnly is set; update
classifyDependencyUpdate so that if Ctx.PatchOnly is true and either
currentVersion.HasSemver or latestVersion.HasSemver is false, it returns a safe
change (e.g., SemverChangeInvalid or SemverChangeNone) with shouldUpdate=false.
Specifically, in classifyDependencyUpdate (and references to DependencyVersion
and Ctx.PatchOnly), add an early guard for Ctx.PatchOnly when versions are
non-semver so non-semver diffs do not trigger updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@npm.go`:
- Around line 203-216: The function classifyDependencyUpdate allows non-semver
changes (e.g., workspace:*, file:, dist-tags) to be marked shouldUpdate=true
even when Ctx.PatchOnly is set; update classifyDependencyUpdate so that if
Ctx.PatchOnly is true and either currentVersion.HasSemver or
latestVersion.HasSemver is false, it returns a safe change (e.g.,
SemverChangeInvalid or SemverChangeNone) with shouldUpdate=false. Specifically,
in classifyDependencyUpdate (and references to DependencyVersion and
Ctx.PatchOnly), add an early guard for Ctx.PatchOnly when versions are
non-semver so non-semver diffs do not trigger updates.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bfd209ad-a411-4e21-b770-5a95be9b9b24

📥 Commits

Reviewing files that changed from the base of the PR and between ae477c4 and 6ca0406.

📒 Files selected for processing (1)
  • npm.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@npm.go`:
- Around line 216-219: The current branch that handles Ctx.PatchOnly in the
semver comparison path wrongly returns SemverChangeNone which hides that the
versions are non-semver-comparable; update the handler in the function that
checks Ctx.PatchOnly to return SemverChangeInvalid, false instead of
SemverChangeNone, false and keep the existing log (or adjust it to mention
“invalid/non-semver”) so callers and diagnostics can distinguish a skipped
non-semver comparison from a true “no change” result; refer to Ctx.PatchOnly,
SemverChangeNone and SemverChangeInvalid to locate and modify the return.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e944e3e-7b32-4052-a31c-6d0d38060dc7

📥 Commits

Reviewing files that changed from the base of the PR and between 6ca0406 and add9f88.

📒 Files selected for processing (1)
  • npm.go

Comment thread npm.go
Comment on lines +216 to +219
if Ctx.PatchOnly {
log.Warnf("Cannot determine change type for non-semver dependency version '%s' -> '%s', skipping update due to patch-only mode", currentVersion.String(), latestVersion.String())
return SemverChangeNone, false
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Don’t classify non-semver patch-only skips as SemverChangeNone.

Line 218 currently reports “none” even when the real reason is “not semver-comparable under patch-only,” which can mislead logs and diagnostics. Return SemverChangeInvalid with false to preserve reason while still skipping the update.

Suggested fix
 	if Ctx.PatchOnly {
 		log.Warnf("Cannot determine change type for non-semver dependency version '%s' -> '%s', skipping update due to patch-only mode", currentVersion.String(), latestVersion.String())
-		return SemverChangeNone, false
+		return SemverChangeInvalid, false
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if Ctx.PatchOnly {
log.Warnf("Cannot determine change type for non-semver dependency version '%s' -> '%s', skipping update due to patch-only mode", currentVersion.String(), latestVersion.String())
return SemverChangeNone, false
}
if Ctx.PatchOnly {
log.Warnf("Cannot determine change type for non-semver dependency version '%s' -> '%s', skipping update due to patch-only mode", currentVersion.String(), latestVersion.String())
return SemverChangeInvalid, false
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@npm.go` around lines 216 - 219, The current branch that handles Ctx.PatchOnly
in the semver comparison path wrongly returns SemverChangeNone which hides that
the versions are non-semver-comparable; update the handler in the function that
checks Ctx.PatchOnly to return SemverChangeInvalid, false instead of
SemverChangeNone, false and keep the existing log (or adjust it to mention
“invalid/non-semver”) so callers and diagnostics can distinguish a skipped
non-semver comparison from a true “no change” result; refer to Ctx.PatchOnly,
SemverChangeNone and SemverChangeInvalid to locate and modify the return.

Add a dedicated `testjspatch` target that exercises `--patch-only` in the JS fixture, and extend the fixture dependency set to cover patch-only update cases.
When `--patch-only` blocks a normal semver update, fetch registry versions and apply the latest compatible patch release instead.
@inayayousfi

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@npm.go`:
- Around line 127-130: The new helper currently aborts when Ctx.HTTPClient is
nil (client := Ctx.HTTPClient; if client == nil { return ..., fmt.Errorf(...) })
which breaks the secondary registry lookup even though
getNPMPackageLatestVersion works with a nil client; change the nil branch to
fall back to the default HTTP client (e.g., client = http.DefaultClient) instead
of returning an error so both the primary `/latest` and the subsequent registry
lookup can succeed; update any references in this helper that use client and
keep getNPMPackageLatestVersion behavior unchanged.
- Around line 142-155: The helper currently decodes npm metadata into
result.Time and iterates its keys, which pulls non-version keys like "created"
and "modified"; change the decoded struct to capture the "versions" object
instead (e.g., result.Versions map[string]string `json:"versions"`) and iterate
over result.Versions to build the versions slice so
getLatestPatchNPMPackageVersion and classifyDependencyUpdate only see actual
published version strings.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 32c7fea5-3090-474a-ab8e-ba3a0c2bcc71

📥 Commits

Reviewing files that changed from the base of the PR and between add9f88 and 5ff3ef1.

📒 Files selected for processing (3)
  • Makefile
  • npm.go
  • test_js/package.json
✅ Files skipped from review due to trivial changes (1)
  • test_js/package.json

Comment thread npm.go
Comment thread npm.go
@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

…only

Read registry versions from the `versions` payload and fall back to the default HTTP client when no client is configured.
Add canary and React dependencies to the JS fixture so patch-only update cases cover more registry metadata.
@inayayousfi

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@inayayousfi
inayayousfi merged commit 2707c40 into main May 9, 2026
2 checks passed
@inayayousfi
inayayousfi deleted the 4-patch-only branch May 9, 2026 19:03
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.

Add just patch update for semver

1 participant