Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(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) | |
| 353 value := prop[1] | |
| 354 switch key { | |
| 355 case "rietveld": | |
| 356 rietveld = value.(string) | |
| 357 case "issue": | |
| 358 issue = int64(value.(float64)) | |
| 359 case "got_revision": | |
| 360 ss.Revision = value.(string) | |
| 361 } | |
| 362 } | |
|
nodir
2016/06/28 02:06:44
This code will panic if user input malformed, we s
Ryan Tseng
2016/06/28 21:49:31
Done.
| |
| 363 if issue != -1 && rietveld == "" { | |
| 364 // Default rietveld server | |
| 365 rietveld = "https://codereview.chromium.org" | |
|
nodir
2016/06/28 02:06:44
Do we have to define defaults in our code? Do we h
Ryan Tseng
2016/06/28 21:49:31
Not sure, this is just incase. I'll remove this
| |
| 366 } | |
| 367 if issue != -1 { | |
| 368 ss.Changelist = &resp.Link{ | |
| 369 Label: fmt.Sprintf("Issue %d", issue), | |
| 370 URL: fmt.Sprintf("%s/%d", rietveld, issue), | |
|
nodir
2016/06/28 02:06:44
What if rietveld ends with /
Trim it
Ryan Tseng
2016/06/28 21:49:31
Done.
| |
| 371 } | |
| 372 } | |
| 373 return ss | |
| 374 } | |
| 375 | |
| 344 func getDebugBuild(c context.Context, builder, buildNum string) (*buildbotBuild, error) { | 376 func getDebugBuild(c context.Context, builder, buildNum string) (*buildbotBuild, error) { |
| 345 fname := fmt.Sprintf("%s.%s.json", builder, buildNum) | 377 fname := fmt.Sprintf("%s.%s.json", builder, buildNum) |
| 346 path := filepath.Join("testdata", "buildbot", fname) | 378 path := filepath.Join("testdata", "buildbot", fname) |
| 347 raw, err := ioutil.ReadFile(path) | 379 raw, err := ioutil.ReadFile(path) |
| 348 if err != nil { | 380 if err != nil { |
| 349 return nil, err | 381 return nil, err |
| 350 } | 382 } |
| 351 b := &buildbotBuild{} | 383 b := &buildbotBuild{} |
| 352 return b, json.Unmarshal(raw, b) | 384 return b, json.Unmarshal(raw, b) |
| 353 } | 385 } |
| 354 | 386 |
| 355 // build fetches a buildbot build and translates it into a miloBuild. | 387 // build fetches a buildbot build and translates it into a miloBuild. |
| 356 func build(c context.Context, master, builder, buildNum string) (*resp.MiloBuild , error) { | 388 func build(c context.Context, master, builder, buildNum string) (*resp.MiloBuild , error) { |
| 357 var b *buildbotBuild | 389 var b *buildbotBuild |
| 358 var err error | 390 var err error |
| 359 if master == "debug" { | 391 if master == "debug" { |
| 360 b, err = getDebugBuild(c, builder, buildNum) | 392 b, err = getDebugBuild(c, builder, buildNum) |
| 361 } else { | 393 } else { |
| 362 b, err = getBuild(c, master, builder, buildNum) | 394 b, err = getBuild(c, master, builder, buildNum) |
| 363 } | 395 } |
| 364 if err != nil { | 396 if err != nil { |
| 365 return nil, err | 397 return nil, err |
| 366 } | 398 } |
| 367 | 399 |
| 368 return &resp.MiloBuild{ | 400 return &resp.MiloBuild{ |
| 401 SourceStamp: sourcestamp(b), | |
| 369 Summary: summary(b), | 402 Summary: summary(b), |
| 370 Components: components(b), | 403 Components: components(b), |
| 371 PropertyGroup: properties(b), | 404 PropertyGroup: properties(b), |
| 372 Blame: blame(b), | 405 Blame: blame(b), |
| 373 }, nil | 406 }, nil |
| 374 } | 407 } |
| OLD | NEW |