From 12fc8f41c74ff7794491de4e26acf60901549263 Mon Sep 17 00:00:00 2001 From: Haiyan Meng Date: Mon, 16 Dec 2019 11:08:38 -0800 Subject: [PATCH] Add support for github paths starting with "git@github.com:" --- api/internal/crawl/doc/docname.go | 12 +++++++++--- api/internal/crawl/doc/docname_test.go | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api/internal/crawl/doc/docname.go b/api/internal/crawl/doc/docname.go index ee05b2d3f..5afca1290 100644 --- a/api/internal/crawl/doc/docname.go +++ b/api/internal/crawl/doc/docname.go @@ -78,11 +78,17 @@ func (doc *Document) ID() string { } func (doc *Document) RepositoryFullName() string { - doc.RepositoryURL = strings.TrimRight(doc.RepositoryURL, "/") - sections := strings.Split(doc.RepositoryURL, "/") + url := strings.TrimRight(doc.RepositoryURL, "/") + + gitPrefix := "git@github.com:" + if strings.HasPrefix(url, gitPrefix) { + url = url[len(gitPrefix):] + } + + sections := strings.Split(url, "/") l := len(sections) if l < 2 { - return doc.RepositoryURL + return url } return path.Join(sections[l-2], sections[l-1]) } diff --git a/api/internal/crawl/doc/docname_test.go b/api/internal/crawl/doc/docname_test.go index afcd702cb..f1b65dc8f 100644 --- a/api/internal/crawl/doc/docname_test.go +++ b/api/internal/crawl/doc/docname_test.go @@ -92,6 +92,12 @@ func TestDocument_RepositoryFullName(t *testing.T) { }, expectedRepositoryFullName: "", }, + { + doc: Document{ + RepositoryURL: "git@github.com:user/repo", + }, + expectedRepositoryFullName: "user/repo", + }, } for _, tc := range testCases {