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 #26299

Closed
Closed
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();
});
});
});
11 changes: 10 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,13 @@ 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
// istanbul ignore next
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed, it seems there's a test for it

This comment was marked as outdated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// istanbul ignore next

return Promise.resolve(null);
}
}
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 @@ -5,6 +5,7 @@
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 @@

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,31 @@
});
});

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).toMatchObject({

Check failure on line 3872 in lib/workers/repository/process/lookup/index.spec.ts

View workflow job for this annotation

GitHub Actions / test (10/16)

workers/repository/process/lookup/index › .lookupUpdates() › handles digest update for custom datasource

expect(received).toMatchObject(expected) - Expected - 1 + Received + 10 - Object { + Result { + "res": Object { + "ok": true, + "val": Object { + "currentVersion": "1.0.0", + "fixedVersion": "1.0.0", "updates": Array [ Object { "newDigest": "0123456789abcdef", "newValue": "1.0.0", "updateType": "digest", }, ], + "versioning": "npm", + "warnings": Array [], + }, + }, } at Object.<anonymous> (lib/workers/repository/process/lookup/index.spec.ts:3872:19)
updates: [
{
newDigest: '0123456789abcdef',
newValue: '1.0.0',
updateType: 'digest',
},
],
});
Comment on lines +3871 to +3880
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const res = await lookup.lookupUpdates(config);
expect(res).toMatchObject({
updates: [
{
newDigest: '0123456789abcdef',
newValue: '1.0.0',
updateType: 'digest',
},
],
});
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
Loading