Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog.d/fixed-16234-public-activity-bare-repos.md
Original file line number Diff line number Diff line change
@@ -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)).
23 changes: 19 additions & 4 deletions src/pkg/dashboard/battle_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "..")
}
Expand Down
23 changes: 20 additions & 3 deletions src/pkg/dashboard/battle_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/dashboard/hub_activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading