mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-10 07:26:33 -04:00
Provide list, add, and remove operations for team members via
'tea teams members {list,create,delete}'. The members package reuses
the RequireTeamID helper exported by cmd/teams.
98 lines
2 KiB
Go
98 lines
2 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package print
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"gitea.dev/sdk"
|
|
)
|
|
|
|
// TeamsList prints a list of teams in an organization.
|
|
func TeamsList(teams []*gitea.Team, output, orgName string) {
|
|
if len(teams) == 0 {
|
|
fmt.Printf("No teams found in organization '%s'\n", orgName)
|
|
return
|
|
}
|
|
|
|
t := tableWithHeader(
|
|
"ID",
|
|
"Name",
|
|
"Description",
|
|
"Permission",
|
|
"Can Create Repo",
|
|
"All Repos",
|
|
)
|
|
|
|
for _, team := range teams {
|
|
t.addRow(
|
|
strconv.FormatInt(team.ID, 10),
|
|
team.Name,
|
|
team.Description,
|
|
string(team.Permission),
|
|
yesNo(team.CanCreateOrgRepo),
|
|
yesNo(team.IncludesAllRepositories),
|
|
)
|
|
}
|
|
|
|
fmt.Printf("Teams in organization '%s':\n", orgName)
|
|
t.print(output)
|
|
}
|
|
|
|
// TeamDetails prints detailed information about a team.
|
|
func TeamDetails(team *gitea.Team, output string) {
|
|
fmt.Printf("# Team: %s (ID: %d)\n\n", team.Name, team.ID)
|
|
fmt.Printf("- **Description**: %s\n", team.Description)
|
|
fmt.Printf("- **Permission**: %s\n", team.Permission)
|
|
fmt.Printf("- **Can Create Org Repo**: %t\n", team.CanCreateOrgRepo)
|
|
fmt.Printf("- **Includes All Repositories**: %t\n", team.IncludesAllRepositories)
|
|
|
|
if len(team.Units) > 0 {
|
|
fmt.Printf("- **Repository Units**:\n")
|
|
for _, unit := range team.Units {
|
|
fmt.Printf(" - %s\n", unit)
|
|
}
|
|
}
|
|
|
|
if team.Organization != nil {
|
|
fmt.Printf("- **Organization**: %s\n", team.Organization.UserName)
|
|
}
|
|
}
|
|
|
|
// yesNo maps a bool to a human-readable "yes"/"no" string for table output.
|
|
func yesNo(b bool) string {
|
|
if b {
|
|
return "yes"
|
|
}
|
|
return "no"
|
|
}
|
|
|
|
// TeamMembersList prints a list of team members.
|
|
func TeamMembersList(members []*gitea.User, output, teamName string) {
|
|
if len(members) == 0 {
|
|
fmt.Printf("No members found in team '%s'\n", teamName)
|
|
return
|
|
}
|
|
|
|
t := tableWithHeader(
|
|
"ID",
|
|
"Username",
|
|
"Full Name",
|
|
"Email",
|
|
)
|
|
|
|
for _, m := range members {
|
|
t.addRow(
|
|
strconv.FormatInt(m.ID, 10),
|
|
m.UserName,
|
|
m.FullName,
|
|
m.Email,
|
|
)
|
|
}
|
|
|
|
fmt.Printf("Members of team '%s':\n", teamName)
|
|
t.print(output)
|
|
}
|