@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Navigage Buildkite builds with more nuance

Summary:
Ref T12173.

- If we want to fetch a tag, Buildkite needs it as a "branch" (this means more like "ref to fetch").
- The API gets upset if we pass "refs/tags/...", so just pass the tag name without the prefix, which works.
- Do a better job with commits and pass a real branch to fetch.

Test Plan:
- Built a commit with Buildkite.
- Build a revision with Buildkite.

Reviewers: chad

Reviewed By: chad

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T12173

Differential Revision: https://secure.phabricator.com/D17282

+78 -3
+3
src/__phutil_library_map__.php
··· 1211 1211 'HarbormasterBuildableTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildableTransactionQuery.php', 1212 1212 'HarbormasterBuildableViewController' => 'applications/harbormaster/controller/HarbormasterBuildableViewController.php', 1213 1213 'HarbormasterBuildkiteBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php', 1214 + 'HarbormasterBuildkiteBuildableInterface' => 'applications/harbormaster/interface/HarbormasterBuildkiteBuildableInterface.php', 1214 1215 'HarbormasterBuildkiteHookController' => 'applications/harbormaster/controller/HarbormasterBuildkiteHookController.php', 1215 1216 'HarbormasterBuiltinBuildStepGroup' => 'applications/harbormaster/stepgroup/HarbormasterBuiltinBuildStepGroup.php', 1216 1217 'HarbormasterCircleCIBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterCircleCIBuildStepImplementation.php', ··· 5091 5092 'PhabricatorExtendedPolicyInterface', 5092 5093 'HarbormasterBuildableInterface', 5093 5094 'HarbormasterCircleCIBuildableInterface', 5095 + 'HarbormasterBuildkiteBuildableInterface', 5094 5096 'PhabricatorApplicationTransactionInterface', 5095 5097 'PhabricatorDestructibleInterface', 5096 5098 ), ··· 8789 8791 'PhabricatorMentionableInterface', 8790 8792 'HarbormasterBuildableInterface', 8791 8793 'HarbormasterCircleCIBuildableInterface', 8794 + 'HarbormasterBuildkiteBuildableInterface', 8792 8795 'PhabricatorCustomFieldInterface', 8793 8796 'PhabricatorApplicationTransactionInterface', 8794 8797 'PhabricatorFulltextInterface',
+22
src/applications/differential/storage/DifferentialDiff.php
··· 7 7 PhabricatorExtendedPolicyInterface, 8 8 HarbormasterBuildableInterface, 9 9 HarbormasterCircleCIBuildableInterface, 10 + HarbormasterBuildkiteBuildableInterface, 10 11 PhabricatorApplicationTransactionInterface, 11 12 PhabricatorDestructibleInterface { 12 13 ··· 620 621 $ref = preg_replace('(^refs/tags/)', '', $ref); 621 622 return $ref; 622 623 } 624 + 625 + 626 + /* -( HarbormasterBuildkiteBuildableInterface )---------------------------- */ 627 + 628 + public function getBuildkiteBranch() { 629 + $ref = $this->getStagingRef(); 630 + 631 + // NOTE: Circa late January 2017, Buildkite fails with the error message 632 + // "Tags have been disabled for this project" if we pass the "refs/tags/" 633 + // prefix via the API and the project doesn't have GitHub tag builds 634 + // enabled, even if GitHub builds are disabled. The tag builds fine 635 + // without this prefix. 636 + $ref = preg_replace('(^refs/tags/)', '', $ref); 637 + 638 + return $ref; 639 + } 640 + 641 + public function getBuildkiteCommit() { 642 + return 'HEAD'; 643 + } 644 + 623 645 624 646 public function getStagingRef() { 625 647 // TODO: We're just hoping to get lucky. Instead, `arc` should store
+11
src/applications/harbormaster/interface/HarbormasterBuildkiteBuildableInterface.php
··· 1 + <?php 2 + 3 + /** 4 + * Support for Buildkite. 5 + */ 6 + interface HarbormasterBuildkiteBuildableInterface { 7 + 8 + public function getBuildkiteBranch(); 9 + public function getBuildkiteCommit(); 10 + 11 + }
+3 -3
src/applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php
··· 75 75 $buildable = $build->getBuildable(); 76 76 77 77 $object = $buildable->getBuildableObject(); 78 - if (!($object instanceof HarbormasterCircleCIBuildableInterface)) { 78 + if (!($object instanceof HarbormasterBuildkiteBuildableInterface)) { 79 79 throw new Exception( 80 80 pht('This object does not support builds with Buildkite.')); 81 81 } ··· 89 89 $pipeline); 90 90 91 91 $data_structure = array( 92 - 'commit' => $object->getCircleCIBuildIdentifier(), 93 - 'branch' => 'master', 92 + 'commit' => $object->getBuildkiteCommit(), 93 + 'branch' => $object->getBuildkiteBranch(), 94 94 'message' => pht( 95 95 'Harbormaster Build %s ("%s") for %s', 96 96 $build->getID(),
+39
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 11 11 PhabricatorMentionableInterface, 12 12 HarbormasterBuildableInterface, 13 13 HarbormasterCircleCIBuildableInterface, 14 + HarbormasterBuildkiteBuildableInterface, 14 15 PhabricatorCustomFieldInterface, 15 16 PhabricatorApplicationTransactionInterface, 16 17 PhabricatorFulltextInterface, ··· 586 587 } 587 588 588 589 public function getCircleCIBuildIdentifier() { 590 + return $this->getCommitIdentifier(); 591 + } 592 + 593 + 594 + /* -( HarbormasterBuildkiteBuildableInterface )---------------------------- */ 595 + 596 + 597 + public function getBuildkiteBranch() { 598 + $viewer = PhabricatorUser::getOmnipotentUser(); 599 + $repository = $this->getRepository(); 600 + 601 + $branches = DiffusionQuery::callConduitWithDiffusionRequest( 602 + $viewer, 603 + DiffusionRequest::newFromDictionary( 604 + array( 605 + 'repository' => $repository, 606 + 'user' => $viewer, 607 + )), 608 + 'diffusion.branchquery', 609 + array( 610 + 'contains' => $this->getCommitIdentifier(), 611 + 'repository' => $repository->getPHID(), 612 + )); 613 + 614 + if (!$branches) { 615 + throw new Exception( 616 + pht( 617 + 'Commit "%s" is not an ancestor of any branch head, so it can not '. 618 + 'be built with Buildkite.', 619 + $this->getCommitIdentifier())); 620 + } 621 + 622 + $branch = head($branches); 623 + 624 + return 'refs/heads/'.$branch['shortName']; 625 + } 626 + 627 + public function getBuildkiteCommit() { 589 628 return $this->getCommitIdentifier(); 590 629 } 591 630