From 77d94b7afda07c3813fbf4e1d4fb7dab6a3464f7 Mon Sep 17 00:00:00 2001 From: Keegan Carruthers-Smith Date: Wed, 6 May 2026 09:03:27 +0200 Subject: [PATCH] feat/gitindex: support more code host URL templates Bitbucket Cloud and Azure DevOps repositories need host-specific URL templates so indexed search results can link back to commits and file locations in their native web UIs. The Azure file template uses the commit-version prefix because Zoekt stores commit SHAs for branch versions, avoiding a branch-only URL form. Test Plan: go test ./gitindex -run TestSetTemplates Amp-Thread-ID: https://ampcode.com/threads/T-019dfc16-15c7-7058-bbfe-90582e3badf6 Co-authored-by: Amp --- gitindex/index.go | 12 ++++++++++++ gitindex/index_test.go | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/gitindex/index.go b/gitindex/index.go index 93c9148e2..3e9f4b6bd 100644 --- a/gitindex/index.go +++ b/gitindex/index.go @@ -143,6 +143,18 @@ func setTemplates(repo *zoekt.Repository, u *url.URL, typ string) error { repo.CommitURLTemplate = urlJoinPath("commits", varVersion) repo.FileURLTemplate = urlJoinPath(varPath) + "?at={{.Version}}" repo.LineFragmentTemplate = "#{{.LineNumber}}" + case "bitbucket-cloud": + // https://bitbucket.org///commits/ + // https://bitbucket.org///src// + repo.CommitURLTemplate = urlJoinPath("commits", varVersion) + repo.FileURLTemplate = urlJoinPath("src", varVersion, varPath) + repo.LineFragmentTemplate = "#{{.LineNumber}}" + case "azuredevops": + // https://dev.azure.com///_git//commit/ + // https://dev.azure.com///_git/?path=/&version=GC + repo.CommitURLTemplate = urlJoinPath("commit", varVersion) + repo.FileURLTemplate = urlJoinPath() + "?path=/{{.Path}}&version=GC{{.Version}}&_a=contents" + repo.LineFragmentTemplate = "&line={{.LineNumber}}&lineEnd={{.LineNumber}}&lineStartColumn=1&lineEndColumn=200" case "gitlab": // https://gitlab.com/gitlab-org/omnibus-gitlab/-/commit/b152c864303dae0e55377a1e2c53c9592380ffed // https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/aad04155b3f6fc50ede88aedaee7fc624d481149/files/gitlab-config-template/gitlab.rb.template diff --git a/gitindex/index_test.go b/gitindex/index_test.go index d8d303751..c62148e6b 100644 --- a/gitindex/index_test.go +++ b/gitindex/index_test.go @@ -1097,6 +1097,16 @@ func TestSetTemplates(t *testing.T) { commit: "https://example.com/repo/name/commits/VERSION", file: "https://example.com/repo/name/dir/name.txt?at=VERSION", line: "#10", + }, { + typ: "bitbucket-cloud", + commit: "https://example.com/repo/name/commits/VERSION", + file: "https://example.com/repo/name/src/VERSION/dir/name.txt", + line: "#10", + }, { + typ: "azuredevops", + commit: "https://example.com/repo/name/commit/VERSION", + file: "https://example.com/repo/name?path=/dir/name.txt&version=GCVERSION&_a=contents", + line: "&line=10&lineEnd=10&lineStartColumn=1&lineEndColumn=200", }, { typ: "gitlab", commit: "https://example.com/repo/name/-/commit/VERSION",