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
33e3bf7c
Unverified
Commit
33e3bf7c
authored
2 years ago
by
Michael Kriese
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor: move nested function to module scope (#17361)
Co-authored-by:
Rhys Arkins
<
rhys@arkins.net
>
parent
57ade2b3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/manager/regex/utils.ts
+23
-19
23 additions, 19 deletions
lib/modules/manager/regex/utils.ts
with
23 additions
and
19 deletions
lib/modules/manager/regex/utils.ts
+
23
−
19
View file @
33e3bf7c
...
...
@@ -20,6 +20,27 @@ export const validMatchFields = [
type
ValidMatchFields
=
typeof
validMatchFields
[
number
];
function
updateDependency
(
dependency
:
PackageDependency
,
field
:
ValidMatchFields
,
value
:
string
):
void
{
switch
(
field
)
{
case
'
registryUrl
'
:
// check if URL is valid and pack inside an array
try
{
const
url
=
new
URL
(
value
).
toString
();
dependency
.
registryUrls
=
[
url
];
}
catch
(
err
)
{
logger
.
warn
({
value
},
'
Invalid regex manager registryUrl
'
);
}
break
;
default
:
dependency
[
field
]
=
value
;
break
;
}
}
export
function
createDependency
(
extractionTemplate
:
ExtractionTemplate
,
config
:
CustomExtractConfig
,
...
...
@@ -28,30 +49,13 @@ export function createDependency(
const
dependency
=
dep
??
{};
const
{
groups
,
replaceString
}
=
extractionTemplate
;
function
updateDependency
(
field
:
ValidMatchFields
,
value
:
string
):
void
{
switch
(
field
)
{
case
'
registryUrl
'
:
// check if URL is valid and pack inside an array
try
{
const
url
=
new
URL
(
value
).
toString
();
dependency
.
registryUrls
=
[
url
];
}
catch
(
err
)
{
logger
.
warn
({
value
},
'
Invalid regex manager registryUrl
'
);
}
break
;
default
:
dependency
[
field
]
=
value
;
break
;
}
}
for
(
const
field
of
validMatchFields
)
{
const
fieldTemplate
=
`
${
field
}
Template`
as
keyof
RegexManagerTemplates
;
const
tmpl
=
config
[
fieldTemplate
];
if
(
tmpl
)
{
try
{
const
compiled
=
template
.
compile
(
tmpl
,
groups
,
false
);
updateDependency
(
field
,
compiled
);
updateDependency
(
dependency
,
field
,
compiled
);
}
catch
(
err
)
{
logger
.
warn
(
{
template
:
tmpl
},
...
...
@@ -60,7 +64,7 @@ export function createDependency(
return
null
;
}
}
else
if
(
groups
[
field
])
{
updateDependency
(
field
,
groups
[
field
]);
updateDependency
(
dependency
,
field
,
groups
[
field
]);
}
}
dependency
.
replaceString
=
replaceString
;
...
...
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