Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datasource/bicep): suppress resourceFunctions #28379

Merged
61 changes: 45 additions & 16 deletions lib/modules/datasource/azure-bicep-resource/index.spec.ts
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
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