Skip to content

Commit

Permalink
fix(datasource/azure-bicep-resource): accomodate changes to response …
Browse files Browse the repository at this point in the history
…schema (#27589)
  • Loading branch information
RahulGautamSingh committed Feb 27, 2024
1 parent 78a1cac commit 81a7762
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 36 deletions.
24 changes: 10 additions & 14 deletions lib/modules/datasource/azure-bicep-resource/index.spec.ts
Expand Up @@ -14,8 +14,8 @@ describe('modules/datasource/azure-bicep-resource/index', () => {
200,
codeBlock`
{
"Resources": {},
"Functions": {}
"resources": {},
"resourceFunctions": {}
}
`,
);
Expand All @@ -36,19 +36,17 @@ describe('modules/datasource/azure-bicep-resource/index', () => {
200,
codeBlock`
{
"Resources": {},
"Functions": {
"resources": {},
"resourceFunctions": {
"microsoft.billing/billingaccounts": {
"2019-10-01-preview": [
{
"RelativePath": "billing/microsoft.billing/2019-10-01-preview/types.json",
"Index": 307
"$ref": "billing/microsoft.billing/2019-10-01-preview/types.json#/304"
}
],
"2020-05-01": [
{
"RelativePath": "billing/microsoft.billing/2020-05-01/types.json",
"Index": 287
"$ref": "billing/microsoft.billing/2020-05-01/types.json#/287"
}
]
}
Expand Down Expand Up @@ -86,17 +84,15 @@ describe('modules/datasource/azure-bicep-resource/index', () => {
200,
codeBlock`
{
"Resources": {
"resources": {
"Microsoft.Storage/storageAccounts@2015-05-01-preview": {
"RelativePath": "storage/microsoft.storage/2015-05-01-preview/types.json",
"Index": 31
"$ref": "storage/microsoft.storage/2015-05-01-preview/types.json#/31"
},
"Microsoft.Storage/storageAccounts@2018-02-01": {
"RelativePath": "storage/microsoft.storage/2018-02-01/types.json",
"Index": 85
"$ref": "storage/microsoft.storage/2018-02-01/types.json#/85"
}
},
"Functions": {}
"resourceFunctions": {}
}
`,
);
Expand Down
27 changes: 5 additions & 22 deletions lib/modules/datasource/azure-bicep-resource/schema.ts
Expand Up @@ -2,37 +2,20 @@ import { z } from 'zod';

export const BicepResourceVersionIndex = z
.object({
Resources: z.record(
z.string(),
z.object({
RelativePath: z.string(),
Index: z.number(),
}),
),
Functions: z.record(
z.string(),
z.record(
z.string(),
z.array(
z.object({
RelativePath: z.string(),
Index: z.number(),
}),
),
),
),
resources: z.record(z.string(), z.unknown()),
resourceFunctions: z.record(z.string(), z.record(z.string(), z.unknown())),
})
.transform(({ Resources, Functions }) => {
.transform(({ resources, resourceFunctions }) => {
const releaseMap = new Map<string, string[]>();

for (const resourceReference of Object.keys(Resources)) {
for (const resourceReference of Object.keys(resources)) {
const [type, version] = resourceReference.toLowerCase().split('@', 2);
const versions = releaseMap.get(type) ?? [];
versions.push(version);
releaseMap.set(type, versions);
}

for (const [type, versionMap] of Object.entries(Functions)) {
for (const [type, versionMap] of Object.entries(resourceFunctions)) {
const versions = Object.keys(versionMap);
releaseMap.set(type, versions);
}
Expand Down

0 comments on commit 81a7762

Please sign in to comment.