fix(github): preserve trailing hyphens in repository names #4695
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.
Description:
Fix a bug where repository names ending with a hyphen (e.g.,
my-repo-) would have the trailing hyphen stripped when parsing the URL, causing 404 errors when trying to access the repository via the GitHub API.Root cause: The
getRepoURLParts()function reconstructed the URL viaurl.URL.String()and then re-parsed it by splitting on/. This process could lose trailing special characters in certain edge cases.Fix: Use
repoURL.HostandrepoURL.Pathdirectly instead of reconstructing viaString(), which preserves the original path including any trailing hyphens.Example of the bug:
Fixes #4679
Checklist:
make test-community)?make lintthis requires golangci-lint)?Testing notes:
New unit tests added in
TestGetRepoURLPartsWithTrailingHyphencovering edge cases for trailing hyphens in repository names (https, ssh, multiple hyphens, single-repo name).