diff --git a/changelog.d/fixed-16234-public-activity-bare-repos.md b/changelog.d/fixed-16234-public-activity-bare-repos.md new file mode 100644 index 0000000000..5b1d97996e --- /dev/null +++ b/changelog.d/fixed-16234-public-activity-bare-repos.md @@ -0,0 +1 @@ +- The spoke's hub activity digest (and Battle Log / Hive of the Week) now treats a public hive's own project repos as public again: config loading strips the org off `project.repos` and `primary_repo`, and the public repo set rejected the bare names, so every item was marked private and the hub's public fleet view showed "0 items" for every hive ([#16234](https://github.com/hivecommons/hive/issues/16234)). diff --git a/src/pkg/dashboard/battle_log.go b/src/pkg/dashboard/battle_log.go index a3f62a2dd3..b81c4acd05 100644 --- a/src/pkg/dashboard/battle_log.go +++ b/src/pkg/dashboard/battle_log.go @@ -520,23 +520,38 @@ func (s *Server) publicRepos() publicRepoSet { if s == nil || s.deps == nil || s.deps.Config == nil { return pub } - return registryPublicRepos(pub, s.deps.Config.Hub.IsPublic, s.deps.Config.Project.PrimaryRepo, s.deps.Config.Project.Repos) + cfg := s.deps.Config + return registryPublicRepos(pub, cfg.Hub.IsPublic, cfg.Project.Org, cfg.Project.PrimaryRepo, cfg.Project.Repos) } -func registryPublicRepos(pub publicRepoSet, hiveIsPublic bool, primaryRepo string, repos []string) publicRepoSet { +// registryPublicRepos adds a public hive's own project repos to pub. Config +// loading strips the org off primary_repo and every repos entry, so a bare +// name is qualified with org here; publicRepoSet.add only accepts owner/name +// and would otherwise drop every one of them, marking the whole board private. +func registryPublicRepos(pub publicRepoSet, hiveIsPublic bool, org, primaryRepo string, repos []string) publicRepoSet { if pub == nil { pub = publicRepoSet{} } if !hiveIsPublic { return pub } - pub.add(primaryRepo) + pub.add(qualifyProjectRepo(org, primaryRepo)) for _, repo := range repos { - pub.add(repo) + pub.add(qualifyProjectRepo(org, repo)) } return pub } +// qualifyProjectRepo returns org/repo for a bare repo name; a name that +// already carries an owner, or an empty org, is returned as is. +func qualifyProjectRepo(org, repo string) string { + org, repo = strings.TrimSpace(org), strings.TrimSpace(repo) + if repo == "" || org == "" || strings.Contains(repo, "/") { + return repo + } + return org + "/" + repo +} + func validGourceProject(project string) bool { return project != "" && gourceProjectName.MatchString(project) && !strings.Contains(project, "..") } diff --git a/src/pkg/dashboard/battle_log_test.go b/src/pkg/dashboard/battle_log_test.go index 895cf91d9a..a8b2af669f 100644 --- a/src/pkg/dashboard/battle_log_test.go +++ b/src/pkg/dashboard/battle_log_test.go @@ -199,7 +199,7 @@ func TestRegistryPublicReposDerivedFromPublicHive(t *testing.T) { t.Setenv("HIVE_PUBLIC_REPOS", "") // A public hive's own project repos are public; the primary repo counts // even when it is not repeated in repos. - pub := registryPublicRepos(publicReposFromEnv(), true, "HiveCommons/Hive", []string{"hivecommons/docs", "not-a-repo", ""}) + pub := registryPublicRepos(publicReposFromEnv(), true, "hivecommons", "HiveCommons/Hive", []string{"hivecommons/docs", "not-a-repo", ""}) for repo, want := range map[string]bool{ "hivecommons/hive": true, "hivecommons/docs": true, @@ -210,13 +210,30 @@ func TestRegistryPublicReposDerivedFromPublicHive(t *testing.T) { t.Fatalf("public hive allows(%q) = %v, want %v", repo, got, want) } } + // Config loading strips the org off primary_repo and repos, so the live + // values are bare names; they must be qualified with project.org, and a + // name that already carries an owner is left alone. + pub = registryPublicRepos(publicReposFromEnv(), true, "hivecommons", "", []string{"hive", "docs", "other-org/tool"}) + for repo, want := range map[string]bool{ + "hivecommons/hive": true, + "hivecommons/docs": true, + "other-org/tool": true, + "hive": false, + } { + if got := pub.allows(repo); got != want { + t.Fatalf("bare-name public hive allows(%q) = %v, want %v", repo, got, want) + } + } + if pub := registryPublicRepos(publicReposFromEnv(), true, "", "", []string{"hive"}); len(pub) != 0 { + t.Fatalf("a bare name without an org cannot be qualified: %v", pub) + } // A hive the registry does not list as public contributes nothing. - if pub := registryPublicRepos(publicReposFromEnv(), false, "hivecommons/hive", []string{"hivecommons/hive"}); pub.allows("hivecommons/hive") { + if pub := registryPublicRepos(publicReposFromEnv(), false, "hivecommons", "hivecommons/hive", []string{"hivecommons/hive"}); pub.allows("hivecommons/hive") { t.Fatalf("private hive must not publish its repos") } // HIVE_PUBLIC_REPOS remains an explicit union with the registry-derived set. t.Setenv("HIVE_PUBLIC_REPOS", "acme/widgets") - pub = registryPublicRepos(publicReposFromEnv(), true, "hivecommons/hive", nil) + pub = registryPublicRepos(publicReposFromEnv(), true, "hivecommons", "hivecommons/hive", nil) if !pub.allows("acme/widgets") || !pub.allows("hivecommons/hive") { t.Fatalf("env allowlist and registry repos must union: %v", pub) } diff --git a/src/pkg/dashboard/hub_activity_test.go b/src/pkg/dashboard/hub_activity_test.go index 0542c96fe6..ea8f730c73 100644 --- a/src/pkg/dashboard/hub_activity_test.go +++ b/src/pkg/dashboard/hub_activity_test.go @@ -52,7 +52,8 @@ func TestHubActivityItemsReadsTheMemoisedTracker(t *testing.T) { s := newTestServer() s.stageStore = stagelabels.NewStore("", func() time.Time { return now }) s.deps = &Dependencies{Config: &config.Config{ - Project: config.ProjectConfig{Org: "acme", PrimaryRepo: "acme/widget", Repos: []string{"acme/widget"}}, + // Bare names, as config loading leaves them after stripping the org. + Project: config.ProjectConfig{Org: "acme", PrimaryRepo: "widget", Repos: []string{"widget"}}, Hub: config.HubConfig{IsPublic: true}, }} builds := 0