fix(github-issues): handle file: type source-locations in getHostnameFromEntity#9105
Open
Fortune-Ndlovu wants to merge 1 commit intobackstage:mainfrom
Open
Conversation
…FromEntity `getHostnameFromEntity` unconditionally passes the entity's source-location target to `new URL()`, which throws `TypeError: Invalid URL` when the source-location is `file:` type (e.g. `file:./catalog-entities/foo.yaml`). This affects any Backstage deployment where entities are registered via `file:` type catalog locations — the standard approach for local, Helm, and operator-managed instances. The fix checks the `type` field returned by `getEntitySourceLocation()`: - `url:` type → parse hostname from the URL (existing behavior) - `file:` type → fall back to `github.com` Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
Contributor
Changed Packages
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a runtime crash in @backstage-community/plugin-github-issues when entities are registered from file: catalog locations by preventing new URL() from being called on non-URL targets.
Changes:
- Updated
getHostnameFromEntityto branch ongetEntitySourceLocation(entity).type, parsing hostnames only forurland defaulting togithub.comotherwise. - Added unit tests covering
getHostnameFromEntity(includingfile:andmanaged-by-locationfallback) andgetProjectNameFromEntity. - Added a changeset to ship the fix as a patch release.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| workspaces/github/plugins/github-issues/src/hooks/useEntityGithubRepositories.ts | Avoids new URL() on file: source-locations by checking the location type first. |
| workspaces/github/plugins/github-issues/src/hooks/useEntityGithubRepositories.test.ts | Adds focused unit tests for hostname/project-slug extraction, including file: scenarios. |
| .changeset/fix-github-issues-file-source-location.md | Declares a patch release note for the crash fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hopehadfield
approved these changes
May 11, 2026
Contributor
hopehadfield
left a comment
There was a problem hiding this comment.
Just one small nitpick but otherwise LGTM! Thanks for adding the tests.
| if (type === 'url') { | ||
| return new URL(target).hostname; | ||
| } | ||
| return 'github.com'; |
Contributor
There was a problem hiding this comment.
I'd extract this as a const
5 tasks
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.
Summary
getHostnameFromEntity()in@backstage-community/plugin-github-issuesunconditionally passes the entity's source-location target tonew URL(), which throwsTypeError: Invalid URLwhen the source-location isfile:typetypefield fromgetEntitySourceLocation(): forurl:type it parses the hostname as before, forfile:type it falls back togithub.comgetHostnameFromEntityandgetProjectNameFromEntityThe Problem
The
getHostnameFromEntityfunction extracts the GitHub hostname from an entity's source-location:getEntitySourceLocation()returns{ type, target }where:url:https://github.com/org/repo->{ type: "url", target: "https://github.com/org/repo" }file:./catalog-entities/foo.yaml->{ type: "file", target: "./catalog-entities/foo.yaml" }The function ignores the
typefield and unconditionally callsnew URL(target). When the source-location isfile:type, the target is a relative filesystem path, not a valid URL, sonew URL()throwsTypeError: Invalid URL, crashing the Issues tab.Who's Affected
Any Backstage deployment where entities are registered via
file:type catalog locationsThe Fix
Test plan
url:type source-location (parses hostname correctly)url:source-location (parses custom hostname)file:type source-location (falls back togithub.com)managed-by-locationfallback withfile:typegetProjectNameFromEntity