Skip to content

Add CacheMetadata with repository_id to cache v2 requests #2093

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fkorotkov
Copy link

@fkorotkov fkorotkov commented Jun 18, 2025

The V2 cache supports passing metadata so let's pass it along.

Fixes #2094

- Add optional CacheMetadata to CreateCacheEntry and FinalizeCacheEntryUpload requests
- Include repository_id from GITHUB_REPOSITORY_ID environment variable when available
- Gracefully handle missing environment variable by sending undefined metadata
- Update tests to verify both scenarios with and without repository_id
@Copilot Copilot AI review requested due to automatic review settings June 18, 2025 12:53
@fkorotkov fkorotkov requested a review from a team as a code owner June 18, 2025 12:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for passing cache metadata (specifically the repositoryId) to Cache V2 API requests.

  • Introduced getCacheMetadata() to read GITHUB_REPOSITORY_ID and build a CacheMetadata object.
  • Updated saveCacheV2 to include metadata in both create and finalize cache entry requests.
  • Extended tests to set GITHUB_REPOSITORY_ID and assert that metadata is included.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/cache/src/cache.ts Added import of CacheMetadata, implemented getCacheMetadata(), and wired metadata into V2 requests.
packages/cache/tests/saveCacheV2.test.ts Set GITHUB_REPOSITORY_ID in tests and added expectations for the metadata field.
Comments suppressed due to low confidence (3)

packages/cache/src/cache.ts:55

  • Consider adding a JSDoc comment for getCacheMetadata to explain what fields are included (e.g., repositoryId and scope) and under what conditions it returns undefined.
function getCacheMetadata(): CacheMetadata | undefined {

packages/cache/tests/saveCacheV2.test.ts:30

  • Add a test case for when GITHUB_REPOSITORY_ID is not set to verify that metadata is omitted (i.e., undefined) in the request.
  process.env['GITHUB_REPOSITORY_ID'] = '123456789'

packages/cache/src/cache.ts:56

  • Verify that repositoryId matches the expected type in CacheMetadata (e.g., number vs. string). If the schema requires a numeric ID, parse it with Number() or parseInt() and handle NaN cases.
  const repositoryId = process.env['GITHUB_REPOSITORY_ID']

Comment on lines 539 to +540
const request: CreateCacheEntryRequest = {
metadata: getCacheMetadata(),
Copy link
Preview

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

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

[nitpick] Since getCacheMetadata() is called twice in this function, consider invoking it once (e.g., const metadata = getCacheMetadata()) and reusing the same object for both requests to improve readability and consistency.

Suggested change
const request: CreateCacheEntryRequest = {
metadata: getCacheMetadata(),
const metadata = getCacheMetadata();
const request: CreateCacheEntryRequest = {
metadata,

Copilot uses AI. Check for mistakes.

Comment on lines 127 to 134
expect(createCacheEntryMock).toHaveBeenCalledWith({
metadata: {
repositoryId: '123456789',
scope: []
},
key,
version: cacheVersion
})
Copy link
Preview

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

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

[nitpick] To reduce duplication and improve clarity, extract the expected metadata object into a constant or use expect.objectContaining({ metadata }) so tests remain concise.

Suggested change
expect(createCacheEntryMock).toHaveBeenCalledWith({
metadata: {
repositoryId: '123456789',
scope: []
},
key,
version: cacheVersion
})
const metadata = {
repositoryId: '123456789',
scope: []
};
expect(createCacheEntryMock).toHaveBeenCalledWith({
metadata,
key,
version: cacheVersion
});

Copilot uses AI. Check for mistakes.

@fkorotkov
Copy link
Author

FYI @GhadimiR @Link-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass CacheMetadata along the cache v2 save requests
1 participant