Skip to content

Commit 7eaf192

Browse files
yp05327lunny
andauthored
Rename GetUnits to LoadUnits (#22970)
Same as #22967 --------- Co-authored-by: Lunny Xiao <[email protected]>
1 parent 61b8974 commit 7eaf192

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

models/organization/team.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,8 @@ func (t *Team) ColorFormat(s fmt.State) {
111111
t.AccessMode)
112112
}
113113

114-
// GetUnits return a list of available units for a team
115-
func (t *Team) GetUnits() error {
116-
return t.getUnits(db.DefaultContext)
117-
}
118-
119-
func (t *Team) getUnits(ctx context.Context) (err error) {
114+
// LoadUnits load a list of available units for a team
115+
func (t *Team) LoadUnits(ctx context.Context) (err error) {
120116
if t.Units != nil {
121117
return nil
122118
}
@@ -193,7 +189,7 @@ func (t *Team) UnitEnabled(ctx context.Context, tp unit.Type) bool {
193189

194190
// UnitAccessMode returns if the team has the given unit type enabled
195191
func (t *Team) UnitAccessMode(ctx context.Context, tp unit.Type) perm.AccessMode {
196-
if err := t.getUnits(ctx); err != nil {
192+
if err := t.LoadUnits(ctx); err != nil {
197193
log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error())
198194
}
199195

models/organization/team_list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type TeamList []*Team
1919

2020
func (t TeamList) LoadUnits(ctx context.Context) error {
2121
for _, team := range t {
22-
if err := team.getUnits(ctx); err != nil {
22+
if err := team.LoadUnits(ctx); err != nil {
2323
return err
2424
}
2525
}

routers/api/v1/org/team.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func EditTeam(ctx *context.APIContext) {
256256

257257
form := web.GetForm(ctx).(*api.EditTeamOption)
258258
team := ctx.Org.Team
259-
if err := team.GetUnits(); err != nil {
259+
if err := team.LoadUnits(ctx); err != nil {
260260
ctx.InternalServerError(err)
261261
return
262262
}

services/convert/convert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func ToTeams(ctx context.Context, teams []*organization.Team, loadOrgs bool) ([]
304304
cache := make(map[int64]*api.Organization)
305305
apiTeams := make([]*api.Team, len(teams))
306306
for i := range teams {
307-
if err := teams[i].GetUnits(); err != nil {
307+
if err := teams[i].LoadUnits(ctx); err != nil {
308308
return nil, err
309309
}
310310

tests/integration/api_team_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestAPITeam(t *testing.T) {
111111

112112
// Read team.
113113
teamRead := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
114-
assert.NoError(t, teamRead.GetUnits())
114+
assert.NoError(t, teamRead.LoadUnits(db.DefaultContext))
115115
req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamID)
116116
resp = MakeRequest(t, req, http.StatusOK)
117117
apiTeam = api.Team{}
@@ -181,7 +181,7 @@ func TestAPITeam(t *testing.T) {
181181
resp = MakeRequest(t, req, http.StatusOK)
182182
apiTeam = api.Team{}
183183
DecodeJSON(t, resp, &apiTeam)
184-
assert.NoError(t, teamRead.GetUnits())
184+
assert.NoError(t, teamRead.LoadUnits(db.DefaultContext))
185185
checkTeamResponse(t, "ReadTeam2", &apiTeam, teamRead.Name, *teamToEditDesc.Description, teamRead.IncludesAllRepositories,
186186
teamRead.AccessMode.String(), teamRead.GetUnitNames(), teamRead.GetUnitsMap())
187187

@@ -210,7 +210,7 @@ func checkTeamResponse(t *testing.T, testName string, apiTeam *api.Team, name, d
210210

211211
func checkTeamBean(t *testing.T, id int64, name, description string, includesAllRepositories bool, permission string, units []string, unitsMap map[string]string) {
212212
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: id})
213-
assert.NoError(t, team.GetUnits(), "GetUnits")
213+
assert.NoError(t, team.LoadUnits(db.DefaultContext), "LoadUnits")
214214
apiTeam, err := convert.ToTeam(db.DefaultContext, team)
215215
assert.NoError(t, err)
216216
checkTeamResponse(t, fmt.Sprintf("checkTeamBean/%s_%s", name, description), apiTeam, name, description, includesAllRepositories, permission, units, unitsMap)

0 commit comments

Comments
 (0)