@@ -308,40 +308,38 @@ func ToTeam(ctx context.Context, team *organization.Team, loadOrg ...bool) (*api
308
308
309
309
// ToTeams convert models.Team list to api.Team list
310
310
func ToTeams (ctx context.Context , teams []* organization.Team , loadOrgs bool ) ([]* api.Team , error ) {
311
- if len (teams ) == 0 || teams [0 ] == nil {
312
- return nil , nil
313
- }
314
-
315
311
cache := make (map [int64 ]* api.Organization )
316
- apiTeams := make ([]* api.Team , len (teams ))
317
- for i := range teams {
318
- if err := teams [ i ] .LoadUnits (ctx ); err != nil {
312
+ apiTeams := make ([]* api.Team , 0 , len (teams ))
313
+ for _ , t := range teams {
314
+ if err := t .LoadUnits (ctx ); err != nil {
319
315
return nil , err
320
316
}
321
317
322
- apiTeams [ i ] = & api.Team {
323
- ID : teams [ i ] .ID ,
324
- Name : teams [ i ] .Name ,
325
- Description : teams [ i ] .Description ,
326
- IncludesAllRepositories : teams [ i ] .IncludesAllRepositories ,
327
- CanCreateOrgRepo : teams [ i ] .CanCreateOrgRepo ,
328
- Permission : teams [ i ] .AccessMode .String (),
329
- Units : teams [ i ] .GetUnitNames (),
330
- UnitsMap : teams [ i ] .GetUnitsMap (),
318
+ apiTeam : = & api.Team {
319
+ ID : t .ID ,
320
+ Name : t .Name ,
321
+ Description : t .Description ,
322
+ IncludesAllRepositories : t .IncludesAllRepositories ,
323
+ CanCreateOrgRepo : t .CanCreateOrgRepo ,
324
+ Permission : t .AccessMode .String (),
325
+ Units : t .GetUnitNames (),
326
+ UnitsMap : t .GetUnitsMap (),
331
327
}
332
328
333
329
if loadOrgs {
334
- apiOrg , ok := cache [teams [ i ] .OrgID ]
330
+ apiOrg , ok := cache [t .OrgID ]
335
331
if ! ok {
336
- org , err := organization .GetOrgByID (ctx , teams [ i ] .OrgID )
332
+ org , err := organization .GetOrgByID (ctx , t .OrgID )
337
333
if err != nil {
338
334
return nil , err
339
335
}
340
336
apiOrg = ToOrganization (ctx , org )
341
- cache [teams [ i ] .OrgID ] = apiOrg
337
+ cache [t .OrgID ] = apiOrg
342
338
}
343
- apiTeams [ i ] .Organization = apiOrg
339
+ apiTeam .Organization = apiOrg
344
340
}
341
+
342
+ apiTeams = append (apiTeams , apiTeam )
345
343
}
346
344
return apiTeams , nil
347
345
}
0 commit comments