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 "errors" | 9 "errors" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 | 508 |
| 509 // updatePostProcessBuild transforms a build from its raw JSON format into the | 509 // updatePostProcessBuild transforms a build from its raw JSON format into the |
| 510 // format that should be presented to users. | 510 // format that should be presented to users. |
| 511 // | 511 // |
| 512 // Post-processing includes: | 512 // Post-processing includes: |
| 513 // - If the build is LogDog-only, promotes aliases (LogDog links) to | 513 // - If the build is LogDog-only, promotes aliases (LogDog links) to |
| 514 // first-class links in the build. | 514 // first-class links in the build. |
| 515 func updatePostProcessBuild(b *buildbotBuild) { | 515 func updatePostProcessBuild(b *buildbotBuild) { |
| 516 // If this is a LogDog-only build, we want to promote the LogDog links. | 516 // If this is a LogDog-only build, we want to promote the LogDog links. |
| 517 if loc, ok := b.getPropertyValue("log_location").(string); ok && strings .HasPrefix(loc, "logdog://") { | 517 if loc, ok := b.getPropertyValue("log_location").(string); ok && strings .HasPrefix(loc, "logdog://") { |
| 518 linkMap := make(map[string]string) | |
|
hinoka
2017/03/27 23:40:29
nit: map[string]string{} will do.
dnj
2017/03/27 23:44:51
Done.
| |
| 518 for sidx := range b.Steps { | 519 for sidx := range b.Steps { |
| 519 » » » promoteLogDogLinks(&b.Steps[sidx], sidx == 0) | 520 » » » promoteLogDogLinks(&b.Steps[sidx], sidx == 0, linkMap) |
| 521 » » } | |
| 522 | |
| 523 » » // Update "Logs". This field is part of BuildBot, and is the ama lgamation | |
| 524 » » // of all logs in the build's steps. Since each log is out of co ntext of its | |
| 525 » » // original step, we can't apply the promotion logic; instead, w e will use | |
| 526 » » // the link map to map any old URLs that were matched in "promot eLogDogLnks" | |
| 527 » » // to their new URLs. | |
| 528 » » for _, link := range b.Logs { | |
| 529 » » » // "link" is in the form: [NAME, URL] | |
| 530 » » » if len(link) != 2 { | |
| 531 » » » » continue | |
| 532 » » » } | |
| 533 | |
| 534 » » » if newURL, ok := linkMap[link[1]]; ok { | |
| 535 » » » » link[1] = newURL | |
| 536 » » » } | |
| 520 } | 537 } |
| 521 } | 538 } |
| 522 } | 539 } |
| 523 | 540 |
| 524 // promoteLogDogLinks updates the links in a BuildBot step to | 541 // promoteLogDogLinks updates the links in a BuildBot step to |
| 525 // promote LogDog links. | 542 // promote LogDog links. |
| 526 // | 543 // |
| 527 // A build's links come in one of three forms: | 544 // A build's links come in one of three forms: |
| 528 // - Log Links, which link directly to BuildBot build logs. | 545 // - Log Links, which link directly to BuildBot build logs. |
| 529 // - URL Links, which are named links to arbitrary URLs. | 546 // - URL Links, which are named links to arbitrary URLs. |
| 530 // - Aliases, which attach to the label in one of the other types of links and | 547 // - Aliases, which attach to the label in one of the other types of links and |
| 531 // augment it with additional named links. | 548 // augment it with additional named links. |
| 532 // | 549 // |
| 533 // LogDog uses aliases exclusively to attach LogDog logs to other links. When | 550 // LogDog uses aliases exclusively to attach LogDog logs to other links. When |
| 534 // the build is LogDog-only, though, the original links are actually junk. What | 551 // the build is LogDog-only, though, the original links are actually junk. What |
| 535 // we want to do is remove the original junk links and replace them with their | 552 // we want to do is remove the original junk links and replace them with their |
| 536 // alias counterparts, so that the "natural" BuildBot links are actually LogDog | 553 // alias counterparts, so that the "natural" BuildBot links are actually LogDog |
| 537 // links. | 554 // links. |
| 538 func promoteLogDogLinks(s *buildbotStep, isInitialStep bool) { | 555 // |
| 556 // As URLs are re-mapped, the supplied "linkMap" will be updated to map the old | |
| 557 // URLs to the new ones. | |
| 558 func promoteLogDogLinks(s *buildbotStep, isInitialStep bool, linkMap map[string] string) { | |
| 539 type stepLog struct { | 559 type stepLog struct { |
| 540 label string | 560 label string |
| 541 url string | 561 url string |
| 542 } | 562 } |
| 543 | 563 |
| 544 remainingAliases := stringset.New(len(s.Aliases)) | 564 remainingAliases := stringset.New(len(s.Aliases)) |
| 545 for linkAnchor := range s.Aliases { | 565 for linkAnchor := range s.Aliases { |
| 546 remainingAliases.Add(linkAnchor) | 566 remainingAliases.Add(linkAnchor) |
| 547 } | 567 } |
| 548 | 568 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 573 // Any link named "logdog" (Annotee cosmetic implementat ion detail) will | 593 // Any link named "logdog" (Annotee cosmetic implementat ion detail) will |
| 574 // inherit the name of the original log. | 594 // inherit the name of the original log. |
| 575 if !isLog { | 595 if !isLog { |
| 576 if aliasStepLog.label == "logdog" { | 596 if aliasStepLog.label == "logdog" { |
| 577 aliasStepLog.label = sl.label | 597 aliasStepLog.label = sl.label |
| 578 } | 598 } |
| 579 } | 599 } |
| 580 | 600 |
| 581 result[i] = &aliasStepLog | 601 result[i] = &aliasStepLog |
| 582 } | 602 } |
| 603 | |
| 604 // If we performed mapping, add the OLD -> NEW URL mapping to li nkMap. | |
| 605 if len(result) > 0 { | |
|
hinoka
2017/03/27 23:40:29
Add comment about why this chooses the last result
dnj
2017/03/27 23:44:51
Done.
| |
| 606 linkMap[sl.url] = result[len(result)-1].url | |
| 607 } | |
| 608 | |
| 583 return result | 609 return result |
| 584 } | 610 } |
| 585 | 611 |
| 586 // Update step logs. | 612 // Update step logs. |
| 587 newLogs := make([][]string, 0, len(s.Logs)) | 613 newLogs := make([][]string, 0, len(s.Logs)) |
| 588 for _, l := range s.Logs { | 614 for _, l := range s.Logs { |
| 589 for _, res := range maybePromoteAliases(&stepLog{l[0], l[1]}, tr ue) { | 615 for _, res := range maybePromoteAliases(&stepLog{l[0], l[1]}, tr ue) { |
| 590 newLogs = append(newLogs, []string{res.label, res.url}) | 616 newLogs = append(newLogs, []string{res.label, res.url}) |
| 591 } | 617 } |
| 592 } | 618 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 613 var newAliases map[string][]*buildbotLinkAlias | 639 var newAliases map[string][]*buildbotLinkAlias |
| 614 if l := remainingAliases.Len(); l > 0 { | 640 if l := remainingAliases.Len(); l > 0 { |
| 615 newAliases = make(map[string][]*buildbotLinkAlias, l) | 641 newAliases = make(map[string][]*buildbotLinkAlias, l) |
| 616 remainingAliases.Iter(func(v string) bool { | 642 remainingAliases.Iter(func(v string) bool { |
| 617 newAliases[v] = s.Aliases[v] | 643 newAliases[v] = s.Aliases[v] |
| 618 return true | 644 return true |
| 619 }) | 645 }) |
| 620 } | 646 } |
| 621 s.Aliases = newAliases | 647 s.Aliases = newAliases |
| 622 } | 648 } |
| OLD | NEW |