autobuilder: Don't try to determine import paths for file URLs

Also improve logging
This commit is contained in:
Sauyon Lee
2020-08-05 11:40:05 -07:00
parent b057cbee7b
commit 8e6c1835dd
2 changed files with 20 additions and 2 deletions

View File

@@ -84,11 +84,16 @@ func getImportPath() (importpath string) {
if importpath == "" {
repourl := os.Getenv("SEMMLE_REPO_URL")
if repourl == "" {
log.Printf("Unable to determine import path, as neither LGTM_INDEX_IMPORT_PATH nor SEMMLE_REPO_URL is set\n")
return ""
}
importpath = getImportPathFromRepoURL(repourl)
if importpath == "" {
log.Printf("Failed to determine import path from SEMMLE_REPO_URL '%s'\n", repourl)
return
}
}
log.Printf("Import path is %s\n", importpath)
log.Printf("Import path is '%s'\n", importpath)
return
}
@@ -103,8 +108,18 @@ func getImportPathFromRepoURL(repourl string) string {
// otherwise parse as proper URL
u, err := url.Parse(repourl)
if err != nil {
log.Fatalf("Malformed repository URL %s.\n", repourl)
log.Fatalf("Malformed repository URL '%s'\n", repourl)
}
if u.Scheme == "file" {
// we can't determine import paths from file paths
return ""
}
if u.Hostname() == "" || u.Path == "" {
return ""
}
host := u.Hostname()
path := u.Path
// strip off leading slashes and trailing `.git` if present

View File

@@ -9,6 +9,9 @@ func TestGetImportPathFromRepoURL(t *testing.T) {
"https://github.com/github/codeql-go.git": "github.com/github/codeql-go",
"https://github.com:12345/github/codeql-go": "github.com/github/codeql-go",
"gitolite@some.url:some/repo": "some.url/some/repo",
"file:///C:/some/path": "",
"https:///no/hostname": "",
"https://hostnameonly": "",
}
for input, expected := range tests {
actual := getImportPathFromRepoURL(input)