Skip to content

feat(updaters): add Gradle version catalog TOML updater - #597

Open
ruromero wants to merge 1 commit into
guacsec:mainfrom
ruromero:TC-5412
Open

feat(updaters): add Gradle version catalog TOML updater#597
ruromero wants to merge 1 commit into
guacsec:mainfrom
ruromero:TC-5412

Conversation

@ruromero

@ruromero ruromero commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • New src/updaters/toml_updater.js module with updateTomlVersions() API
  • Supports centralized version.ref, inline version = "x.y.z", and string shorthand patterns
  • Position-based regex replacement preserves TOML comments and formatting
  • Handles group/name notation alongside module notation
  • 21 new tests covering all patterns, edge cases, and error handling

Implements TC-5412

Test plan

  • Centralized version updates via version.ref
  • Inline version updates
  • String shorthand updates
  • Group/name notation support
  • Formatting and comment preservation
  • Malformed TOML fail-safe
  • Idempotency verification
  • npm run lint passes
  • npm test passes

Summary by Sourcery

Add a TOML updater for Gradle version catalogs and comprehensive tests and fixtures to validate version update behavior.

New Features:

  • Introduce updateTomlVersions helper to update dependency versions in Gradle libs.versions.toml catalogs using centralized and inline version declarations.

Tests:

  • Add extensive toml_updater test suite and TOML fixtures covering centralized refs, inline and shorthand versions, edge cases, malformed input, and idempotency.

Implements TC-5412

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Assisted-by: Claude Code
@sourcery-ai

sourcery-ai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a new TOML-based Gradle version catalog updater and comprehensive tests/fixtures to support updating dependency versions via centralized refs, inline declarations, and shorthand strings while preserving formatting and comments.

File-Level Changes

Change Details Files
Introduce updateTomlVersions TOML updater for Gradle version catalogs using smol-toml and regex-based, position-aware replacement.
  • Add updateTomlVersions() to parse libs.versions.toml with smol-toml and apply versionChanges for given groupId/artifactId pairs.
  • Build a library index from [libraries] entries supporting module, group/name, and string shorthand formats to resolve modules.
  • Implement detection of centralized version.ref versus inline version or shorthand versions and branch update behavior accordingly.
  • Use regex-based replacement helpers to update [versions] section entries and inline versions in-place while preserving layout and comments.
  • Track applied vs skipped updates with structured reasons for no-op, missing entries, missing refs, malformed TOML, or unchanged versions.
src/updaters/toml_updater.js
Add tests and fixtures validating TOML updater behavior across centralized, inline, shorthand, edge, malformed, and idempotent cases.
  • Create libs.versions.toml fixture representing typical Gradle version catalog with centralized refs, inline versions, shorthand strings, bundles, plugins, and BOM-managed entries.
  • Add toml_updater.test.js suites covering centralized version.ref updates, inline and shorthand updates, unmatched and BOM-managed entries, comment/section preservation, idempotency, multiple changes per call, malformed/degenerate TOML handling, and edge cases including group/name and complex version strings.
test/updaters/toml_updater.test.js
test/updaters/fixtures/libs.versions.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/updaters/toml_updater.js" line_range="238-247" />
<code_context>
+ * @param {string} newVersion - replacement version string
+ * @returns {string} updated content
+ */
+function replaceInlineVersion(content, alias, oldVersion, newVersion) {
+	const escapedAlias = escapeRegExp(alias)
+	const escapedOld = escapeRegExp(oldVersion)
+	const pattern = new RegExp(
+		`^(\\s*${escapedAlias}\\s*=\\s*\\{[^}]*version\\s*=\\s*")${escapedOld}("[^}]*\\}\\s*)$`,
+		'm'
+	)
+	const result = content.replace(pattern, `$1${newVersion}$2`)
+	if (result !== content) {
+		return result
+	}
+	const stringPattern = new RegExp(
+		`^(\\s*${escapedAlias}\\s*=\\s*"[^:]+:[^:]+:)${escapedOld}("\\s*)$`,
+		'm'
+	)
+	return content.replace(stringPattern, `$1${newVersion}$2`)
+}
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Handle failure to match inline versions to avoid false positives in `applied`

`replaceInlineVersion` can return the original `content` when neither regex matches (e.g. formatting differences or the version being in a different position), but the caller still records this as applied. Consider detecting when no replacement occurs and propagating that information so the caller can mark the change as skipped instead. For example, return `{ content, replaced: boolean }` or compare the result with the input and act accordingly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +238 to +247
function replaceInlineVersion(content, alias, oldVersion, newVersion) {
const escapedAlias = escapeRegExp(alias)
const escapedOld = escapeRegExp(oldVersion)
const pattern = new RegExp(
`^(\\s*${escapedAlias}\\s*=\\s*\\{[^}]*version\\s*=\\s*")${escapedOld}("[^}]*\\}\\s*)$`,
'm'
)
const result = content.replace(pattern, `$1${newVersion}$2`)
if (result !== content) {
return result

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Handle failure to match inline versions to avoid false positives in applied

replaceInlineVersion can return the original content when neither regex matches (e.g. formatting differences or the version being in a different position), but the caller still records this as applied. Consider detecting when no replacement occurs and propagating that information so the caller can mark the change as skipped instead. For example, return { content, replaced: boolean } or compare the result with the input and act accordingly.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.33840% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.21%. Comparing base (156bb77) to head (8edd65e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/updaters/toml_updater.js 97.33% 7 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #597      +/-   ##
==========================================
+ Coverage   91.01%   91.21%   +0.20%     
==========================================
  Files          38       39       +1     
  Lines        8001     8264     +263     
  Branches     1395     1438      +43     
==========================================
+ Hits         7282     7538     +256     
- Misses        719      726       +7     
Flag Coverage Δ
unit-tests 91.21% <97.33%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/updaters/toml_updater.js 97.33% <97.33%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants