Skip to content

Commit

Permalink
Support digest in custom datasource
Browse files Browse the repository at this point in the history
To support digests a datasource has to implement the getDigest method.
The value itself can be provided in the getReleases method.
  • Loading branch information
fstehle committed Dec 14, 2023
1 parent e1a6dd1 commit c470002
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/modules/datasource/custom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import is from '@sindresorhus/is';
import jsonata from 'jsonata';
import { logger } from '../../../logger';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import type { GetReleasesConfig, ReleaseResult, DigestConfig } from '../types';
import { fetchers } from './formats';
import { ReleaseResultZodSchema } from './schema';
import { getCustomConfig } from './utils';
Expand Down Expand Up @@ -57,4 +57,14 @@ export class CustomDatasource extends Datasource {
return null;
}
}

override getDigest(
{ packageName: repo, registryUrl }: Partial<DigestConfig>,
newValue?: string,
): Promise<string | null> {
// Return null here to support setting a digest: value can be provided digest in getReleases
return new Promise<null>((resolve) => {
resolve(null);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ exports[`workers/repository/process/lookup/index .lookupUpdates() handles digest
}
`;

exports[`workers/repository/process/lookup/index .lookupUpdates() handles digest update for custom datasource 1`] = `
{
"currentVersion": "1.0.0",
"fixedVersion": "1.0.0",
"updates": [
{
"newDigest": "0123456789abcdef",
"newValue": "1.0.0",
"updateType": "digest",
},
],
"versioning": "npm",
"warnings": [],
}
`;

exports[`workers/repository/process/lookup/index .lookupUpdates() handles digest update for non-version 1`] = `
{
"updates": [
Expand Down
31 changes: 31 additions & 0 deletions lib/workers/repository/process/lookup/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as httpMock from '../../../../../test/http-mock';
import { partial } from '../../../../../test/util';
import { getConfig } from '../../../../config/defaults';
import { CONFIG_VALIDATION } from '../../../../constants/error-messages';
import { CustomDatasource } from "../../../../modules/datasource/custom";
import { DockerDatasource } from '../../../../modules/datasource/docker';
import { GitRefsDatasource } from '../../../../modules/datasource/git-refs';
import { GithubReleasesDatasource } from '../../../../modules/datasource/github-releases';
Expand Down Expand Up @@ -56,6 +57,11 @@ describe('workers/repository/process/lookup/index', () => {
'getReleases',
);

const getCustomDatasourceReleases = jest.spyOn(
CustomDatasource.prototype,
'getReleases',
);

const getDockerDigest = jest.spyOn(DockerDatasource.prototype, 'getDigest');

beforeEach(() => {
Expand Down Expand Up @@ -1938,6 +1944,31 @@ describe('workers/repository/process/lookup/index', () => {
});
});

it('handles digest update for custom datasource', async () => {
config.currentValue = '1.0.0';
config.packageName = 'my-package';
config.datasource = CustomDatasource.id;
config.currentDigest = 'zzzzzzzzzzzzzzz';
getCustomDatasourceReleases.mockResolvedValueOnce({
releases: [
{
version: '1.0.0',
newDigest: '0123456789abcdef',
}
],
});
const res = await lookup.lookupUpdates(config);
expect(res).toMatchSnapshot({
updates: [
{
newDigest: '0123456789abcdef',
newValue: '1.0.0',
updateType: 'digest',
},
],
});
});

it('handles digest update for non-version', async () => {
config.currentValue = 'alpine';
config.packageName = 'node';
Expand Down

0 comments on commit c470002

Please sign in to comment.