Skip to content

Commit

Permalink
fix(datasource/bicep): suppress resourceFunctions (#28379)
Browse files Browse the repository at this point in the history
  • Loading branch information
moerketh authored Apr 16, 2024
1 parent c3635f7 commit fbe88c2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
61 changes: 45 additions & 16 deletions lib/modules/datasource/azure-bicep-resource/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('modules/datasource/azure-bicep-resource/index', () => {
expect(result).toBeNull();
});

it('should return versions when package is a function', async () => {
it('should return null when package is a function', async () => {
httpMock
.scope(gitHubHost)
.get(indexPath)
Expand Down Expand Up @@ -57,23 +57,10 @@ describe('modules/datasource/azure-bicep-resource/index', () => {

const azureBicepResourceDatasource = new AzureBicepResourceDatasource();
const result = await azureBicepResourceDatasource.getReleases({
packageName: 'Microsoft.Billing/billingAccounts',
packageName: 'unknown',
});

expect(result).toEqual({
releases: [
{
version: '2019-10-01-preview',
changelogUrl:
'https://learn.microsoft.com/en-us/azure/templates/microsoft.billing/change-log/billingaccounts#2019-10-01-preview',
},
{
version: '2020-05-01',
changelogUrl:
'https://learn.microsoft.com/en-us/azure/templates/microsoft.billing/change-log/billingaccounts#2020-05-01',
},
],
});
expect(result).toBeNull();
});

it('should return versions when package is a resource', async () => {
Expand Down Expand Up @@ -117,4 +104,46 @@ describe('modules/datasource/azure-bicep-resource/index', () => {
],
});
});

it('should return versions when package is a resource and a function', async () => {
httpMock
.scope(gitHubHost)
.get(indexPath)
.reply(
200,
codeBlock`
{
"resources": {
"Microsoft.OperationalInsights/workspaces@2023-09-01": {
"$ref": "operationalinsights/microsoft.operationalinsights/2023-09-01/types.json#/31"
}
},
"resourceFunctions": {
"microsoft.operationalinsights/workspaces": {
"2015-03-20": [
{
"$ref": "operationalinsights/workspaces/2015-03-20/types.json#/304"
}
]
}
}
}
`,
);

const azureBicepResourceDatasource = new AzureBicepResourceDatasource();
const result = await azureBicepResourceDatasource.getReleases({
packageName: 'Microsoft.OperationalInsights/workspaces',
});

expect(result).toEqual({
releases: [
{
version: '2023-09-01',
changelogUrl:
'https://learn.microsoft.com/en-us/azure/templates/microsoft.operationalinsights/change-log/workspaces#2023-09-01',
},
],
});
});
});
8 changes: 1 addition & 7 deletions lib/modules/datasource/azure-bicep-resource/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { z } from 'zod';
export const BicepResourceVersionIndex = z
.object({
resources: z.record(z.string(), z.unknown()),
resourceFunctions: z.record(z.string(), z.record(z.string(), z.unknown())),
})
.transform(({ resources, resourceFunctions }) => {
.transform(({ resources }) => {
const releaseMap = new Map<string, string[]>();

for (const resourceReference of Object.keys(resources)) {
Expand All @@ -15,11 +14,6 @@ export const BicepResourceVersionIndex = z
releaseMap.set(type, versions);
}

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

return Object.fromEntries(releaseMap);
});

Expand Down

0 comments on commit fbe88c2

Please sign in to comment.