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: allow to use reponame without host in the index (#771)

The repo is indexed only with the reponame which is more user-friendly
in the search when there is onely one host
Filter string will be "r:my-repo" instead of "r:my-gerrit-sever.com/my-repo"

+23 -1
+23 -1
cmd/zoekt-mirror-gerrit/main.go
··· 26 26 "net/url" 27 27 "os" 28 28 "path/filepath" 29 + "slices" 29 30 "strconv" 30 31 "strings" 31 32 ··· 70 71 Transport: &loggingRT{ 71 72 RoundTripper: http.DefaultTransport, 72 73 }, 74 + } 75 + } 76 + 77 + const qualifiedRepoNameFormat = "qualified" 78 + const projectRepoNameFormat = "project" 79 + 80 + var validRepoNameFormat = []string{qualifiedRepoNameFormat, projectRepoNameFormat} 81 + 82 + func validateRepoNameFormat(s string) { 83 + if !slices.Contains(validRepoNameFormat, s) { 84 + log.Fatal(fmt.Sprintf("repo-name-format must be one of %s", strings.Join(validRepoNameFormat, ", "))) 73 85 } 74 86 } 75 87 76 88 func main() { 89 + 77 90 dest := flag.String("dest", "", "destination directory") 78 91 namePattern := flag.String("name", "", "only clone repos whose name matches the regexp.") 92 + repoNameFormat := flag.String("repo-name-format", qualifiedRepoNameFormat, fmt.Sprintf("the format of the local repo name in zoekt (valid values: %s)", strings.Join(validRepoNameFormat, ", "))) 79 93 excludePattern := flag.String("exclude", "", "don't mirror repos whose names match this regexp.") 80 94 deleteRepos := flag.Bool("delete", false, "delete missing repos") 81 95 httpCrendentialsPath := flag.String("http-credentials", "", "path to a file containing http credentials stored like 'user:password'.") ··· 85 99 if len(flag.Args()) < 1 { 86 100 log.Fatal("must provide URL argument.") 87 101 } 102 + validateRepoNameFormat(*repoNameFormat) 88 103 89 104 rootURL, err := url.Parse(flag.Arg(0)) 90 105 if err != nil { ··· 162 177 } 163 178 164 179 name := filepath.Join(cloneURL.Host, cloneURL.Path) 180 + var zoektName string 181 + switch *repoNameFormat { 182 + case qualifiedRepoNameFormat: 183 + zoektName = name 184 + case projectRepoNameFormat: 185 + zoektName = k 186 + } 165 187 config := map[string]string{ 166 - "zoekt.name": name, 188 + "zoekt.name": zoektName, 167 189 "zoekt.gerrit-project": k, 168 190 "zoekt.gerrit-host": rootURL.String(), 169 191 "zoekt.archived": marshalBool(v.State == "READ_ONLY"),