Index: milo/appengine/job_source/buildbot/build.go |
diff --git a/milo/appengine/buildbot/build.go b/milo/appengine/job_source/buildbot/build.go |
similarity index 97% |
rename from milo/appengine/buildbot/build.go |
rename to milo/appengine/job_source/buildbot/build.go |
index 1d88681de1e3d1e6f65cb10094e320d21c25313f..52bc2e64b8ade8d3db254a86b398b9f284461a20 100644 |
--- a/milo/appengine/buildbot/build.go |
+++ b/milo/appengine/job_source/buildbot/build.go |
@@ -447,44 +447,45 @@ func sourcestamp(c context.Context, b *buildbotBuild) *resp.SourceStamp { |
return ss |
} |
-func getDebugBuild(c context.Context, builder string, buildNum int) (*buildbotBuild, error) { |
+func renderBuild(c context.Context, b *buildbotBuild) *resp.MiloBuild { |
+ // Modify the build for rendering. |
+ updatePostProcessBuild(b) |
+ |
+ // TODO(hinoka): Do all fields concurrently. |
+ return &resp.MiloBuild{ |
+ SourceStamp: sourcestamp(c, b), |
+ Summary: summary(c, b), |
+ Components: components(b), |
+ PropertyGroup: properties(b), |
+ Blame: blame(b), |
+ } |
+} |
+ |
+// DebugBuild fetches a debugging build for testing. |
+func DebugBuild(c context.Context, relBuildbotDir string, builder string, buildNum int) (*resp.MiloBuild, error) { |
fname := fmt.Sprintf("%s.%d.json", builder, buildNum) |
// ../buildbot below assumes that |
// - this code is not executed by tests outside of this dir |
// - this dir is a sibling of frontend dir |
- path := filepath.Join("..", "buildbot", "testdata", fname) |
+ path := filepath.Join(relBuildbotDir, "testdata", fname) |
raw, err := ioutil.ReadFile(path) |
if err != nil { |
return nil, err |
} |
b := &buildbotBuild{} |
- return b, json.Unmarshal(raw, b) |
+ if err := json.Unmarshal(raw, b); err != nil { |
+ return nil, err |
+ } |
+ return renderBuild(c, b), nil |
} |
-// build fetches a buildbot build and translates it into a miloBuild. |
+// Build fetches a buildbot build and translates it into a miloBuild. |
func Build(c context.Context, master, builder string, buildNum int) (*resp.MiloBuild, error) { |
- var b *buildbotBuild |
- var err error |
- if master == "debug" { |
- b, err = getDebugBuild(c, builder, buildNum) |
- } else { |
- b, err = getBuild(c, master, builder, buildNum) |
- } |
+ b, err := getBuild(c, master, builder, buildNum) |
if err != nil { |
return nil, err |
} |
- |
- // Modify the build for rendering. |
- updatePostProcessBuild(b) |
- |
- // TODO(hinoka): Do all fields concurrently. |
- return &resp.MiloBuild{ |
- SourceStamp: sourcestamp(c, b), |
- Summary: summary(c, b), |
- Components: components(b), |
- PropertyGroup: properties(b), |
- Blame: blame(b), |
- }, nil |
+ return renderBuild(c, b), nil |
} |
// updatePostProcessBuild transforms a build from its raw JSON format into the |