fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

zoekt-mirror-gerrit: handle http authentication (#770)

+18 -1
+18 -1
cmd/zoekt-mirror-gerrit/main.go
··· 139 139 for _, s := range []string{"http", "anonymous http"} { 140 140 if schemeInfo, ok := info.Download.Schemes[s]; ok { 141 141 projectURL = schemeInfo.URL 142 + if s == "http" && schemeInfo.IsAuthRequired { 143 + projectURL = addPassword(projectURL, rootURL.User) 144 + // remove "/a/" prefix needed for API call with basic auth but not with git command → cleaner repo name 145 + projectURL = strings.Replace(projectURL, "/a/${project}", "/${project}", 1) 146 + } 142 147 break 143 148 } 144 149 } ··· 187 192 config := map[string]string{ 188 193 "zoekt.name": zoektName, 189 194 "zoekt.gerrit-project": k, 190 - "zoekt.gerrit-host": rootURL.String(), 195 + "zoekt.gerrit-host": anonymousURL(rootURL), 191 196 "zoekt.archived": marshalBool(v.State == "READ_ONLY"), 192 197 "zoekt.public": marshalBool(v.State != "HIDDEN"), 193 198 } ··· 246 251 } 247 252 return "0" 248 253 } 254 + 255 + func anonymousURL(u *url.URL) string { 256 + anon := *u 257 + anon.User = nil 258 + return anon.String() 259 + } 260 + 261 + func addPassword(u string, user *url.Userinfo) string { 262 + password, _ := user.Password() 263 + username := user.Username() 264 + return strings.Replace(u, fmt.Sprintf("://%s@", username), fmt.Sprintf("://%s:%s@", username, password), 1) 265 + }