fix(image-link): parse image refs explicitly and add GHCR/Quay support#191
Open
coding-shalabh wants to merge 1 commit into
Open
fix(image-link): parse image refs explicitly and add GHCR/Quay support#191coding-shalabh wants to merge 1 commit into
coding-shalabh wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the image link provider to replace three positional regexes with an explicit parseImageRef() helper that follows Docker's reference resolution rules (a first path component is a registry hostname iff it contains ., :, or equals localhost). This fixes #179, where references like nrt.vultrcr.com/wulicoco/code-sync previously fell through silently, and adds explicit link targets for GHCR and Quay.io.
Changes:
- New
parseImageRef()parser plusbuildLinkUri()dispatcher; existing Docker Hub / MCR link targets and ranges are preserved. - Adds GHCR (
ghcr.io/<owner>/<repo>→ GitHub package page) and Quay (quay.io/<owner>/<repo>→ quay.io repository page) link generation, plusghcr/quaytelemetry values. - Adds three test cases covering GHCR, Quay, and the negative case for unrecognized private registries (including the exact reference from #179).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/service/providers/ImageLinkProvider.ts | Replaces three regex branches with explicit reference parsing and adds GHCR/Quay link builders. |
| src/test/providers/ImageLinkProvider.test.ts | Adds positive tests for GHCR and Quay and a negative test locking in #179 behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Refactor the regex-based matcher in ImageLinkProvider into an explicit Docker image-reference parser that follows the registry-resolution rules documented in github.com/distribution/reference: a path component before the first '/' is treated as a registry hostname when it contains '.', contains ':', or is exactly 'localhost'. The previous matchers worked correctly for the public Docker Hub / namespaced / MCR cases but silently produced no link for any image on another registry, even well-known public ones. With the new parser: - Docker Hub official, namespaced, and MCR cases keep their existing link targets and ranges (all 119 prior tests pass unchanged). - ghcr.io/<owner>/<repo>[:tag] now links to the package page on github.com (.../pkgs/container/<repo>). - quay.io/<owner>/<repo>[:tag] now links to its repository page. - Unrecognized private registries (e.g. nrt.vultrcr.com/..., localhost:5000/..., registry.gitlab.com/...) explicitly return no link rather than relying on the namespace-regex incidentally rejecting them. Adds three new test cases covering GHCR, Quay, and the unrecognized private-registry scenario from issue microsoft#179. Fixes microsoft#179
dcd1deb to
0b7d6d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #179.
What the issue was
The previous implementation matched image references with three positional regexes:
These worked for Docker Hub / namespaced / MCR cases but for any other registry —
ghcr.io,quay.io,localhost:5000,nrt.vultrcr.com/...— they all silently fell through to "no link." The user filing the issue saw what looked like a wrong link because they expected some clickable hint and got none. The underlying gap is real even though the symptom they described isn't exactly what happens.What this PR does
1. Refactors the regex jungle into an explicit image-reference parser. A new
parseImageRef()helper follows the rules documented at github.com/distribution/reference: a path component before the first/is treated as a registry hostname if it contains., contains:, or is exactlylocalhost. Otherwise the reference is resolved against Docker Hub.2. Preserves every existing link target. All 119 prior tests pass unchanged — Docker Hub official (
alpine), namespaced (library/alpine), MCR (mcr.microsoft.com/dotnet/sdk), the "other hosts" negative case, multi-namespaced negative case, build-section negative case, etc.3. Adds support for two more public registries. Both are common enough in
compose.yamlfiles that linking to their UI is high-value:ghcr.io/<owner>/<repo>[:tag]https://github.com/<owner>/<repo>/pkgs/container/<repo>quay.io/<owner>/<repo>[:tag]https://quay.io/repository/<owner>/<repo>Tags are stripped from the link target (matching the existing behavior for Docker Hub).
4. Adds three new test cases:
Should provide links for GitHub Container Registry images— coversghcr.io/microsoft/playwright-mcpand a tagged form.Should provide links for Quay.io images— coversquay.io/prometheus/node-exporterand a tagged form.Should NOT provide links for unrecognized private registries— includes the exact image from Hover link onimage:field in compose.yaml always points to Docker Hub, even for private registries #179 (nrt.vultrcr.com/wulicoco/code-sync) pluslocalhost:5000/myimgandregistry.gitlab.com/group/project/image. Locks in the negative behavior so it can't regress.Total test count: 122 passing (was 119).
Things I deliberately did not change
:tagsuffix, matching the existing Docker Hub / MCR behavior.imageTypesset still records what was matched;dockerHub,dockerHubNamespaced,mcrkeep their existing values andghcr/quayare added.Verification
npm run lint— cleannpm run build— clean (esm + cjs)npm test— 122 passing, 1 pending (no changes to pending list)