-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: main
Are you sure you want to change the base?
Conversation
- 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
There was a problem hiding this 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 readGITHUB_REPOSITORY_ID
and build aCacheMetadata
object. - Updated
saveCacheV2
to includemetadata
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
andscope
) and under what conditions it returnsundefined
.
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 thatmetadata
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 inCacheMetadata
(e.g., number vs. string). If the schema requires a numeric ID, parse it withNumber()
orparseInt()
and handle NaN cases.
const repositoryId = process.env['GITHUB_REPOSITORY_ID']
const request: CreateCacheEntryRequest = { | ||
metadata: getCacheMetadata(), |
There was a problem hiding this comment.
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.
const request: CreateCacheEntryRequest = { | |
metadata: getCacheMetadata(), | |
const metadata = getCacheMetadata(); | |
const request: CreateCacheEntryRequest = { | |
metadata, |
Copilot uses AI. Check for mistakes.
expect(createCacheEntryMock).toHaveBeenCalledWith({ | ||
metadata: { | ||
repositoryId: '123456789', | ||
scope: [] | ||
}, | ||
key, | ||
version: cacheVersion | ||
}) |
There was a problem hiding this comment.
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.
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.
The V2 cache supports passing
metadata
so let's pass it along.Fixes #2094