This repository was archived by the owner on Jan 5, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -84,11 +84,16 @@ func getImportPath() (importpath string) {
84
84
if importpath == "" {
85
85
repourl := os .Getenv ("SEMMLE_REPO_URL" )
86
86
if repourl == "" {
87
+ log .Printf ("Unable to determine import path, as neither LGTM_INDEX_IMPORT_PATH nor SEMMLE_REPO_URL is set\n " )
87
88
return ""
88
89
}
89
90
importpath = getImportPathFromRepoURL (repourl )
91
+ if importpath == "" {
92
+ log .Printf ("Failed to determine import path from SEMMLE_REPO_URL '%s'\n " , repourl )
93
+ return
94
+ }
90
95
}
91
- log .Printf ("Import path is %s \n " , importpath )
96
+ log .Printf ("Import path is '%s' \n " , importpath )
92
97
return
93
98
}
94
99
@@ -103,8 +108,18 @@ func getImportPathFromRepoURL(repourl string) string {
103
108
// otherwise parse as proper URL
104
109
u , err := url .Parse (repourl )
105
110
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 ""
107
117
}
118
+
119
+ if u .Hostname () == "" || u .Path == "" {
120
+ return ""
121
+ }
122
+
108
123
host := u .Hostname ()
109
124
path := u .Path
110
125
// 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) {
9
9
"https://github.com/github/codeql-go.git" : "github.com/github/codeql-go" ,
10
10
"https://github.com:12345/github/codeql-go" : "github.com/github/codeql-go" ,
11
11
"[email protected] :some/repo" :
"some.url/some/repo" ,
12
+ "file:///C:/some/path" : "" ,
13
+ "https:///no/hostname" : "" ,
14
+ "https://hostnameonly" : "" ,
12
15
}
13
16
for input , expected := range tests {
14
17
actual := getImportPathFromRepoURL (input )
You can’t perform that action at this time.
0 commit comments