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

Side by Side Diff: appengine/cmd/milo/buildbot/build.go

Issue 2102903002: Milo: Extract the rietveld information from buildbot. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Review Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | appengine/cmd/milo/buildbot/expectations/CrWinGoma.30608.build.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "fmt" 9 "fmt"
10 "io/ioutil" 10 "io/ioutil"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 Repo: c.Repository, 334 Repo: c.Repository,
335 Revision: c.Revision, 335 Revision: c.Revision,
336 Description: c.Comments, 336 Description: c.Comments,
337 Title: strings.Split(c.Comments, "\n")[0], 337 Title: strings.Split(c.Comments, "\n")[0],
338 File: files, 338 File: files,
339 }) 339 })
340 } 340 }
341 return 341 return
342 } 342 }
343 343
344 // sourcestamp extracts the source stamp from various parts of a buildbot build,
345 // including the properties.
346 func sourcestamp(c context.Context, b *buildbotBuild) *resp.SourceStamp {
347 ss := &resp.SourceStamp{}
348 rietveld := ""
349 issue := int64(-1)
350 // TODO(hinoka): Gerrit URLs.
351 for _, prop := range b.Properties {
352 key := prop[0].(string)
nodir 2016/06/28 21:44:24 please add a comment to buildbotBuild.Properties t
Ryan Tseng 2016/06/28 21:49:31 Done.
353 value := prop[1]
354 switch key {
355 case "rietveld":
356 if v, ok := value.(string); ok {
357 rietveld = v
358 } else {
359 log.Warningf(c, "Field rietveld is not a string: %#v", value)
360 }
361 case "issue":
362 if v, ok := value.(float64); ok {
363 issue = int64(v)
364 } else {
365 log.Warningf(c, "Field issue is not a float: %#v ", value)
366 }
367
368 case "got_revision":
369 if v, ok := value.(string); ok {
370 ss.Revision = v
371 } else {
372 log.Warningf(c, "Field got_revision is not a str ing: %#v", value)
373 }
374
375 }
376 }
377 if issue != -1 {
378 if rietveld != "" {
379 rietveld = strings.TrimRight(rietveld, "/")
380 ss.Changelist = &resp.Link{
381 Label: fmt.Sprintf("Issue %d", issue),
382 URL: fmt.Sprintf("%s/%d", rietveld, issue),
383 }
384 } else {
385 log.Warningf(c, "Found issue but not rietveld property." )
386 }
387 }
388 return ss
389 }
390
344 func getDebugBuild(c context.Context, builder, buildNum string) (*buildbotBuild, error) { 391 func getDebugBuild(c context.Context, builder, buildNum string) (*buildbotBuild, error) {
345 fname := fmt.Sprintf("%s.%s.json", builder, buildNum) 392 fname := fmt.Sprintf("%s.%s.json", builder, buildNum)
346 path := filepath.Join("testdata", "buildbot", fname) 393 path := filepath.Join("testdata", "buildbot", fname)
347 raw, err := ioutil.ReadFile(path) 394 raw, err := ioutil.ReadFile(path)
348 if err != nil { 395 if err != nil {
349 return nil, err 396 return nil, err
350 } 397 }
351 b := &buildbotBuild{} 398 b := &buildbotBuild{}
352 return b, json.Unmarshal(raw, b) 399 return b, json.Unmarshal(raw, b)
353 } 400 }
354 401
355 // build fetches a buildbot build and translates it into a miloBuild. 402 // build fetches a buildbot build and translates it into a miloBuild.
356 func build(c context.Context, master, builder, buildNum string) (*resp.MiloBuild , error) { 403 func build(c context.Context, master, builder, buildNum string) (*resp.MiloBuild , error) {
357 var b *buildbotBuild 404 var b *buildbotBuild
358 var err error 405 var err error
359 if master == "debug" { 406 if master == "debug" {
360 b, err = getDebugBuild(c, builder, buildNum) 407 b, err = getDebugBuild(c, builder, buildNum)
361 } else { 408 } else {
362 b, err = getBuild(c, master, builder, buildNum) 409 b, err = getBuild(c, master, builder, buildNum)
363 } 410 }
364 if err != nil { 411 if err != nil {
365 return nil, err 412 return nil, err
366 } 413 }
367 414
415 // TODO(hinoka): Do all fields concurrently.
368 return &resp.MiloBuild{ 416 return &resp.MiloBuild{
417 SourceStamp: sourcestamp(c, b),
369 Summary: summary(b), 418 Summary: summary(b),
370 Components: components(b), 419 Components: components(b),
371 PropertyGroup: properties(b), 420 PropertyGroup: properties(b),
372 Blame: blame(b), 421 Blame: blame(b),
373 }, nil 422 }, nil
374 } 423 }
OLDNEW
« no previous file with comments | « no previous file | appengine/cmd/milo/buildbot/expectations/CrWinGoma.30608.build.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698