| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package swarmingV1 |
| 6 |
| 7 import ( |
| 8 "sort" |
| 9 |
| 10 swarm "github.com/luci/luci-go/common/api/swarming/swarming/v1" |
| 11 ) |
| 12 |
| 13 // ToCipdPackage converts this to a swarming api SwarmingRpcsCipdPackage. |
| 14 func (c *CipdPackage) ToCipdPackage() *swarm.SwarmingRpcsCipdPackage { |
| 15 if c == nil { |
| 16 return nil |
| 17 } |
| 18 return &swarm.SwarmingRpcsCipdPackage{PackageName: c.Name, Version: c.Ve
rsion} |
| 19 } |
| 20 |
| 21 // ToCipdInput converts this to a swarming api SwarmingRpcsCipdInput. |
| 22 func (c *CipdSpec) ToCipdInput() *swarm.SwarmingRpcsCipdInput { |
| 23 if c == nil || c.Client == nil && len(c.ByPath) == 0 { |
| 24 return nil |
| 25 } |
| 26 ret := &swarm.SwarmingRpcsCipdInput{ |
| 27 ClientPackage: c.Client.ToCipdPackage(), |
| 28 } |
| 29 if len(c.ByPath) > 0 { |
| 30 count := 0 |
| 31 paths := make(sort.StringSlice, 0, len(c.ByPath)) |
| 32 for path, pkgs := range c.ByPath { |
| 33 paths = append(paths, path) |
| 34 count += len(pkgs.Pkg) |
| 35 } |
| 36 ret.Packages = make([]*swarm.SwarmingRpcsCipdPackage, 0, count) |
| 37 for _, path := range paths { |
| 38 for _, pkg := range c.ByPath[path].Pkg { |
| 39 retPkg := pkg.ToCipdPackage() |
| 40 retPkg.Path = path |
| 41 ret.Packages = append(ret.Packages, retPkg) |
| 42 } |
| 43 } |
| 44 } |
| 45 return ret |
| 46 } |
| OLD | NEW |