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

at recaptime-dev/main 87 lines 2.5 kB view raw
1<?php 2 3final class HarbormasterCircleCIHookHandler 4 extends HarbormasterHookHandler { 5 6 public function getName() { 7 return 'circleci'; 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}