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(crate): Support releaseTimestamp #31467

Merged
merged 30 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5ce274d
feat(datasource): Post-fetch interceptors for candidate release items
zharinov Sep 5, 2024
c1ada9c
Fix lint
zharinov Sep 5, 2024
0b72ad6
Merge branch 'main' into feat/datasource-release-interception
zharinov Sep 6, 2024
8e142a2
Move helper and types to datasource
zharinov Sep 6, 2024
770b4cb
Fix test
zharinov Sep 6, 2024
80350ce
Fix eslint
zharinov Sep 6, 2024
55100db
Merge branch 'main' into feat/datasource-release-interception
zharinov Sep 6, 2024
132987b
Fix renaming
zharinov Sep 7, 2024
a4686d8
Remove `currentValue` from config
zharinov Sep 7, 2024
45925fb
Fixes
zharinov Sep 8, 2024
8384f67
fix
zharinov Sep 8, 2024
ea941ea
Add debug log
zharinov Sep 9, 2024
35a41ae
Merge branch 'main' into feat/datasource-release-interception
zharinov Sep 9, 2024
f0f9fd7
Add comment
zharinov Sep 9, 2024
a545bc5
Merge branch 'main' into feat/datasource-release-interception
zharinov Sep 12, 2024
98eaddb
Merge branch 'main' into feat/datasource-release-interception
zharinov Sep 16, 2024
61ae05f
Log warnings once
zharinov Sep 16, 2024
474b1bf
Merge branch 'main' into feat/datasource-release-interception
zharinov Sep 16, 2024
0615dab
Merge branch 'main' into feat/datasource-release-interception
zharinov Sep 18, 2024
7911006
Add datasource to debug log
zharinov Sep 16, 2024
76c0712
feat(crate): Support `releaseTimestamp`
zharinov Sep 18, 2024
a12b75b
Add tests
zharinov Sep 18, 2024
cd38acc
Merge branch 'main' into feat/crates-release-timestamps
zharinov Sep 18, 2024
39abee3
Merge branch 'main' into feat/crates-release-timestamps
rarkins Sep 19, 2024
b4f7f6d
Merge branch 'main' into feat/crates-release-timestamps
zharinov Sep 19, 2024
aae5cef
Increase TTL to 1 week
zharinov Sep 21, 2024
52e697b
Merge branch 'main' into feat/crates-release-timestamps
zharinov Sep 26, 2024
acb2369
Fix types
zharinov Sep 26, 2024
334ece4
Merge branch 'main' into feat/crates-release-timestamps
zharinov Oct 9, 2024
e9e9e8c
Extract schema
zharinov Oct 9, 2024
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
42 changes: 42 additions & 0 deletions lib/modules/datasource/crate/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,46 @@ describe('modules/datasource/crate/index', () => {
).toReject();
});
});

describe('postprocessRelease', () => {
const datasource = new CrateDatasource();

it('no-op for registries other than crates.io', async () => {
const releaseOrig = { version: '4.5.17' };

const res = await datasource.postprocessRelease(
{
packageName: 'clap',
registryUrl: 'https://example.com',
},
releaseOrig,
);

expect(res).toBe(releaseOrig);
});

it('fetches releaseTimestamp', async () => {
httpMock
.scope(API_BASE_URL)
.get('/crates/clap/4.5.17')
.reply(200, {
version: {
created_at: '2024-09-04T19:16:41.355243+00:00',
},
});

const res = await datasource.postprocessRelease(
{
packageName: 'clap',
registryUrl: 'https://crates.io',
},
{ version: '4.5.17' },
);

expect(res).toEqual({
version: '4.5.17',
releaseTimestamp: '2024-09-04T19:16:41.355243+00:00',
});
});
});
});
36 changes: 35 additions & 1 deletion lib/modules/datasource/crate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import { newlineRegex, regEx } from '../../../util/regex';
import { joinUrlParts, parseUrl } from '../../../util/url';
import * as cargoVersioning from '../../versioning/cargo';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
import type {
GetReleasesConfig,
PostprocessReleaseConfig,
PostprocessReleaseResult,
Release,
ReleaseResult,
} from '../types';
import { ReleaseTimestampSchema } from './schema';
import type {
CrateMetadata,
CrateRecord,
Expand Down Expand Up @@ -371,4 +378,31 @@ export class CrateDatasource extends Datasource {

return [packageName.slice(0, 2), packageName.slice(2, 4), packageName];
}

@cache({
namespace: `datasource-crate`,
key: (
{ registryUrl, packageName }: PostprocessReleaseConfig,
{ version }: Release,
) => `postprocessRelease:${registryUrl}:${packageName}:${version}`,
ttlMinutes: 7 * 24 * 60,
cacheable: ({ registryUrl }: PostprocessReleaseConfig, _: Release) =>
registryUrl === 'https://crates.io',
})
override async postprocessRelease(
{ packageName, registryUrl }: PostprocessReleaseConfig,
release: Release,
): Promise<PostprocessReleaseResult> {
if (registryUrl !== 'https://crates.io') {
return release;
}

const url = `https://crates.io/api/v1/crates/${packageName}/${release.version}`;
const { body: releaseTimestamp } = await this.http.getJson(
url,
ReleaseTimestampSchema,
);
release.releaseTimestamp = releaseTimestamp;
return release;
}
}
11 changes: 11 additions & 0 deletions lib/modules/datasource/crate/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from 'zod';

export const ReleaseTimestampSchema = z
.object({
version: z.object({
created_at: z.string(),
}),
})
.transform(({ version: { created_at } }) => created_at)
.nullable()
.catch(null);