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

feat(datasource/custom): Support digest in custom datasource #28760

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/modules/datasource/custom/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,4 +697,13 @@ describe('modules/datasource/custom/index', () => {
expect(result).toEqual(expected);
});
});

describe('getDigest', () => {
it('returns null as digest should be provided in releases', async () => {
const digest = await new CustomDatasource().getDigest({
packageName: 'my-package',
});
expect(digest).toBeNull();
});
});
});
10 changes: 9 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 { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types';
import { fetchers } from './formats';
import { ReleaseResultZodSchema } from './schema';
import { getCustomConfig } from './utils';
Expand Down Expand Up @@ -57,4 +57,12 @@ export class CustomDatasource extends Datasource {
return null;
}
}

override getDigest(
{ packageName }: DigestConfig,
newValue?: string,
): Promise<string | null> {
// Return null here to support setting a digest: value can be provided digest in getReleases
return Promise.resolve(null);
}
}
33 changes: 33 additions & 0 deletions lib/workers/repository/process/lookup/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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 @@ -62,6 +63,11 @@ describe('workers/repository/process/lookup/index', () => {

const getMavenReleases = jest.spyOn(MavenDatasource.prototype, 'getReleases');

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

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

beforeEach(() => {
Expand Down Expand Up @@ -3849,6 +3855,33 @@ 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 { updates } = await Result.wrap(
lookup.lookupUpdates(config),
).unwrapOrThrow();

expect(updates).toEqual([
{
newDigest: '0123456789abcdef',
newValue: '1.0.0',
updateType: 'digest',
},
]);
});

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