Conversation
The cache-first, embedded-fallback pattern for container pin resolution was duplicated between applyContainerPins (docker.go) and resolveContainerDigest (awf_helpers.go). Extract lookupContainerPin into action_pins.go and use it in both callers. This reduces each call site from 4-6 lines to a single conditional, and ensures both code paths share the same lookup logic. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
1 similar comment
|
Hey One thing that would make this even more solid:
If you'd like a hand, you can assign this prompt to your coding agent:
|
There was a problem hiding this comment.
Pull request overview
Refactors container pin resolution by extracting a shared lookupContainerPin helper to remove duplicated “cache-first, embedded-fallback” logic introduced in #27762.
Changes:
- Added
lookupContainerPin(image, cache)helper inpkg/workflow/action_pins.go. - Updated
applyContainerPinsto use the helper for pinned image resolution. - Updated
resolveContainerDigestto use the helper for digest resolution.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/action_pins.go | Introduces shared helper for container pin lookup (cache then embedded). |
| pkg/workflow/docker.go | Uses helper inside applyContainerPins to resolve pinned image refs and manifest entries. |
| pkg/workflow/awf_helpers.go | Uses helper inside resolveContainerDigest for AWF image-tag digest metadata. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 2
| for i, img := range images { | ||
| if cache != nil { | ||
| if pin, ok := cache.GetContainerPin(img); ok && pin.PinnedImage != "" { | ||
| result[i] = pin.PinnedImage | ||
| pins[i] = GHAWManifestContainer(pin) | ||
| dockerLog.Printf("Pinned container image: %s -> %s", img, pin.PinnedImage) | ||
| continue | ||
| } | ||
| } | ||
| if embeddedPin, ok := getEmbeddedContainerPin(img); ok && embeddedPin.PinnedImage != "" { | ||
| result[i] = embeddedPin.PinnedImage | ||
| pins[i] = GHAWManifestContainer(embeddedPin) | ||
| dockerLog.Printf("Pinned container image from embedded pins: %s -> %s", img, embeddedPin.PinnedImage) | ||
| if pin, ok := lookupContainerPin(img, cache); ok && pin.PinnedImage != "" { | ||
| result[i] = pin.PinnedImage | ||
| pins[i] = GHAWManifestContainer(pin) | ||
| dockerLog.Printf("Pinned container image: %s -> %s", img, pin.PinnedImage) | ||
| continue |
| // lookupContainerPin returns the ContainerPin for the given image, checking cache first | ||
| // then falling back to embedded pins. Returns false if the image is not pinned. | ||
| func lookupContainerPin(image string, cache *ActionCache) (ContainerPin, bool) { | ||
| if cache != nil { | ||
| if pin, ok := cache.GetContainerPin(image); ok { | ||
| return pin, true | ||
| } | ||
| } | ||
| if pin, ok := getEmbeddedContainerPin(image); ok { | ||
| return ContainerPin(pin), true | ||
| } |
Overview
Follow-up simplification to #27762 ("Pin builtin container images by digest"). The cache-first, embedded-fallback pattern for container pin resolution was introduced in two places with identical structure but different return fields used by each caller.
Files Simplified
pkg/workflow/action_pins.go— addedlookupContainerPinhelperpkg/workflow/docker.go—applyContainerPinsuseslookupContainerPinpkg/workflow/awf_helpers.go—resolveContainerDigestuseslookupContainerPinImprovement Made
Reduced Duplication — Extracted
lookupContainerPinhelperBoth
applyContainerPins(docker.go) andresolveContainerDigest(awf_helpers.go) implemented the same cache-first, embedded-fallback logic:The new helper in
action_pins.go:Changes Based On
Recent changes from:
Testing
TestApplyContainerPins,TestBuildAWFImageTagWithDigests,TestBuildAWFArgs_ImageTagIncludesDigests,TestGetContainerPin_ReturnsPinnedImage)go vetcleanmake build)Review Focus
Please verify:
lookupContainerPincorrectly unifies both lookup patternsAutomated by Code Simplifier Agent — analyzing code from the last 24 hours