Skip to content

Fix source file links for non-GitHub hosts (e.g. Azure DevOps)#373

Open
jirisacha wants to merge 1 commit into
AIDotNet:mainfrom
jirisacha:fix/source-files-non-github-host
Open

Fix source file links for non-GitHub hosts (e.g. Azure DevOps)#373
jirisacha wants to merge 1 commit into
AIDotNet:mainfrom
jirisacha:fix/source-files-non-github-host

Conversation

@jirisacha

Copy link
Copy Markdown
Contributor

Problem

On a wiki page, the "Sources" footer renders file links that point to a
non-existent github.com repository when the repository is not hosted on
GitHub (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 the
in-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:

  • In-content links are baked server-side into the stored Markdown by
    WikiGenerator.BuildGitFileBaseUrl, which already detects the hosting
    platform (GitHub / GitLab / Gitee / Bitbucket / Azure DevOps). ✅ correct.
  • The "Sources" footer is built client-side by the SourceFiles
    component, which diverged:
    1. It was never passed the repository git URL, so it fabricated
      https://github.com/${owner}/${repo} from the route params
      (source-files.tsx). For non-GitHub repos this is a dead link.
    2. 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.

The docs API (RepositoryDocResponse) did not expose the repository git URL,
so the component had nothing correct to use.

Fix

  • Backend: return GitUrl and Branch from the docs API
    (RepositoryDocResponse, populated in RepositoryDocsService.GetDocAsync
    from the repository entity and the resolved branch).
  • Frontend: thread gitUrl and branch into SourceFiles; add an Azure
    DevOps format to buildFileUrl (?version=GB{branch}&path=/{file},
    mirroring the backend); and remove the hardcoded github.com fallback — when
    the git URL is unknown the file is shown as a plain label instead of a broken
    link.

Notes

  • No data migration required: footer links are computed at render time, so the
    fix retroactively corrects all existing repositories. Stored content is
    unchanged.
  • GitHub-hosted repositories keep the existing /blob/ behaviour.

Verification

  • dotnet build — 0 errors.
  • Frontend tsc --noEmit and eslint on the changed files — clean.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant