From c1c9dc491f8f87179338b5143b37c5fecafabe3e Mon Sep 17 00:00:00 2001 From: "Andrew E. Timmes" Date: Mon, 16 Sep 2024 21:58:16 -0400 Subject: [PATCH 1/2] add a flag to exclude user projects from mirroring --- cmd/zoekt-mirror-gitlab/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/zoekt-mirror-gitlab/main.go b/cmd/zoekt-mirror-gitlab/main.go index 9bfa3715..30a0ea64 100644 --- a/cmd/zoekt-mirror-gitlab/main.go +++ b/cmd/zoekt-mirror-gitlab/main.go @@ -46,6 +46,7 @@ func main() { isMember := flag.Bool("membership", false, "only mirror repos this user is a member of ") isPublic := flag.Bool("public", false, "only mirror public repos") deleteRepos := flag.Bool("delete", false, "delete missing repos") + excludeUserRepos := flag.Bool("exclude-user", false, "exclude user repos") namePattern := flag.String("name", "", "only clone repos whose name matches the given regexp.") excludePattern := flag.String("exclude", "", "don't mirror repos whose names match this regexp.") flag.Parse() @@ -103,6 +104,9 @@ func main() { if project.DefaultBranch == "" { continue } + if *excludeUserRepos && project.Namespace.Kind == "user" { + continue + } gitlabProjects = append(gitlabProjects, project) } @@ -128,7 +132,6 @@ func main() { } gitlabProjects = trimmed } - fetchProjects(destDir, apiToken, gitlabProjects) if *deleteRepos { From 28e734aedececd4afe14ca43a2214dca5a301d31 Mon Sep 17 00:00:00 2001 From: "Andrew E. Timmes" Date: Mon, 16 Sep 2024 23:07:43 -0400 Subject: [PATCH 2/2] add ExcludeUserRepos --- cmd/zoekt-indexserver/config.go | 10 +++++++--- cmd/zoekt-mirror-gitlab/main.go | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/zoekt-indexserver/config.go b/cmd/zoekt-indexserver/config.go index a1fb3923..e35fda6a 100644 --- a/cmd/zoekt-indexserver/config.go +++ b/cmd/zoekt-indexserver/config.go @@ -51,7 +51,8 @@ type ConfigEntry struct { Active bool NoArchived bool GerritFetchMetaConfig bool - GerritRepoNameFormat string + GerritRepoNameFormat string + ExcludeUserRepos bool } func randomize(entries []ConfigEntry) []ConfigEntry { @@ -243,6 +244,9 @@ func executeMirror(cfg []ConfigEntry, repoDir string, pendingRepos chan<- string if c.OnlyPublic { cmd.Args = append(cmd.Args, "-public") } + if c.ExcludeUserRepos { + cmd.Args = append(cmd.Args, "-exclude_user") + } if c.CredentialPath != "" { cmd.Args = append(cmd.Args, "-token", c.CredentialPath) } @@ -261,9 +265,9 @@ func executeMirror(cfg []ConfigEntry, repoDir string, pendingRepos chan<- string if c.Active { cmd.Args = append(cmd.Args, "-active") } - if c.GerritFetchMetaConfig { + if c.GerritFetchMetaConfig { cmd.Args = append(cmd.Args, "-fetch-meta-config") - } + } if c.GerritRepoNameFormat != "" { cmd.Args = append(cmd.Args, "-repo-name-format", c.GerritRepoNameFormat) } diff --git a/cmd/zoekt-mirror-gitlab/main.go b/cmd/zoekt-mirror-gitlab/main.go index 30a0ea64..f28f9ce2 100644 --- a/cmd/zoekt-mirror-gitlab/main.go +++ b/cmd/zoekt-mirror-gitlab/main.go @@ -46,7 +46,7 @@ func main() { isMember := flag.Bool("membership", false, "only mirror repos this user is a member of ") isPublic := flag.Bool("public", false, "only mirror public repos") deleteRepos := flag.Bool("delete", false, "delete missing repos") - excludeUserRepos := flag.Bool("exclude-user", false, "exclude user repos") + excludeUserRepos := flag.Bool("exclude_user", false, "exclude user repos") namePattern := flag.String("name", "", "only clone repos whose name matches the given regexp.") excludePattern := flag.String("exclude", "", "don't mirror repos whose names match this regexp.") flag.Parse()