@@ -308,40 +308,38 @@ func ToTeam(ctx context.Context, team *organization.Team, loadOrg ...bool) (*api
308308
309309// ToTeams convert models.Team list to api.Team list
310310func 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-
315311 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 {
319315 return nil , err
320316 }
321317
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 (),
331327 }
332328
333329 if loadOrgs {
334- apiOrg , ok := cache [teams [ i ] .OrgID ]
330+ apiOrg , ok := cache [t .OrgID ]
335331 if ! ok {
336- org , err := organization .GetOrgByID (ctx , teams [ i ] .OrgID )
332+ org , err := organization .GetOrgByID (ctx , t .OrgID )
337333 if err != nil {
338334 return nil , err
339335 }
340336 apiOrg = ToOrganization (ctx , org )
341- cache [teams [ i ] .OrgID ] = apiOrg
337+ cache [t .OrgID ] = apiOrg
342338 }
343- apiTeams [ i ] .Organization = apiOrg
339+ apiTeam .Organization = apiOrg
344340 }
341+
342+ apiTeams = append (apiTeams , apiTeam )
345343 }
346344 return apiTeams , nil
347345}
0 commit comments