| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2016 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package rawpresentation | 15 package rawpresentation |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "encoding/json" |
| 18 "fmt" | 19 "fmt" |
| 19 "time" | 20 "time" |
| 20 | 21 |
| 21 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 22 | 23 |
| 23 "github.com/luci/luci-go/common/clock" | 24 "github.com/luci/luci-go/common/clock" |
| 24 "github.com/luci/luci-go/common/proto/google" | 25 "github.com/luci/luci-go/common/proto/google" |
| 25 miloProto "github.com/luci/luci-go/common/proto/milo" | 26 miloProto "github.com/luci/luci-go/common/proto/milo" |
| 26 "github.com/luci/luci-go/milo/api/resp" | 27 "github.com/luci/luci-go/milo/api/resp" |
| 27 "github.com/luci/luci-go/milo/common/model" | 28 "github.com/luci/luci-go/milo/common/model" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // AddLogDogToBuild takes a set of logdog streams and populate a milo build. | 199 // AddLogDogToBuild takes a set of logdog streams and populate a milo build. |
| 199 // build.Summary.Finished must be set. | 200 // build.Summary.Finished must be set. |
| 200 func AddLogDogToBuild( | 201 func AddLogDogToBuild( |
| 201 c context.Context, ub URLBuilder, mainAnno *miloProto.Step, build *resp.
MiloBuild) { | 202 c context.Context, ub URLBuilder, mainAnno *miloProto.Step, build *resp.
MiloBuild) { |
| 202 now := clock.Now(c) | 203 now := clock.Now(c) |
| 203 | 204 |
| 204 // Now fill in each of the step components. | 205 // Now fill in each of the step components. |
| 205 // TODO(hinoka): This is totes cachable. | 206 // TODO(hinoka): This is totes cachable. |
| 206 buildCompletedTime := google.TimeFromProto(mainAnno.Ended) | 207 buildCompletedTime := google.TimeFromProto(mainAnno.Ended) |
| 207 build.Summary = *(miloBuildStep(ub, mainAnno, true, buildCompletedTime,
now)[0]) | 208 build.Summary = *(miloBuildStep(ub, mainAnno, true, buildCompletedTime,
now)[0]) |
| 209 propMap := map[string]string{} |
| 208 for _, substepContainer := range mainAnno.Substep { | 210 for _, substepContainer := range mainAnno.Substep { |
| 209 anno := substepContainer.GetStep() | 211 anno := substepContainer.GetStep() |
| 210 if anno == nil { | 212 if anno == nil { |
| 211 // TODO: We ignore non-embedded substeps for now. | 213 // TODO: We ignore non-embedded substeps for now. |
| 212 continue | 214 continue |
| 213 } | 215 } |
| 214 | 216 |
| 215 bss := miloBuildStep(ub, anno, false, buildCompletedTime, now) | 217 bss := miloBuildStep(ub, anno, false, buildCompletedTime, now) |
| 216 for _, bs := range bss { | 218 for _, bs := range bss { |
| 217 if bs.Status != model.Success { | 219 if bs.Status != model.Success { |
| 218 build.Summary.Text = append( | 220 build.Summary.Text = append( |
| 219 build.Summary.Text, fmt.Sprintf("%s %s",
bs.Status, bs.Label)) | 221 build.Summary.Text, fmt.Sprintf("%s %s",
bs.Status, bs.Label)) |
| 220 } | 222 } |
| 221 build.Components = append(build.Components, bs) | 223 build.Components = append(build.Components, bs) |
| 222 propGroup := &resp.PropertyGroup{GroupName: bs.Label} | 224 propGroup := &resp.PropertyGroup{GroupName: bs.Label} |
| 223 for _, prop := range anno.Property { | 225 for _, prop := range anno.Property { |
| 224 propGroup.Property = append(propGroup.Property,
&resp.Property{ | 226 propGroup.Property = append(propGroup.Property,
&resp.Property{ |
| 225 Key: prop.Name, | 227 Key: prop.Name, |
| 226 Value: prop.Value, | 228 Value: prop.Value, |
| 227 }) | 229 }) |
| 230 propMap[prop.Name] = prop.Value |
| 228 } | 231 } |
| 229 build.PropertyGroup = append(build.PropertyGroup, propGr
oup) | 232 build.PropertyGroup = append(build.PropertyGroup, propGr
oup) |
| 230 } | 233 } |
| 231 } | 234 } |
| 232 | 235 |
| 233 // Take care of properties | 236 // Take care of properties |
| 234 propGroup := &resp.PropertyGroup{GroupName: "Main"} | 237 propGroup := &resp.PropertyGroup{GroupName: "Main"} |
| 235 for _, prop := range mainAnno.Property { | 238 for _, prop := range mainAnno.Property { |
| 236 propGroup.Property = append(propGroup.Property, &resp.Property{ | 239 propGroup.Property = append(propGroup.Property, &resp.Property{ |
| 237 Key: prop.Name, | 240 Key: prop.Name, |
| 238 Value: prop.Value, | 241 Value: prop.Value, |
| 239 }) | 242 }) |
| 243 propMap[prop.Name] = prop.Value |
| 240 } | 244 } |
| 241 build.PropertyGroup = append(build.PropertyGroup, propGroup) | 245 build.PropertyGroup = append(build.PropertyGroup, propGroup) |
| 242 | 246 |
| 247 // HACK(hinoka,iannucci): Extract revision out of properties. |
| 248 if jrev, ok := propMap["got_revision"]; ok { |
| 249 // got_revision is a json string, so it looks like "aaaaaabbcc12
3..." |
| 250 var rev string |
| 251 err := json.Unmarshal([]byte(jrev), &rev) |
| 252 if err == nil { |
| 253 if build.SourceStamp == nil { |
| 254 build.SourceStamp = &resp.SourceStamp{} |
| 255 } |
| 256 build.SourceStamp.Revision = resp.NewLink( |
| 257 rev, fmt.Sprintf("https://crrev.com/%s", rev)) |
| 258 } |
| 259 } |
| 260 |
| 243 return | 261 return |
| 244 } | 262 } |
| OLD | NEW |