This repository was archived by the owner on Jan 5, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 "gitolite@some.url: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 )
You can’t perform that action at this time.
0 commit comments