fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

gitindex: interpret SSH URLs (#764)

This allows indexing repos that are used for development and therefore have an
SSH 'origin' URL.

+32
+16
gitindex/index.go
··· 27 27 "net/url" 28 28 "os" 29 29 "path/filepath" 30 + "regexp" 30 31 "sort" 31 32 "strconv" 32 33 "strings" ··· 111 112 // setTemplates fills in URL templates for known git hosting 112 113 // sites. 113 114 func setTemplates(repo *zoekt.Repository, u *url.URL, typ string) error { 115 + if u.Scheme == "ssh+git" { 116 + u.Scheme = "https" 117 + u.User = nil 118 + } 119 + 114 120 repo.URL = u.String() 115 121 switch typ { 116 122 case "gitiles": ··· 191 197 } 192 198 return rc.URLs[0] 193 199 } 200 + 201 + var sshRelativeURLRegexp = regexp.MustCompile(`^([^@]+)@([^:]+):(.*)$`) 194 202 195 203 func setTemplatesFromConfig(desc *zoekt.Repository, repoDir string) error { 196 204 repo, err := git.PlainOpen(repoDir) ··· 228 236 if remoteURL == "" { 229 237 return nil 230 238 } 239 + if sm := sshRelativeURLRegexp.FindStringSubmatch(remoteURL); sm != nil { 240 + user := sm[1] 241 + host := sm[2] 242 + path := sm[3] 243 + 244 + remoteURL = fmt.Sprintf("ssh+git://%s@%s/%s", user, host, path) 245 + } 246 + 231 247 u, err := url.Parse(remoteURL) 232 248 if err != nil { 233 249 return err
+16
gitindex/index_test.go
··· 768 768 t.Fatalf("execution error: %v, output %s", err, out) 769 769 } 770 770 } 771 + 772 + func TestSetTemplate(t *testing.T) { 773 + repositoryDir := t.TempDir() 774 + 775 + // setup: initialize the repository and all of its branches 776 + runScript(t, repositoryDir, "git init -b master") 777 + runScript(t, repositoryDir, "git config remote.origin.url git@github.com:sourcegraph/zoekt.git") 778 + desc := zoekt.Repository{} 779 + if err := setTemplatesFromConfig(&desc, repositoryDir); err != nil { 780 + t.Fatalf("setTemplatesFromConfig: %v", err) 781 + } 782 + 783 + if got, want := desc.FileURLTemplate, "https://github.com/sourcegraph/zoekt/blob/{{.Version}}/{{.Path}}"; got != want { 784 + t.Errorf("got %q, want %q", got, want) 785 + } 786 + }