From 81921cd0bb4fcd4a18b15adb97b41578c1535d97 Mon Sep 17 00:00:00 2001 From: Julien Tanay Date: Wed, 20 Nov 2024 06:38:50 +0100 Subject: [PATCH] feat(bundler): add inline source support (#32600) --- lib/modules/manager/bundler/extract.spec.ts | 44 +++++++++++++++++---- lib/modules/manager/bundler/extract.ts | 8 ++++ 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/lib/modules/manager/bundler/extract.spec.ts b/lib/modules/manager/bundler/extract.spec.ts index 54fd4b4cfe8542..8e58870bed9922 100644 --- a/lib/modules/manager/bundler/extract.spec.ts +++ b/lib/modules/manager/bundler/extract.spec.ts @@ -145,8 +145,6 @@ describe('modules/manager/bundler/extract', () => { it('parses source variable in Gemfile', async () => { const sourceVariableGemfile = codeBlock` - source "https://rubygems.org" - ruby '~> 1.5.3' foo = 'https://gems.foo.com' bar = 'https://gems.bar.com' @@ -159,12 +157,42 @@ describe('modules/manager/bundler/extract', () => { fs.readLocalFile.mockResolvedValueOnce(sourceVariableGemfile); const res = await extractPackageFile(sourceVariableGemfile, 'Gemfile'); - expect(res?.deps).toHaveLength(2); - expect(res?.registryUrls).toHaveLength(2); - expect(res?.registryUrls?.[1]).toBe('https://gems.foo.com'); - expect(res?.deps[1]).toMatchObject({ - depName: 'some_internal_gem', - registryUrls: ['https://gems.bar.com'], + expect(res).toMatchObject({ + registryUrls: ['https://gems.foo.com'], + deps: [ + { + depName: 'some_internal_gem', + registryUrls: ['https://gems.bar.com'], + }, + ], + }); + }); + + it('parses inline source in Gemfile', async () => { + const sourceInlineGemfile = codeBlock` + baz = 'https://gems.baz.com' + gem "inline_source_gem", source: 'https://gems.foo.com' + gem 'inline_source_gem_with_version', "~> 1", source: 'https://gems.bar.com' + gem 'inline_source_gem_with_variable_source', source: baz + `; + fs.readLocalFile.mockResolvedValueOnce(sourceInlineGemfile); + const res = await extractPackageFile(sourceInlineGemfile, 'Gemfile'); + expect(res).toMatchObject({ + deps: [ + { + depName: 'inline_source_gem', + registryUrls: ['https://gems.foo.com'], + }, + { + depName: 'inline_source_gem_with_version', + currentValue: '"~> 1"', + registryUrls: ['https://gems.bar.com'], + }, + { + depName: 'inline_source_gem_with_variable_source', + registryUrls: ['https://gems.baz.com'], + }, + ], }); }); }); diff --git a/lib/modules/manager/bundler/extract.ts b/lib/modules/manager/bundler/extract.ts index 8087f2afadd216..e84cd65cb36f41 100644 --- a/lib/modules/manager/bundler/extract.ts +++ b/lib/modules/manager/bundler/extract.ts @@ -137,6 +137,14 @@ export async function extractPackageFile( const currentValue = gemMatch.groups.currentValue; dep.currentValue = currentValue; } + if (gemMatch.groups?.registryUrl) { + const registryUrl = gemMatch.groups.registryUrl; + dep.registryUrls = [registryUrl]; + } + if (gemMatch.groups?.sourceName) { + const registryUrl = variables[gemMatch.groups.sourceName]; + dep.registryUrls = [registryUrl]; + } dep.datasource = RubygemsDatasource.id; res.deps.push(dep); }