Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartDataLab
public
applications
renovate
Commits
0e218922
Unverified
Commit
0e218922
authored
Jun 4, 2020
by
Praveen Adusumilli
Committed by
GitHub
Jun 4, 2020
Browse files
Options
Downloads
Patches
Plain Diff
fix: Add validations for aliases (#6426)
parent
08de7aff
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/config/__snapshots__/validation.spec.ts.snap
+20
-0
20 additions, 0 deletions
lib/config/__snapshots__/validation.spec.ts.snap
lib/config/validation.spec.ts
+46
-0
46 additions, 0 deletions
lib/config/validation.spec.ts
lib/config/validation.ts
+31
-11
31 additions, 11 deletions
lib/config/validation.ts
with
97 additions
and
11 deletions
lib/config/__snapshots__/validation.spec.ts.snap
+
20
−
0
View file @
0e218922
...
...
@@ -88,6 +88,24 @@ Array [
]
`;
exports[`config/validation validateConfig(config) errors if aliases depth is more than 1 1`] = `
Array [
Object {
"depName": "Configuration Error",
"message": "Invalid alias object configuration",
},
]
`;
exports[`config/validation validateConfig(config) errors if aliases have invalid url 1`] = `
Array [
Object {
"depName": "Configuration Error",
"message": "Invalid alias object configuration",
},
]
`;
exports[`config/validation validateConfig(config) errors if regexManager fields are missing 1`] = `
Array [
Object {
...
...
@@ -150,3 +168,5 @@ Array [
},
]
`;
exports[`config/validation validateConfig(config) validates valid alias objects 1`] = `Array []`;
This diff is collapsed.
Click to expand it.
lib/config/validation.spec.ts
+
46
−
0
View file @
0e218922
...
...
@@ -336,5 +336,51 @@ describe('config/validation', () => {
expect
(
warnings
).
toHaveLength
(
0
);
expect
(
errors
).
toHaveLength
(
0
);
});
it
(
'
validates valid alias objects
'
,
async
()
=>
{
const
config
=
{
aliases
:
{
example1
:
'
http://www.example.com
'
,
example2
:
'
https://www.example2.com/example
'
,
},
};
const
{
warnings
,
errors
}
=
await
configValidation
.
validateConfig
(
config
);
expect
(
warnings
).
toHaveLength
(
0
);
expect
(
errors
).
toHaveLength
(
0
);
expect
(
errors
).
toMatchSnapshot
();
});
it
(
'
errors if aliases depth is more than 1
'
,
async
()
=>
{
const
config
=
{
aliases
:
{
sample
:
{
example1
:
'
http://www.example.com
'
,
},
},
};
const
{
warnings
,
errors
}
=
await
configValidation
.
validateConfig
(
config
);
expect
(
warnings
).
toHaveLength
(
0
);
expect
(
errors
).
toHaveLength
(
1
);
expect
(
errors
).
toMatchSnapshot
();
});
it
(
'
errors if aliases have invalid url
'
,
async
()
=>
{
const
config
=
{
aliases
:
{
example1
:
'
noturl
'
,
example2
:
'
http://www.example.com
'
,
},
};
const
{
warnings
,
errors
}
=
await
configValidation
.
validateConfig
(
config
);
expect
(
warnings
).
toHaveLength
(
0
);
expect
(
errors
).
toHaveLength
(
1
);
expect
(
errors
).
toMatchSnapshot
();
});
});
});
This diff is collapsed.
Click to expand it.
lib/config/validation.ts
+
31
−
11
View file @
0e218922
...
...
@@ -56,6 +56,17 @@ export async function validateConfig(
return
ignoredNodes
.
includes
(
key
);
}
function
validateAliasObject
(
key
:
string
,
val
:
object
):
boolean
{
if
(
key
===
'
aliases
'
)
{
for
(
const
value
of
Object
.
values
(
val
))
{
if
(
!
is
.
urlString
(
value
))
{
return
false
;
}
}
}
return
true
;
}
for
(
const
[
key
,
val
]
of
Object
.
entries
(
config
))
{
const
currentPath
=
parentPath
?
`
${
parentPath
}
.
${
key
}
`
:
key
;
if
(
...
...
@@ -346,6 +357,14 @@ export async function validateConfig(
}
}
else
if
(
type
===
'
object
'
&&
currentPath
!==
'
compatibility
'
)
{
if
(
is
.
object
(
val
))
{
if
(
key
===
'
aliases
'
)
{
if
(
!
validateAliasObject
(
key
,
val
))
{
errors
.
push
({
depName
:
'
Configuration Error
'
,
message
:
`Invalid alias object configuration`
,
});
}
}
else
{
const
ignoredObjects
=
options
.
filter
((
option
)
=>
option
.
freeChoice
)
.
map
((
option
)
=>
option
.
name
);
...
...
@@ -358,6 +377,7 @@ export async function validateConfig(
warnings
=
warnings
.
concat
(
subValidation
.
warnings
);
errors
=
errors
.
concat
(
subValidation
.
errors
);
}
}
}
else
{
errors
.
push
({
depName
:
'
Configuration Error
'
,
...
...
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
sign in
to comment