Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
a1c51509
Unverified
Commit
a1c51509
authored
6 months ago
by
Julien Tanay
Committed by
GitHub
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
feat(bundler): add source variables support (#32337)
parent
0cc330e9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/modules/manager/bundler/extract.spec.ts
+26
-0
26 additions, 0 deletions
lib/modules/manager/bundler/extract.spec.ts
lib/modules/manager/bundler/extract.ts
+36
-7
36 additions, 7 deletions
lib/modules/manager/bundler/extract.ts
with
62 additions
and
7 deletions
lib/modules/manager/bundler/extract.spec.ts
+
26
−
0
View file @
a1c51509
import
is
from
'
@sindresorhus/is
'
;
import
is
from
'
@sindresorhus/is
'
;
import
{
codeBlock
}
from
'
common-tags
'
;
import
{
Fixtures
}
from
'
../../../../test/fixtures
'
;
import
{
Fixtures
}
from
'
../../../../test/fixtures
'
;
import
{
fs
}
from
'
../../../../test/util
'
;
import
{
fs
}
from
'
../../../../test/util
'
;
import
{
isValid
}
from
'
../../versioning/ruby
'
;
import
{
isValid
}
from
'
../../versioning/ruby
'
;
...
@@ -141,4 +142,29 @@ describe('modules/manager/bundler/extract', () => {
...
@@ -141,4 +142,29 @@ describe('modules/manager/bundler/extract', () => {
{
depName
:
'
sfn_my_dep2
'
,
currentValue
:
'
"~> 1"
'
},
{
depName
:
'
sfn_my_dep2
'
,
currentValue
:
'
"~> 1"
'
},
]);
]);
});
});
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'
source foo
source bar do
gem "some_internal_gem"
end
`
;
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
'
],
});
});
});
});
This diff is collapsed.
Click to expand it.
lib/modules/manager/bundler/extract.ts
+
36
−
7
View file @
a1c51509
...
@@ -78,6 +78,9 @@ export async function extractPackageFile(
...
@@ -78,6 +78,9 @@ export async function extractPackageFile(
registryUrls
:
[],
registryUrls
:
[],
deps
:
[],
deps
:
[],
};
};
const
variables
:
Record
<
string
,
string
>
=
{};
const
lines
=
content
.
split
(
newlineRegex
);
const
lines
=
content
.
split
(
newlineRegex
);
for
(
lineNumber
=
0
;
lineNumber
<
lines
.
length
;
lineNumber
+=
1
)
{
for
(
lineNumber
=
0
;
lineNumber
<
lines
.
length
;
lineNumber
+=
1
)
{
const
line
=
lines
[
lineNumber
];
const
line
=
lines
[
lineNumber
];
...
@@ -85,12 +88,20 @@ export async function extractPackageFile(
...
@@ -85,12 +88,20 @@ export async function extractPackageFile(
for
(
const
delimiter
of
delimiters
)
{
for
(
const
delimiter
of
delimiters
)
{
sourceMatch
=
sourceMatch
=
sourceMatch
??
sourceMatch
??
regEx
(
`^source
${
delimiter
}
([^
${
delimiter
}
]+)
${
delimiter
}
\\
s*$`
).
exec
(
regEx
(
line
,
`^source ((
${
delimiter
}
(?<registryUrl>[^
${
delimiter
}
]+)
${
delimiter
}
)|(?<sourceName>
\\
w+))
\\
s*$`
,
);
).
exec
(
line
);
}
}
if
(
sourceMatch
)
{
if
(
sourceMatch
)
{
res
.
registryUrls
?.
push
(
sourceMatch
[
1
]);
if
(
sourceMatch
.
groups
?.
registryUrl
)
{
res
.
registryUrls
?.
push
(
sourceMatch
.
groups
.
registryUrl
);
}
if
(
sourceMatch
.
groups
?.
sourceName
)
{
const
registryUrl
=
variables
[
sourceMatch
.
groups
.
sourceName
];
if
(
registryUrl
)
{
res
.
registryUrls
?.
push
(
registryUrl
);
}
}
}
}
const
rubyMatch
=
extractRubyVersion
(
line
);
const
rubyMatch
=
extractRubyVersion
(
line
);
...
@@ -103,8 +114,18 @@ export async function extractPackageFile(
...
@@ -103,8 +114,18 @@ export async function extractPackageFile(
});
});
}
}
const
variableMatchRegex
=
regEx
(
`^(?<key>
\\
w+)
\\
s*=
\\
s*['"](?<value>[^'"]+)['"]`
,
);
const
variableMatch
=
variableMatchRegex
.
exec
(
line
);
if
(
variableMatch
)
{
if
(
variableMatch
.
groups
?.
key
)
{
variables
[
variableMatch
.
groups
?.
key
]
=
variableMatch
.
groups
?.
value
;
}
}
const
gemMatchRegex
=
regEx
(
const
gemMatchRegex
=
regEx
(
`^
\\
s*gem
\\
s+(['"])(?<depName>[^'"]+)(['"])(
\\
s*,
\\
s*(?<currentValue>(['"])[^'"]+['"](
\\
s*,
\\
s*['"][^'"]+['"])?))?`
,
`^
\\
s*gem
\\
s+(['"])(?<depName>[^'"]+)(['"])(
\\
s*,
\\
s*(?<currentValue>(['"])[^'"]+['"](
\\
s*,
\\
s*['"][^'"]+['"])?))?
(
\\
s*,
\\
s*source:
\\
s*(['"](?<registryUrl>[^'"]+)['"]|(?<sourceName>[^'"]+)))?
`
,
);
);
const
gemMatch
=
gemMatchRegex
.
exec
(
line
);
const
gemMatch
=
gemMatchRegex
.
exec
(
line
);
if
(
gemMatch
)
{
if
(
gemMatch
)
{
...
@@ -124,10 +145,18 @@ export async function extractPackageFile(
...
@@ -124,10 +145,18 @@ export async function extractPackageFile(
for
(
const
delimiter
of
delimiters
)
{
for
(
const
delimiter
of
delimiters
)
{
const
sourceBlockMatch
=
regEx
(
const
sourceBlockMatch
=
regEx
(
`^source
\\
s+
${
delimiter
}
(
.*?)
${
delimiter
}
\\
s+do`
,
`^source
\\
s+
((
${
delimiter
}
(
?<registryUrl>[^
${
delimiter
}
]+)
${
delimiter
}
)|(?<sourceName>
\\
w+))
\\
s+do`
,
).
exec
(
line
);
).
exec
(
line
);
if
(
sourceBlockMatch
)
{
if
(
sourceBlockMatch
)
{
const
repositoryUrl
=
sourceBlockMatch
[
1
];
let
repositoryUrl
=
''
;
if
(
sourceBlockMatch
.
groups
?.
registryUrl
)
{
repositoryUrl
=
sourceBlockMatch
.
groups
.
registryUrl
;
}
if
(
sourceBlockMatch
.
groups
?.
sourceName
)
{
if
(
variables
[
sourceBlockMatch
.
groups
.
sourceName
])
{
repositoryUrl
=
variables
[
sourceBlockMatch
.
groups
.
sourceName
];
}
}
const
sourceLineNumber
=
lineNumber
;
const
sourceLineNumber
=
lineNumber
;
let
sourceContent
=
''
;
let
sourceContent
=
''
;
let
sourceLine
=
''
;
let
sourceLine
=
''
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment