diff --git a/internal/app/teams.go b/internal/app/teams.go index 48217868..0386da65 100644 --- a/internal/app/teams.go +++ b/internal/app/teams.go @@ -184,8 +184,10 @@ $ tea team view 2 --json units`, if a.options.json != "" { return a.writeJSON(cmd, team) } + // Gitea shows a public team to non-members of its organization, but not its members. members, err := service.Members(cmd.Context(), team.ID, teamViewNames, 1) - if err != nil { + membersHidden := services.IsForbidden(err) + if err != nil && !membersHidden { return err } repos, err := service.Repositories(cmd.Context(), team.ID, teamViewNames, 1) @@ -199,6 +201,10 @@ $ tea team view 2 --json units`, units = append(units, strings.TrimPrefix(unit, "repo.")+": "+access) } } + memberNames := "" + if !membersHidden { + memberNames = listedNames(members, func(member services.OrganizationMember) string { return member.Username }) + } repositories := listedNames(repos, func(repo services.Repository) string { return repo.FullName }) if team.AllRepositories { repositories = "all repositories of " + team.Organization @@ -208,7 +214,7 @@ $ tea team view 2 --json units`, Fields: []terminal.Field{ {Label: "Access", Value: team.Access(), PipedOnly: true}, {Label: "Units", Value: strings.Join(units, ", ")}, - {Label: "Members", Value: listedNames(members, func(member services.OrganizationMember) string { return member.Username })}, + {Label: "Members", Value: memberNames}, {Label: "Repositories", Value: repositories}, {Label: "Can create repos", Value: yesNo(team.CanCreateRepo)}, }, diff --git a/internal/services/errors.go b/internal/services/errors.go index 21e27cd8..9f7f97dc 100644 --- a/internal/services/errors.go +++ b/internal/services/errors.go @@ -198,6 +198,12 @@ func IsNotFound(err error) bool { return ok && failure.Status == http.StatusNotFound } +// IsForbidden reports whether err is a 403 response. +func IsForbidden(err error) bool { + failure, ok := errors.AsType[*transport.APIError](err) + return ok && failure.Status == http.StatusForbidden +} + // refusal returns the conflict reason of a refused request, or "". func refusal(apiErr *transport.APIError) string { if apiErr.Status == http.StatusLocked {