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
52687368
Commit
52687368
authored
3 years ago
by
Rhys Arkins
Browse files
Options
Downloads
Patches
Plain Diff
refactor: hostRules error
parent
61c648d2
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/util/host-rules.spec.ts
+6
-3
6 additions, 3 deletions
lib/util/host-rules.spec.ts
lib/util/host-rules.ts
+9
-8
9 additions, 8 deletions
lib/util/host-rules.ts
with
15 additions
and
11 deletions
lib/util/host-rules.spec.ts
+
6
−
3
View file @
52687368
...
@@ -15,7 +15,7 @@ describe(getName(), () => {
...
@@ -15,7 +15,7 @@ describe(getName(), () => {
domainName
:
'
github.com
'
,
domainName
:
'
github.com
'
,
hostName
:
'
api.github.com
'
,
hostName
:
'
api.github.com
'
,
})
})
).
toThrow
(
'
hostRules cannot contain both a domainName and hostName
'
);
).
toThrow
();
});
});
it
(
'
throws if both domainName and baseUrl
'
,
()
=>
{
it
(
'
throws if both domainName and baseUrl
'
,
()
=>
{
expect
(()
=>
expect
(()
=>
...
@@ -24,7 +24,7 @@ describe(getName(), () => {
...
@@ -24,7 +24,7 @@ describe(getName(), () => {
domainName
:
'
github.com
'
,
domainName
:
'
github.com
'
,
baseUrl
:
'
https://api.github.com
'
,
baseUrl
:
'
https://api.github.com
'
,
})
})
).
toThrow
(
'
hostRules cannot contain both a domainName and baseUrl
'
);
).
toThrow
();
});
});
it
(
'
throws if both hostName and baseUrl
'
,
()
=>
{
it
(
'
throws if both hostName and baseUrl
'
,
()
=>
{
expect
(()
=>
expect
(()
=>
...
@@ -33,7 +33,7 @@ describe(getName(), () => {
...
@@ -33,7 +33,7 @@ describe(getName(), () => {
hostName
:
'
api.github.com
'
,
hostName
:
'
api.github.com
'
,
baseUrl
:
'
https://api.github.com
'
,
baseUrl
:
'
https://api.github.com
'
,
})
})
).
toThrow
(
'
hostRules cannot contain both a hostName and baseUrl
'
);
).
toThrow
();
});
});
it
(
'
supports baseUrl-only
'
,
()
=>
{
it
(
'
supports baseUrl-only
'
,
()
=>
{
add
({
add
({
...
@@ -45,6 +45,9 @@ describe(getName(), () => {
...
@@ -45,6 +45,9 @@ describe(getName(), () => {
});
});
});
});
describe
(
'
find()
'
,
()
=>
{
describe
(
'
find()
'
,
()
=>
{
beforeEach
(()
=>
{
clear
();
});
it
(
'
warns and returns empty for bad search
'
,
()
=>
{
it
(
'
warns and returns empty for bad search
'
,
()
=>
{
expect
(
find
({
abc
:
'
def
'
}
as
any
)).
toEqual
({});
expect
(
find
({
abc
:
'
def
'
}
as
any
)).
toEqual
({});
});
});
...
...
This diff is collapsed.
Click to expand it.
lib/util/host-rules.ts
+
9
−
8
View file @
52687368
...
@@ -7,15 +7,16 @@ import * as sanitize from './sanitize';
...
@@ -7,15 +7,16 @@ import * as sanitize from './sanitize';
let
hostRules
:
HostRule
[]
=
[];
let
hostRules
:
HostRule
[]
=
[];
const
matchFields
=
[
'
hostName
'
,
'
domainName
'
,
'
baseUrl
'
];
export
function
add
(
params
:
HostRule
):
void
{
export
function
add
(
params
:
HostRule
):
void
{
if
(
params
.
domainName
&&
params
.
hostName
)
{
const
matchedFields
=
matchFields
.
filter
((
field
)
=>
params
[
field
]);
throw
new
Error
(
'
hostRules cannot contain both a domainName and hostName
'
);
if
(
matchedFields
.
length
>
1
)
{
}
throw
new
Error
(
if
(
params
.
domainName
&&
params
.
baseUrl
)
{
`hostRules cannot contain more than one host-matching field. Found: [
${
matchedFields
.
join
(
throw
new
Error
(
'
hostRules cannot contain both a domainName and baseUrl
'
);
'
,
'
}
)}
]`
if
(
params
.
hostName
&&
params
.
baseUrl
)
{
);
throw
new
Error
(
'
hostRules cannot contain both a hostName and baseUrl
'
);
}
}
const
confidentialFields
=
[
'
password
'
,
'
token
'
];
const
confidentialFields
=
[
'
password
'
,
'
token
'
];
let
resolvedHost
=
params
.
baseUrl
||
params
.
hostName
||
params
.
domainName
;
let
resolvedHost
=
params
.
baseUrl
||
params
.
hostName
||
params
.
domainName
;
...
...
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