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
b1023296
Unverified
Commit
b1023296
authored
Nov 10, 2023
by
Sergei Zharinov
Committed by
GitHub
Nov 10, 2023
Browse files
Options
Downloads
Patches
Plain Diff
refactor(hex): Datasource schema validation (#25009)
parent
9a55d753
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/modules/datasource/hex/index.ts
+9
-39
9 additions, 39 deletions
lib/modules/datasource/hex/index.ts
lib/modules/datasource/hex/schema.ts
+47
-0
47 additions, 0 deletions
lib/modules/datasource/hex/schema.ts
lib/modules/datasource/hex/types.ts
+0
-8
0 additions, 8 deletions
lib/modules/datasource/hex/types.ts
with
56 additions
and
47 deletions
lib/modules/datasource/hex/index.ts
+
9
−
39
View file @
b1023296
import
{
logger
}
from
'
../../../logger
'
;
import
{
logger
}
from
'
../../../logger
'
;
import
{
cache
}
from
'
../../../util/cache/package/decorator
'
;
import
{
cache
}
from
'
../../../util/cache/package/decorator
'
;
import
type
{
HttpResponse
}
from
'
../../../util/http/types
'
;
import
*
as
hexVersioning
from
'
../../versioning/hex
'
;
import
*
as
hexVersioning
from
'
../../versioning/hex
'
;
import
{
Datasource
}
from
'
../datasource
'
;
import
{
Datasource
}
from
'
../datasource
'
;
import
type
{
GetReleasesConfig
,
ReleaseResult
}
from
'
../types
'
;
import
type
{
GetReleasesConfig
,
ReleaseResult
}
from
'
../types
'
;
import
type
{
HexRelease
}
from
'
./
types
'
;
import
{
HexRelease
}
from
'
./
schema
'
;
export
class
HexDatasource
extends
Datasource
{
export
class
HexDatasource
extends
Datasource
{
static
readonly
id
=
'
hex
'
;
static
readonly
id
=
'
hex
'
;
...
@@ -43,44 +42,15 @@ export class HexDatasource extends Datasource {
...
@@ -43,44 +42,15 @@ export class HexDatasource extends Datasource {
:
''
;
:
''
;
const
hexUrl
=
`
${
registryUrl
}
api/
${
organizationUrlPrefix
}
packages/
${
hexPackageName
}
`
;
const
hexUrl
=
`
${
registryUrl
}
api/
${
organizationUrlPrefix
}
packages/
${
hexPackageName
}
`
;
let
response
:
HttpResponse
<
HexRelease
>
;
const
{
val
:
result
,
err
}
=
await
this
.
http
try
{
.
getJsonSafe
(
hexUrl
,
HexRelease
)
response
=
await
this
.
http
.
getJson
<
HexRelease
>
(
hexUrl
);
.
onError
((
err
)
=>
{
}
catch
(
err
)
{
logger
.
warn
({
datasource
:
'
hex
'
,
packageName
,
err
},
`Error fetching
${
hexUrl
}
`
);
// prettier-ignore
this
.
handleGenericErrors
(
err
);
})
}
.
unwrap
();
const
hexRelease
:
HexRelease
=
response
.
body
;
if
(
!
hexRelease
)
{
logger
.
warn
({
datasource
:
'
hex
'
,
packageName
},
`Invalid response body`
);
return
null
;
}
const
{
releases
=
[],
html_url
:
homepage
,
meta
}
=
hexRelease
;
if
(
releases
.
length
===
0
)
{
logger
.
debug
(
`No versions found for
${
hexPackageName
}
(
${
hexUrl
}
)`
);
// prettier-ignore
return
null
;
}
const
result
:
ReleaseResult
=
{
releases
:
releases
.
map
(({
version
,
inserted_at
})
=>
inserted_at
?
{
version
,
releaseTimestamp
:
inserted_at
,
}
:
{
version
},
),
};
if
(
homepage
)
{
result
.
homepage
=
homepage
;
}
if
(
meta
?.
links
?.
Github
)
{
if
(
err
)
{
result
.
sourceUrl
=
meta
?.
links
?.
Github
;
this
.
handleGenericErrors
(
err
)
;
}
}
return
result
;
return
result
;
...
...
This diff is collapsed.
Click to expand it.
lib/modules/datasource/hex/schema.ts
0 → 100644
+
47
−
0
View file @
b1023296
import
{
z
}
from
'
zod
'
;
import
{
LooseArray
}
from
'
../../../util/schema-utils
'
;
import
type
{
Release
,
ReleaseResult
}
from
'
../types
'
;
export
const
HexRelease
=
z
.
object
({
html_url
:
z
.
string
().
optional
(),
meta
:
z
.
object
({
links
:
z
.
object
({
Github
:
z
.
string
(),
}),
})
.
nullable
()
.
catch
(
null
),
releases
:
LooseArray
(
z
.
object
({
version
:
z
.
string
(),
inserted_at
:
z
.
string
().
optional
(),
}),
).
refine
((
releases
)
=>
releases
.
length
>
0
,
'
No releases found
'
),
})
.
transform
((
hexResponse
):
ReleaseResult
=>
{
const
releases
:
Release
[]
=
hexResponse
.
releases
.
map
(
({
version
,
inserted_at
:
releaseTimestamp
}):
Release
=>
{
const
release
:
Release
=
{
version
};
if
(
releaseTimestamp
)
{
release
.
releaseTimestamp
=
releaseTimestamp
;
}
return
release
;
},
);
const
releaseResult
:
ReleaseResult
=
{
releases
};
if
(
hexResponse
.
html_url
)
{
releaseResult
.
homepage
=
hexResponse
.
html_url
;
}
if
(
hexResponse
.
meta
?.
links
?.
Github
)
{
releaseResult
.
sourceUrl
=
hexResponse
.
meta
.
links
.
Github
;
}
return
releaseResult
;
});
This diff is collapsed.
Click to expand it.
lib/modules/datasource/hex/types.ts
deleted
100644 → 0
+
0
−
8
View file @
9a55d753
export
interface
HexRelease
{
html_url
:
string
;
meta
?:
{
links
?:
Record
<
string
,
string
>
};
releases
?:
{
version
:
string
;
inserted_at
?:
string
;
}[];
}
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