@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.

Add a CircleCI webhook

Summary: Ref T9456. This makes everything work, except that CircleCI doesn't fetch tags which are not ancestors of branch heads.

Test Plan: Ran passing builds through CircleCI.

Reviewers: chad

Reviewed By: chad

Subscribers: dpaola2, JustinTulloss

Maniphest Tasks: T9456

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

+112 -3
+2
src/__phutil_library_map__.php
··· 1108 1108 'HarbormasterBuiltinBuildStepGroup' => 'applications/harbormaster/stepgroup/HarbormasterBuiltinBuildStepGroup.php', 1109 1109 'HarbormasterCircleCIBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterCircleCIBuildStepImplementation.php', 1110 1110 'HarbormasterCircleCIBuildableInterface' => 'applications/harbormaster/interface/HarbormasterCircleCIBuildableInterface.php', 1111 + 'HarbormasterCircleCIHookController' => 'applications/harbormaster/controller/HarbormasterCircleCIHookController.php', 1111 1112 'HarbormasterConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterConduitAPIMethod.php', 1112 1113 'HarbormasterController' => 'applications/harbormaster/controller/HarbormasterController.php', 1113 1114 'HarbormasterCreateArtifactConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterCreateArtifactConduitAPIMethod.php', ··· 5338 5339 'HarbormasterBuildableViewController' => 'HarbormasterController', 5339 5340 'HarbormasterBuiltinBuildStepGroup' => 'HarbormasterBuildStepGroup', 5340 5341 'HarbormasterCircleCIBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 5342 + 'HarbormasterCircleCIHookController' => 'HarbormasterController', 5341 5343 'HarbormasterConduitAPIMethod' => 'ConduitAPIMethod', 5342 5344 'HarbormasterController' => 'PhabricatorController', 5343 5345 'HarbormasterCreateArtifactConduitAPIMethod' => 'HarbormasterConduitAPIMethod',
+3
src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php
··· 91 91 'lint/' => array( 92 92 '(?P<id>\d+)/' => 'HarbormasterLintMessagesController', 93 93 ), 94 + 'hook/' => array( 95 + 'circleci/' => 'HarbormasterCircleCIHookController', 96 + ), 94 97 ), 95 98 ); 96 99 }
+87
src/applications/harbormaster/controller/HarbormasterCircleCIHookController.php
··· 1 + <?php 2 + 3 + final class HarbormasterCircleCIHookController 4 + extends HarbormasterController { 5 + 6 + public function shouldRequireLogin() { 7 + return false; 8 + } 9 + 10 + /** 11 + * @phutil-external-symbol class PhabricatorStartup 12 + */ 13 + public function handleRequest(AphrontRequest $request) { 14 + $raw_body = PhabricatorStartup::getRawInput(); 15 + $body = phutil_json_decode($raw_body); 16 + 17 + $payload = $body['payload']; 18 + 19 + $parameters = idx($payload, 'build_parameters'); 20 + if (!$parameters) { 21 + $parameters = array(); 22 + } 23 + 24 + $target_phid = idx($parameters, 'HARBORMASTER_BUILD_TARGET_PHID'); 25 + 26 + // NOTE: We'll get callbacks here for builds we triggered, but also for 27 + // arbitrary builds the system executes for other reasons. So it's normal 28 + // to get some notifications with no Build Target PHID. We just ignore 29 + // these under the assumption that they're routine builds caused by events 30 + // like branch updates. 31 + 32 + if ($target_phid) { 33 + $viewer = PhabricatorUser::getOmnipotentUser(); 34 + $target = id(new HarbormasterBuildTargetQuery()) 35 + ->setViewer($viewer) 36 + ->withPHIDs(array($target_phid)) 37 + ->needBuildSteps(true) 38 + ->executeOne(); 39 + if ($target) { 40 + $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); 41 + $this->updateTarget($target, $payload); 42 + } 43 + } 44 + 45 + $response = new AphrontWebpageResponse(); 46 + $response->setContent(pht("Request OK\n")); 47 + return $response; 48 + } 49 + 50 + private function updateTarget( 51 + HarbormasterBuildTarget $target, 52 + array $payload) { 53 + 54 + $step = $target->getBuildStep(); 55 + $impl = $step->getStepImplementation(); 56 + if (!($impl instanceof HarbormasterCircleCIBuildStepImplementation)) { 57 + throw new Exception( 58 + pht( 59 + 'Build target ("%s") has the wrong type of build step. Only '. 60 + 'CircleCI build steps may be updated via the CircleCI webhook.', 61 + $target->getPHID())); 62 + } 63 + 64 + switch (idx($payload, 'status')) { 65 + case 'success': 66 + case 'fixed': 67 + $message_type = HarbormasterMessageType::MESSAGE_PASS; 68 + break; 69 + default: 70 + $message_type = HarbormasterMessageType::MESSAGE_FAIL; 71 + break; 72 + } 73 + 74 + $viewer = PhabricatorUser::getOmnipotentUser(); 75 + 76 + $api_method = 'harbormaster.sendmessage'; 77 + $api_params = array( 78 + 'buildTargetPHID' => $target->getPHID(), 79 + 'type' => $message_type, 80 + ); 81 + 82 + id(new ConduitCall($api_method, $api_params)) 83 + ->setUser($viewer) 84 + ->execute(); 85 + } 86 + 87 + }
+14 -2
src/applications/harbormaster/step/HarbormasterCircleCIBuildStepImplementation.php
··· 20 20 } 21 21 22 22 public function getEditInstructions() { 23 + $hook_uri = '/harbormaster/hook/circleci/'; 24 + $hook_uri = PhabricatorEnv::getProductionURI($hook_uri); 25 + 23 26 return pht(<<<EOTEXT 24 27 WARNING: This build step is new and experimental! 25 28 ··· 38 41 Webhook Configuration 39 42 ===================== 40 43 41 - IMPORTANT: This has not been implemented yet. 44 + Add this webhook to your `circle.yml` file to make CircleCI report results 45 + to Harbormaster. Until you install this hook, builds will hang waiting for 46 + a response from CircleCI. 47 + 48 + ```lang=yml 49 + notify: 50 + webhooks: 51 + - url: %s 52 + ``` 42 53 43 54 Environment 44 55 =========== ··· 50 61 | `HARBORMASTER_BUILD_TARGET_PHID` | PHID of the Build Target. 51 62 52 63 EOTEXT 53 - ); 64 + , 65 + $hook_uri); 54 66 } 55 67 56 68 public static function getGitHubPath($uri) {
+6 -1
src/applications/harbormaster/storage/HarbormasterBuildMessage.php
··· 17 17 private $buildTarget = self::ATTACHABLE; 18 18 19 19 public static function initializeNewMessage(PhabricatorUser $actor) { 20 + $actor_phid = $actor->getPHID(); 21 + if (!$actor_phid) { 22 + $actor_phid = id(new PhabricatorHarbormasterApplication())->getPHID(); 23 + } 24 + 20 25 return id(new HarbormasterBuildMessage()) 21 - ->setAuthorPHID($actor->getPHID()) 26 + ->setAuthorPHID($actor_phid) 22 27 ->setIsConsumed(0); 23 28 } 24 29