| 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 "errors" | 9 "errors" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 sort.Sort(group) | 377 sort.Sort(group) |
| 378 result = append(result, group) | 378 result = append(result, group) |
| 379 } | 379 } |
| 380 return | 380 return |
| 381 } | 381 } |
| 382 | 382 |
| 383 // blame extracts the commit and blame information from a buildbot build and | 383 // blame extracts the commit and blame information from a buildbot build and |
| 384 // returns it as a list of Commits. | 384 // returns it as a list of Commits. |
| 385 func blame(b *buildbotBuild) (result []*resp.Commit) { | 385 func blame(b *buildbotBuild) (result []*resp.Commit) { |
| 386 for _, c := range b.Sourcestamp.Changes { | 386 for _, c := range b.Sourcestamp.Changes { |
| 387 » » files := make([]string, len(c.Files)) | 387 » » files := c.GetFiles() |
| 388 » » for i, f := range c.Files { | |
| 389 » » » // Buildbot stores files both as a string, or as a dict
with a single entry | |
| 390 » » » // named "name". It doesn't matter to us what the type
is, but we need | |
| 391 » » » // to reflect on the type anyways. | |
| 392 » » » if fn, ok := f.(string); ok { | |
| 393 » » » » files[i] = fn | |
| 394 » » » } else if fn, ok := f.(struct{ Name string }); ok { | |
| 395 » » » » files[i] = fn.Name | |
| 396 » » » } | |
| 397 » » } | |
| 398 result = append(result, &resp.Commit{ | 388 result = append(result, &resp.Commit{ |
| 399 AuthorEmail: c.Who, | 389 AuthorEmail: c.Who, |
| 400 Repo: c.Repository, | 390 Repo: c.Repository, |
| 401 » » » Revision: c.Revision, | 391 » » » CommitTime: time.Unix(int64(c.When), 0), |
| 392 » » » Revision: &resp.Link{ |
| 393 » » » » URL: c.Revlink, |
| 394 » » » » Label: c.Revision, |
| 395 » » » }, |
| 402 Description: c.Comments, | 396 Description: c.Comments, |
| 403 Title: strings.Split(c.Comments, "\n")[0], | 397 Title: strings.Split(c.Comments, "\n")[0], |
| 404 File: files, | 398 File: files, |
| 405 }) | 399 }) |
| 406 } | 400 } |
| 407 return | 401 return |
| 408 } | 402 } |
| 409 | 403 |
| 410 // sourcestamp extracts the source stamp from various parts of a buildbot build, | 404 // sourcestamp extracts the source stamp from various parts of a buildbot build, |
| 411 // including the properties. | 405 // including the properties. |
| 412 func sourcestamp(c context.Context, b *buildbotBuild) *resp.SourceStamp { | 406 func sourcestamp(c context.Context, b *buildbotBuild) *resp.SourceStamp { |
| 413 ss := &resp.SourceStamp{} | 407 ss := &resp.SourceStamp{} |
| 414 rietveld := "" | 408 rietveld := "" |
| 409 got_revision := "" |
| 410 repository := "" |
| 415 issue := int64(-1) | 411 issue := int64(-1) |
| 416 // TODO(hinoka): Gerrit URLs. | 412 // TODO(hinoka): Gerrit URLs. |
| 417 for _, prop := range b.Properties { | 413 for _, prop := range b.Properties { |
| 418 switch prop.Name { | 414 switch prop.Name { |
| 419 case "rietveld": | 415 case "rietveld": |
| 420 if v, ok := prop.Value.(string); ok { | 416 if v, ok := prop.Value.(string); ok { |
| 421 rietveld = v | 417 rietveld = v |
| 422 } else { | 418 } else { |
| 423 logging.Warningf(c, "Field rietveld is not a str
ing: %#v", prop.Value) | 419 logging.Warningf(c, "Field rietveld is not a str
ing: %#v", prop.Value) |
| 424 } | 420 } |
| 425 case "issue": | 421 case "issue": |
| 426 if v, ok := prop.Value.(float64); ok { | 422 if v, ok := prop.Value.(float64); ok { |
| 427 issue = int64(v) | 423 issue = int64(v) |
| 428 } else { | 424 } else { |
| 429 logging.Warningf(c, "Field issue is not a float:
%#v", prop.Value) | 425 logging.Warningf(c, "Field issue is not a float:
%#v", prop.Value) |
| 430 } | 426 } |
| 431 | 427 |
| 432 case "got_revision": | 428 case "got_revision": |
| 433 if v, ok := prop.Value.(string); ok { | 429 if v, ok := prop.Value.(string); ok { |
| 434 » » » » ss.Revision = v | 430 » » » » got_revision = v |
| 435 } else { | 431 } else { |
| 436 logging.Warningf(c, "Field got_revision is not a
string: %#v", prop.Value) | 432 logging.Warningf(c, "Field got_revision is not a
string: %#v", prop.Value) |
| 437 } | 433 } |
| 438 | 434 |
| 435 case "repository": |
| 436 if v, ok := prop.Value.(string); ok { |
| 437 repository = v |
| 438 } |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 if issue != -1 { | 441 if issue != -1 { |
| 442 if rietveld != "" { | 442 if rietveld != "" { |
| 443 rietveld = strings.TrimRight(rietveld, "/") | 443 rietveld = strings.TrimRight(rietveld, "/") |
| 444 ss.Changelist = &resp.Link{ | 444 ss.Changelist = &resp.Link{ |
| 445 Label: fmt.Sprintf("Issue %d", issue), | 445 Label: fmt.Sprintf("Issue %d", issue), |
| 446 URL: fmt.Sprintf("%s/%d", rietveld, issue), | 446 URL: fmt.Sprintf("%s/%d", rietveld, issue), |
| 447 } | 447 } |
| 448 } else { | 448 } else { |
| 449 logging.Warningf(c, "Found issue but not rietveld proper
ty.") | 449 logging.Warningf(c, "Found issue but not rietveld proper
ty.") |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 if got_revision != "" { |
| 453 ss.Revision = &resp.Link{ |
| 454 Label: got_revision, |
| 455 } |
| 456 if repository != "" { |
| 457 ss.Revision.URL = repository + "/+/" + got_revision |
| 458 } |
| 459 } |
| 452 return ss | 460 return ss |
| 453 } | 461 } |
| 454 | 462 |
| 455 func getDebugBuild(c context.Context, builder string, buildNum int) (*buildbotBu
ild, error) { | 463 func getDebugBuild(c context.Context, builder string, buildNum int) (*buildbotBu
ild, error) { |
| 456 fname := fmt.Sprintf("%s.%d.json", builder, buildNum) | 464 fname := fmt.Sprintf("%s.%d.json", builder, buildNum) |
| 457 // ../buildbot below assumes that | 465 // ../buildbot below assumes that |
| 458 // - this code is not executed by tests outside of this dir | 466 // - this code is not executed by tests outside of this dir |
| 459 // - this dir is a sibling of frontend dir | 467 // - this dir is a sibling of frontend dir |
| 460 path := filepath.Join("..", "buildbot", "testdata", fname) | 468 path := filepath.Join("..", "buildbot", "testdata", fname) |
| 461 raw, err := ioutil.ReadFile(path) | 469 raw, err := ioutil.ReadFile(path) |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 var newAliases map[string][]*buildbotLinkAlias | 638 var newAliases map[string][]*buildbotLinkAlias |
| 631 if l := remainingAliases.Len(); l > 0 { | 639 if l := remainingAliases.Len(); l > 0 { |
| 632 newAliases = make(map[string][]*buildbotLinkAlias, l) | 640 newAliases = make(map[string][]*buildbotLinkAlias, l) |
| 633 remainingAliases.Iter(func(v string) bool { | 641 remainingAliases.Iter(func(v string) bool { |
| 634 newAliases[v] = s.Aliases[v] | 642 newAliases[v] = s.Aliases[v] |
| 635 return true | 643 return true |
| 636 }) | 644 }) |
| 637 } | 645 } |
| 638 s.Aliases = newAliases | 646 s.Aliases = newAliases |
| 639 } | 647 } |
| OLD | NEW |