Fix source file links for non-GitHub hosts (e.g. Azure DevOps)#373
Open
jirisacha wants to merge 1 commit into
Open
Fix source file links for non-GitHub hosts (e.g. Azure DevOps)#373jirisacha wants to merge 1 commit into
jirisacha wants to merge 1 commit into
Conversation
The "Sources" footer builds file links client-side in the SourceFiles component, but it diverged from the backend link builder in two ways: - The component was never given the repository git URL, so it fabricated a `https://github.com/{owner}/{repo}` URL from the route params. For repos not hosted on GitHub (Azure DevOps, self-hosted GitLab, ...) this produced links to a github.com repository that does not exist. - `buildFileUrl` had no Azure DevOps case, so even with a real git URL it fell back to the GitHub `/blob/` format, which is invalid for ADO. Meanwhile the in-content links are baked server-side by `WikiGenerator.BuildGitFileBaseUrl`, which already handles Azure DevOps, so those were correct - only the footer was wrong. Fix: - Return the repository `GitUrl` and `Branch` from the docs API (`RepositoryDocResponse` / `RepositoryDocsService.GetDocAsync`). - Thread `gitUrl` and `branch` into the `SourceFiles` component. - Add an Azure DevOps URL format to `buildFileUrl` (`?version=GB{branch}&path=/{file}`), mirroring the backend. - Drop the hardcoded github.com fallback: when the git URL is unknown the file is rendered as a plain label instead of a broken link.
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.
Problem
On a wiki page, the "Sources" footer renders file links that point to a
non-existent
github.comrepository when the repository is not hosted onGitHub (Azure DevOps, self-hosted GitLab, etc.).
Example (Azure DevOps repo): the footer links to
https://github.com/{owner}/{repo}/blob/{branch}/{file}— a 404 — while thein-content "Related Links" / source-attribution links on the same page point
to the correct Azure DevOps URL.
Root cause
The two kinds of links are built by two different code paths:
WikiGenerator.BuildGitFileBaseUrl, which already detects the hostingplatform (GitHub / GitLab / Gitee / Bitbucket / Azure DevOps). ✅ correct.
SourceFilescomponent, which diverged:
https://github.com/${owner}/${repo}from the route params(
source-files.tsx). For non-GitHub repos this is a dead link.buildFileUrlhad no Azure DevOps case, so even with a real git URLit fell back to the GitHub
/blob/format, which is invalid for ADO.The docs API (
RepositoryDocResponse) did not expose the repository git URL,so the component had nothing correct to use.
Fix
GitUrlandBranchfrom the docs API(
RepositoryDocResponse, populated inRepositoryDocsService.GetDocAsyncfrom the repository entity and the resolved branch).
gitUrlandbranchintoSourceFiles; add an AzureDevOps format to
buildFileUrl(?version=GB{branch}&path=/{file},mirroring the backend); and remove the hardcoded
github.comfallback — whenthe git URL is unknown the file is shown as a plain label instead of a broken
link.
Notes
fix retroactively corrects all existing repositories. Stored content is
unchanged.
/blob/behaviour.Verification
dotnet build— 0 errors.tsc --noEmitandeslinton the changed files — clean.