Skip to content

Commit

Permalink
feat(datasource/custom): Support digest in custom datasource (#28760)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabian Stehle <fabian.stehle-extern@moia.io>
Co-authored-by: Fabian Stehle <fabi@fstehle.de>
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
5 people authored May 1, 2024
1 parent 3374bd1 commit e3675f1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
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

0 comments on commit e3675f1

Please sign in to comment.