Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Unified Diff: milo/appengine/buildbot/build.go

Issue 2718373004: Milo: Print raw json for buildbot build properties (Closed)
Patch Set: Add in empty strings Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | milo/appengine/buildbot/expectations/CrWinGoma.30608.build.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/appengine/buildbot/build.go
diff --git a/milo/appengine/buildbot/build.go b/milo/appengine/buildbot/build.go
index 289b53592dbd5f3146e9d0fa95120449cf5a1416..ff849722415e0eab2655cb4a6c30e804690aced4 100644
--- a/milo/appengine/buildbot/build.go
+++ b/milo/appengine/buildbot/build.go
@@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io/ioutil"
+ "math"
"path/filepath"
"regexp"
"sort"
@@ -313,49 +314,22 @@ func components(b *buildbotBuild) (result []*resp.BuildComponent) {
return
}
-// parseProp returns a representation of v based off k, and a boolean to
-// specify whether or not to hide it altogether.
-func parseProp(prop map[string]Prop, k string, v interface{}) (string, bool) {
- switch k {
- case "requestedAt":
- if vf, ok := v.(float64); ok {
- return time.Unix(int64(vf), 0).UTC().Format(time.RFC3339), true
- }
- case "buildbucket":
- var b map[string]interface{}
- json.Unmarshal([]byte(v.(string)), &b)
- if b["build"] == nil {
- return "", false
- }
- build := b["build"].(map[string]interface{})
- id := build["id"]
- if id == nil {
- return "", false
- }
- return fmt.Sprintf("https://cr-buildbucket.appspot.com/b/%s", id.(string)), true
- case "issue":
- if rv, ok := prop["rietveld"]; ok {
- rietveld := rv.Value.(string)
- // Issue could be a float, int, or string.
- switch v := v.(type) {
- case float64:
- return fmt.Sprintf("%s/%d", rietveld, int(v)), true
- default: // Probably int or string
- return fmt.Sprintf("%s/%v", rietveld, v), true
- }
- }
- return fmt.Sprintf("%d", int(v.(float64))), true
- case "rietveld":
- return "", false
- default:
- if vs, ok := v.(string); ok && vs == "" {
- return "", false // Value is empty, don't show it.
- }
- if v == nil {
- return "", false
+// parseProp returns a string representation of v.
+func parseProp(v interface{}) string {
+ // if v is a whole number, force it into an int. json.Marshal() would turn
+ // it into what looks like a float instead. We want this to remain and
+ // int instead of a number.
+ if vf, ok := v.(float64); ok {
+ if math.Floor(vf) == vf {
+ return fmt.Sprintf("%d", int64(vf))
}
}
- return fmt.Sprintf("%v", v), true
+ // return the json representation of the value.
+ b, err := json.Marshal(v)
+ if err == nil {
+ return string(b)
+ }
+ return fmt.Sprintf("%v", v)
}
// Prop is a struct used to store a value and group so that we can make a map
@@ -383,10 +357,7 @@ func properties(b *buildbotBuild) (result []*resp.PropertyGroup) {
if _, ok := groups[groupName]; !ok {
groups[groupName] = &resp.PropertyGroup{GroupName: groupName}
}
- vs, ok := parseProp(allProps, key, value)
- if !ok {
- continue
- }
+ vs := parseProp(value)
groups[groupName].Property = append(groups[groupName].Property, &resp.Property{
Key: key,
Value: vs,
« no previous file with comments | « no previous file | milo/appengine/buildbot/expectations/CrWinGoma.30608.build.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698