Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 97291e4

Browse files
authored
Merge pull request #279 from github/rc/1.25
Merge rc/1.25 into master
2 parents 4e409aa + 90bab34 commit 97291e4

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,16 @@ func getImportPath() (importpath string) {
8484
if importpath == "" {
8585
repourl := os.Getenv("SEMMLE_REPO_URL")
8686
if repourl == "" {
87+
log.Printf("Unable to determine import path, as neither LGTM_INDEX_IMPORT_PATH nor SEMMLE_REPO_URL is set\n")
8788
return ""
8889
}
8990
importpath = getImportPathFromRepoURL(repourl)
91+
if importpath == "" {
92+
log.Printf("Failed to determine import path from SEMMLE_REPO_URL '%s'\n", repourl)
93+
return
94+
}
9095
}
91-
log.Printf("Import path is %s\n", importpath)
96+
log.Printf("Import path is '%s'\n", importpath)
9297
return
9398
}
9499

@@ -103,8 +108,18 @@ func getImportPathFromRepoURL(repourl string) string {
103108
// otherwise parse as proper URL
104109
u, err := url.Parse(repourl)
105110
if err != nil {
106-
log.Fatalf("Malformed repository URL %s.\n", repourl)
111+
log.Fatalf("Malformed repository URL '%s'\n", repourl)
112+
}
113+
114+
if u.Scheme == "file" {
115+
// we can't determine import paths from file paths
116+
return ""
107117
}
118+
119+
if u.Hostname() == "" || u.Path == "" {
120+
return ""
121+
}
122+
108123
host := u.Hostname()
109124
path := u.Path
110125
// strip off leading slashes and trailing `.git` if present

extractor/cli/go-autobuilder/go-autobuilder_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ func TestGetImportPathFromRepoURL(t *testing.T) {
99
"https://github.com/github/codeql-go.git": "github.com/github/codeql-go",
1010
"https://github.com:12345/github/codeql-go": "github.com/github/codeql-go",
1111
"[email protected]:some/repo": "some.url/some/repo",
12+
"file:///C:/some/path": "",
13+
"https:///no/hostname": "",
14+
"https://hostnameonly": "",
1215
}
1316
for input, expected := range tests {
1417
actual := getImportPathFromRepoURL(input)

0 commit comments

Comments
 (0)