Skip to content

Fix broken file links #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fixed issue where we crash on startup if the install / upgrade PostHog event fails to send. ([#159](https://github.com/sourcebot-dev/sourcebot/pull/159))
- Fixed issue with broken file links. ([#161](https://github.com/sourcebot-dev/sourcebot/pull/161))

## [2.7.0] - 2025-01-10

Expand Down
26 changes: 22 additions & 4 deletions packages/web/src/app/search/components/codePreviewPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,30 @@ export const CodePreviewPanel = ({
.then(({ source }) => {
const link = (() => {
const template = repoUrlTemplates[fileMatch.Repository];
if (!template) {

// This is a hacky parser for templates generated by
// the go text/template package. Example template:
// {{URLJoinPath "https://github.com/sourcebot-dev/sourcebot" "blob" .Version .Path}}
// @see: https://pkg.go.dev/text/template
if (!template || !template.match(/^{{URLJoinPath\s.*}}(\?.+)?$/)) {
return undefined;
}
return template
.replace("{{.Version}}", branch ?? "HEAD")
.replace("{{.Path}}", fileMatch.FileName);

const url =
template.substring("{{URLJoinPath ".length,template.indexOf("}}"))
.replace(".Version", branch ?? "HEAD")
.replace(".Path", fileMatch.FileName)
.split(" ")
.map((part) => {
// remove wrapping quotes
if (part.startsWith("\"")) part = part.substring(1);
if (part.endsWith("\"")) part = part.substring(0, part.length - 1);
return part;
})
.join("/");

const optionalQueryParams = template.substring(template.indexOf("}}") + 2);
return url + optionalQueryParams;
})();

const decodedSource = base64Decode(source);
Expand Down
Loading