Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zoekt-mirror-gerrit: allow to use reponame without host in the index #771

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion cmd/zoekt-mirror-gerrit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/url"
"os"
"path/filepath"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -73,9 +74,22 @@ func newLoggingClient() *http.Client {
}
}

const qualifiedRepoNameFormat = "qualified"
const projectRepoNameFormat = "project"

var validRepoNameFormat = []string{qualifiedRepoNameFormat, projectRepoNameFormat}

func validateRepoNameFormat(s string) {
if !slices.Contains(validRepoNameFormat, s) {
log.Fatal(fmt.Sprintf("repo-name-format must be one of %s", strings.Join(validRepoNameFormat, ", ")))
}
}

func main() {

dest := flag.String("dest", "", "destination directory")
namePattern := flag.String("name", "", "only clone repos whose name matches the regexp.")
repoNameFormat := flag.String("repo-name-format", qualifiedRepoNameFormat, fmt.Sprintf("the format of the local repo name in zoekt (valid values: %s)", strings.Join(validRepoNameFormat, ", ")))
excludePattern := flag.String("exclude", "", "don't mirror repos whose names match this regexp.")
deleteRepos := flag.Bool("delete", false, "delete missing repos")
httpCrendentialsPath := flag.String("http-credentials", "", "path to a file containing http credentials stored like 'user:password'.")
Expand All @@ -85,6 +99,7 @@ func main() {
if len(flag.Args()) < 1 {
log.Fatal("must provide URL argument.")
}
validateRepoNameFormat(*repoNameFormat)

rootURL, err := url.Parse(flag.Arg(0))
if err != nil {
Expand Down Expand Up @@ -162,8 +177,15 @@ func main() {
}

name := filepath.Join(cloneURL.Host, cloneURL.Path)
var zoektName string
switch *repoNameFormat {
case qualifiedRepoNameFormat:
zoektName = name
case projectRepoNameFormat:
zoektName = k
}
config := map[string]string{
"zoekt.name": name,
"zoekt.name": zoektName,
"zoekt.gerrit-project": k,
"zoekt.gerrit-host": rootURL.String(),
"zoekt.archived": marshalBool(v.State == "READ_ONLY"),
Expand Down
Loading