3 final class HarbormasterCircleCIHookController
4 extends HarbormasterController
{
6 public function shouldRequireLogin() {
11 * @phutil-external-symbol class PhabricatorStartup
13 public function handleRequest(AphrontRequest
$request) {
14 $raw_body = PhabricatorStartup
::getRawInput();
15 $body = phutil_json_decode($raw_body);
17 $payload = $body['payload'];
19 $parameters = idx($payload, 'build_parameters');
21 $parameters = array();
24 $target_phid = idx($parameters, 'HARBORMASTER_BUILD_TARGET_PHID');
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.
33 $viewer = PhabricatorUser
::getOmnipotentUser();
34 $target = id(new HarbormasterBuildTargetQuery())
36 ->withPHIDs(array($target_phid))
37 ->needBuildSteps(true)
40 $unguarded = AphrontWriteGuard
::beginScopedUnguardedWrites();
41 $this->updateTarget($target, $payload);
45 $response = new AphrontWebpageResponse();
46 $response->setContent(pht("Request OK\n"));
50 private function updateTarget(
51 HarbormasterBuildTarget
$target,
54 $step = $target->getBuildStep();
55 $impl = $step->getStepImplementation();
56 if (!($impl instanceof HarbormasterCircleCIBuildStepImplementation
)) {
59 'Build target ("%s") has the wrong type of build step. Only '.
60 'CircleCI build steps may be updated via the CircleCI webhook.',
64 switch (idx($payload, 'status')) {
67 $message_type = HarbormasterMessageType
::MESSAGE_PASS
;
70 $message_type = HarbormasterMessageType
::MESSAGE_FAIL
;
74 $viewer = PhabricatorUser
::getOmnipotentUser();
76 $api_method = 'harbormaster.sendmessage';
78 'buildTargetPHID' => $target->getPHID(),
79 'type' => $message_type,
82 id(new ConduitCall($api_method, $api_params))