Skip to content

Commit

Permalink
fix(manager/jsonata): populate extract result with manager config fie…
Browse files Browse the repository at this point in the history
…lds (#33992)
  • Loading branch information
RahulGautamSingh authored Feb 2, 2025
1 parent bfff982 commit 77a5c15
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
35 changes: 35 additions & 0 deletions lib/modules/manager/custom/jsonata/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('modules/manager/custom/jsonata/index', () => {
const res = await extractPackageFile(json, 'unused', config);

expect(res).toMatchObject({
...config,
deps: [
{
depName: 'foo',
Expand Down Expand Up @@ -119,6 +120,7 @@ describe('modules/manager/custom/jsonata/index', () => {
const res = await extractPackageFile(json, 'unused', config);

expect(res).toMatchObject({
...config,
deps: [
{
depName: 'foo',
Expand Down Expand Up @@ -190,6 +192,7 @@ describe('modules/manager/custom/jsonata/index', () => {
const res = await extractPackageFile(json, 'unused', config);

expect(res).toMatchObject({
...config,
deps: [
{
depName: 'foo',
Expand Down Expand Up @@ -313,6 +316,7 @@ describe('modules/manager/custom/jsonata/index', () => {
};
const res = await extractPackageFile('{}', 'unused', config);
expect(res).toMatchObject({
...config,
deps: [
{
depName: 'foo',
Expand All @@ -327,4 +331,35 @@ describe('modules/manager/custom/jsonata/index', () => {
],
});
});

it('populates manager config and jsonata manager template fields in extract result', async () => {
const config = {
fileFormat: 'json',
matchStrings: [`{"depName": "foo"}`, `{"depName": "bar"}`],
currentValueTemplate: '1.0.0',
datasourceTemplate: 'npm',
// should be included present extract result as it is not valid jsonata manager template
// adding here for testing
autoReplaceStringTemplate: `{{{depName}}}:{{{newValue}}}`,
};
const res = await extractPackageFile('{}', 'unused', config);
expect(res).toMatchObject({
deps: [
{
depName: 'foo',
currentValue: '1.0.0',
datasource: 'npm',
},
{
depName: 'bar',
currentValue: '1.0.0',
datasource: 'npm',
},
],
fileFormat: 'json',
matchStrings: [`{"depName": "foo"}`, `{"depName": "bar"}`],
currentValueTemplate: '1.0.0',
datasourceTemplate: 'npm',
});
});
});
18 changes: 16 additions & 2 deletions lib/modules/manager/custom/jsonata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { logger } from '../../../../logger';
import { parseJson } from '../../../../util/common';
import { parseYaml } from '../../../../util/yaml';
import type { PackageFileContent } from '../../types';
import type { JsonataExtractConfig } from './types';
import { validMatchFields } from '../utils';
import type { JSONataManagerTemplates, JsonataExtractConfig } from './types';
import { handleMatching } from './utils';

export const categories: Category[] = ['custom'];
Expand Down Expand Up @@ -47,7 +48,20 @@ export async function extractPackageFile(
return null;
}

return {
const res: PackageFileContent & JSONataManagerTemplates = {
deps,
matchStrings: config.matchStrings,
fileFormat: config.fileFormat,
};

// copy over templates for autoreplace
for (const field of validMatchFields.map(
(f) => `${f}Template` as keyof JSONataManagerTemplates,
)) {
if (config[field]) {
res[field] = config[field];
}
}

return res;
}
1 change: 1 addition & 0 deletions lib/modules/manager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface PackageFileContent<T = Record<string, any>>
skipInstalls?: boolean | null;
matchStrings?: string[];
matchStringsStrategy?: MatchStringsStrategy;
fileFormat?: string;
}

export interface PackageFile<T = Record<string, any>>
Expand Down

0 comments on commit 77a5c15

Please sign in to comment.