repo mirror list: filter on the owner/repo form shown in the table · Entire
repo mirror list: filter on the owner/repo form shown in the table
d8df699→main·
gtrrz-victor·1w ago·2 files·+20 added/-8 removed
--repo filtered on the bare repo name while the REPO column and the sort key use owner/repo, so a value copied from the table (e.g. acme/web) matched nothing. Filter on the owner/repo form on both the mirror and --show-available paths so it matches the row it came from.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
01KX0DPH9XWKXQD7MRQGNVGD0NView transcript
Changes
2
cmd/entire/cli
- Mrepo_mirror.go+10/-8
Mrepo_mirror_test.go+10
146 unmodified lines
return nil
}
// filterByRepo keeps items whose repo name contains substr (case-insensitive).
// The control plane already filters by owner/provider/cluster server-side but
// not by repo name, so `repo mirror list --repo` narrows that last dimension
// client-side. repoOf extracts the repo field from each item (mirrors and
// available mirrors both carry one). An empty substr returns items unchanged.
// filterByRepo keeps items whose repo identifier contains substr (case-
// insensitive). The control plane already filters by owner/provider/cluster
// server-side but not by repo name, so `repo mirror list --repo` narrows that
// last dimension client-side. repoOf returns the item's displayed identifier —
// the callers pass the owner/repo form shown in the REPO column, so a value
// copied from the table (e.g. acme/web) matches the row it came from. An empty
// substr returns items unchanged.
func filterByRepo[T any](items []T, repoOf func(T) string, substr string) []T {
substr = strings.TrimSpace(substr)
if substr == "" {
354 unmodified lines
if err != nil {
return nil, err
}
avail := filterByRepo(out.Available, func(m coreapi.AvailableMirror) string { return m.Repo }, repo)
avail := filterByRepo(out.Available, func(m coreapi.AvailableMirror) string { return m.Owner + "/" + m.Repo }, repo)
if err := sortAvailable(avail, sortSpec); err != nil {
return nil, err
}
if err != nil {
return nil, err
}
mirrors = filterByRepo(mirrors, func(m coreapi.Mirror) string { return m.Repo }, repo)
mirrors = filterByRepo(mirrors, func(m coreapi.Mirror) string { return m.Owner + "/" + m.Repo }, repo)
if err := sortMirrors(mirrors, sortSpec); err != nil {
return nil, err
}
cmd.Flags().StringVar(&cluster, "cluster", "", "Filter by cluster public host")
cmd.Flags().StringVar(&provider, "provider", "", "Filter by upstream provider (e.g. github)")
cmd.Flags().StringVar(&owner, "owner", "", "Filter by upstream owner login")
cmd.Flags().StringVar(&repo, "repo", "", "Filter by repo-name substring (case-insensitive)")
cmd.Flags().StringVar(&repo, "repo", "", "Filter by owner/repo substring, matching the REPO column (case-insensitive)")
cmd.Flags().StringVar(&sortSpec, "sort", "", "Sort by column (header name; prefix '-' for descending). Default: repo name ascending")
cmd.Flags().BoolVar(&showAvailable, "show-available", false, "Instead of existing mirrors, list GitHub repos you could onboard as mirrors (ignores --cluster/--provider)")
return cmd
Mcmd/entire/cli/repo_mirror.go+10
532 unmodified lines
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
532 unmodified lines
require.NotContains(t, stdout, "other/api")
})
t.Run("--repo matches the owner/repo form shown in the REPO column", func(t *testing.T) {
// A value copied straight from the displayed REPO column must match the
// row it came from; filtering on the bare repo name would drop it.
serveMirrorList(t, mirrors, nil)
stdout, _ := runMirrorList(t, "--repo", "acme/web")
require.Contains(t, stdout, "acme/web")
require.NotContains(t, stdout, "acme/cli")
require.NotContains(t, stdout, "other/api")
})
t.Run("default output is owner/repo sorted", func(t *testing.T) {
serveMirrorList(t, mirrors, nil)
stdout, _ := runMirrorList(t)
Mcmd/entire/cli/repo_mirror_test.go+10