From e35a36d4db24b3c9183f55fa7de82a55608ddb1c Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 11 Apr 2024 13:42:02 +0200 Subject: [PATCH 1/7] feat: Add `created` key to json in registry --- CHANGELOG.md | 4 ++++ src/targets/registry.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbdb6f9b..27b71b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.18.0 + +- feat: Registry target now adds key `created` with current timestamp to json file + ## 1.17.2 - No documented changes. diff --git a/src/targets/registry.ts b/src/targets/registry.ts index df651845..0b3bc8fc 100644 --- a/src/targets/registry.ts +++ b/src/targets/registry.ts @@ -362,7 +362,8 @@ export class RegistryTarget extends BaseTarget { ); } // Update the manifest - const updatedManifest = { ...packageManifest, version }; + const updatedManifest: { [key: string]: any } = { ...packageManifest, version }; + updatedManifest.created = new Date().toISOString(); // Add file links if it's a generic app (legacy) if (registryConfig.type === RegistryPackageType.APP) { From b18b6cfe769c6ceed95426aa24c226adf016680b Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 11 Apr 2024 13:51:54 +0200 Subject: [PATCH 2/7] ref: createdAt --- src/targets/registry.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/targets/registry.ts b/src/targets/registry.ts index 0b3bc8fc..558cb80d 100644 --- a/src/targets/registry.ts +++ b/src/targets/registry.ts @@ -362,8 +362,11 @@ export class RegistryTarget extends BaseTarget { ); } // Update the manifest - const updatedManifest: { [key: string]: any } = { ...packageManifest, version }; - updatedManifest.created = new Date().toISOString(); + const updatedManifest: { [key: string]: any } = { + ...packageManifest, + version, + }; + updatedManifest.createdAt = new Date().toISOString(); // Add file links if it's a generic app (legacy) if (registryConfig.type === RegistryPackageType.APP) { From 23eec101301abade862fea9c2bfab01e03c32050 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 11 Apr 2024 13:59:50 +0200 Subject: [PATCH 3/7] ref: Add more type safety --- src/targets/registry.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/targets/registry.ts b/src/targets/registry.ts index 558cb80d..f333b9dc 100644 --- a/src/targets/registry.ts +++ b/src/targets/registry.ts @@ -362,11 +362,15 @@ export class RegistryTarget extends BaseTarget { ); } // Update the manifest - const updatedManifest: { [key: string]: any } = { + const updatedManifest: { + version: string; + createdAt: string; + [key: string]: any; + } = { ...packageManifest, version, + createdAt: new Date().toISOString(), }; - updatedManifest.createdAt = new Date().toISOString(); // Add file links if it's a generic app (legacy) if (registryConfig.type === RegistryPackageType.APP) { From 01ba9d115e89892de14495fdd2f2feeaf924d3cb Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 11 Apr 2024 14:27:45 +0200 Subject: [PATCH 4/7] ref changelog --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27b71b26..41d34496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.18.0 -- feat: Registry target now adds key `created` with current timestamp to json file +- feat: Registry target now adds key `createdAt` with current timestamp to json file ## 1.17.2 @@ -112,7 +112,7 @@ ### Various fixes & improvements -- ref: Pin cocoapods version (#496) by @brustolin +- ref: Pin cocoapods version (#496) by @brustolin ## 1.6.0 @@ -128,14 +128,14 @@ - build(deps): bump semver from 6.3.0 to 6.3.1 (#470) by @dependabot - build(deps): bump @babel/traverse from 7.22.5 to 7.23.2 (#494) by @dependabot - ref: remove volta from CI (#493) by @asottile-sentry -- fix: Handle `{major}.json` and `{minor}.json` symlinks when publishing older versions (#483) by @cleptric +- fix: Handle `{major}.json` and `{minor}.json` symlinks when publishing older versions (#483) by @cleptric - Bump symbol collector 1.12.0 (#491) by @bruno-garcia ## 1.4.4 ### Various fixes & improvements -- fix(brew): Replace version in artifact names with '__VERSION__' to access checksums from mustache (#488) by @romtsn +- fix(brew): Replace version in artifact names with '**VERSION**' to access checksums from mustache (#488) by @romtsn ## 1.4.3 From 12905f5acbcfd312dd836d41b0c85f7216b180ee Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 11 Apr 2024 15:30:59 +0200 Subject: [PATCH 5/7] reset changelog --- CHANGELOG.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41d34496..bbdb6f9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,5 @@ # Changelog -## 1.18.0 - -- feat: Registry target now adds key `createdAt` with current timestamp to json file - ## 1.17.2 - No documented changes. @@ -112,7 +108,7 @@ ### Various fixes & improvements -- ref: Pin cocoapods version (#496) by @brustolin +- ref: Pin cocoapods version (#496) by @brustolin ## 1.6.0 @@ -128,14 +124,14 @@ - build(deps): bump semver from 6.3.0 to 6.3.1 (#470) by @dependabot - build(deps): bump @babel/traverse from 7.22.5 to 7.23.2 (#494) by @dependabot - ref: remove volta from CI (#493) by @asottile-sentry -- fix: Handle `{major}.json` and `{minor}.json` symlinks when publishing older versions (#483) by @cleptric +- fix: Handle `{major}.json` and `{minor}.json` symlinks when publishing older versions (#483) by @cleptric - Bump symbol collector 1.12.0 (#491) by @bruno-garcia ## 1.4.4 ### Various fixes & improvements -- fix(brew): Replace version in artifact names with '**VERSION**' to access checksums from mustache (#488) by @romtsn +- fix(brew): Replace version in artifact names with '__VERSION__' to access checksums from mustache (#488) by @romtsn ## 1.4.3 From c06bd7567d5cc0d173d677aed7ba2228481f4352 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 11 Apr 2024 15:41:51 +0200 Subject: [PATCH 6/7] Add simple unit test --- src/targets/__tests__/registry.test.ts | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/targets/__tests__/registry.test.ts diff --git a/src/targets/__tests__/registry.test.ts b/src/targets/__tests__/registry.test.ts new file mode 100644 index 00000000..7824ce6e --- /dev/null +++ b/src/targets/__tests__/registry.test.ts @@ -0,0 +1,35 @@ +import { RegistryConfig, RegistryTarget } from '../registry'; +import { NoneArtifactProvider } from '../../artifact_providers/none'; +import { RegistryPackageType } from '../../utils/registry'; + +describe('getUpdatedManifest', () => { + const target = new RegistryTarget( + { name: 'pypi' }, + new NoneArtifactProvider(), + { owner: 'testSourceOwner', repo: 'testSourceRepo' } + ); + + it('check if createdAt exists', async () => { + const registryConfig: RegistryConfig = { + type: RegistryPackageType.SDK, + canonicalName: 'example-package', + }; + const packageManifest = { + canonical: 'example-package', + }; + const canonical = 'example-package'; + const version = '1.2.3'; + const revision = 'abc123'; + + const updatedManifest = await target.getUpdatedManifest( + registryConfig, + packageManifest, + canonical, + version, + revision + ); + + // check if property createdAt exists + expect(updatedManifest).toHaveProperty('createdAt'); + }); +}); From 46f078836439947804264f0b7257db7e42abbc9e Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 11 Apr 2024 15:48:28 +0200 Subject: [PATCH 7/7] Add mock --- src/targets/__tests__/registry.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/targets/__tests__/registry.test.ts b/src/targets/__tests__/registry.test.ts index 7824ce6e..1ec3a3de 100644 --- a/src/targets/__tests__/registry.test.ts +++ b/src/targets/__tests__/registry.test.ts @@ -1,8 +1,21 @@ +jest.mock('../../utils/githubApi.ts'); +import { getGitHubClient } from '../../utils/githubApi'; import { RegistryConfig, RegistryTarget } from '../registry'; import { NoneArtifactProvider } from '../../artifact_providers/none'; import { RegistryPackageType } from '../../utils/registry'; describe('getUpdatedManifest', () => { + let mockClient: jest.Mock; + + beforeEach(() => { + jest.resetAllMocks(); + mockClient = jest.fn(); + (getGitHubClient as jest.MockedFunction< + typeof getGitHubClient + // @ts-ignore we only need to mock a subset + >).mockReturnValue({ graphql: mockClient }); + }); + const target = new RegistryTarget( { name: 'pypi' }, new NoneArtifactProvider(),