@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 HarbormasterHookController as an entry point for all Harbormaster hooks

Summary: This makes the set of hooks easily extensible, as a first step toward integrating more 3rd party CI in phorge.

Test Plan: Send requests to `/harbormaster/hook/circleci/` and `/harbormaster/hook/buildkite/` and check they run the proper handler.

Reviewers: O1 Blessed Committers, Matthew

Reviewed By: O1 Blessed Committers, Matthew

Subscribers: Matthew, speck, tobiaswiese

Maniphest Tasks: T15018

Differential Revision: https://we.phorge.it/D25005

+67 -18
+10 -6
src/__phutil_library_map__.php
··· 1478 1478 'HarbormasterBuildableTransactionEditor' => 'applications/harbormaster/editor/HarbormasterBuildableTransactionEditor.php', 1479 1479 'HarbormasterBuildableTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildableTransactionQuery.php', 1480 1480 'HarbormasterBuildableViewController' => 'applications/harbormaster/controller/HarbormasterBuildableViewController.php', 1481 - 'HarbormasterBuildkiteBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php', 1481 + 'HarbormasterBuildkiteBuildStepImplementation' => 'applications/harbormaster/integration/buildkite/HarbormasterBuildkiteBuildStepImplementation.php', 1482 1482 'HarbormasterBuildkiteBuildableInterface' => 'applications/harbormaster/interface/HarbormasterBuildkiteBuildableInterface.php', 1483 - 'HarbormasterBuildkiteHookController' => 'applications/harbormaster/controller/HarbormasterBuildkiteHookController.php', 1483 + 'HarbormasterBuildkiteHookHandler' => 'applications/harbormaster/integration/buildkite/HarbormasterBuildkiteHookHandler.php', 1484 1484 'HarbormasterBuiltinBuildStepGroup' => 'applications/harbormaster/stepgroup/HarbormasterBuiltinBuildStepGroup.php', 1485 - 'HarbormasterCircleCIBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterCircleCIBuildStepImplementation.php', 1485 + 'HarbormasterCircleCIBuildStepImplementation' => 'applications/harbormaster/integration/circleci/HarbormasterCircleCIBuildStepImplementation.php', 1486 1486 'HarbormasterCircleCIBuildableInterface' => 'applications/harbormaster/interface/HarbormasterCircleCIBuildableInterface.php', 1487 - 'HarbormasterCircleCIHookController' => 'applications/harbormaster/controller/HarbormasterCircleCIHookController.php', 1487 + 'HarbormasterCircleCIHookHandler' => 'applications/harbormaster/integration/circleci/HarbormasterCircleCIHookHandler.php', 1488 1488 'HarbormasterConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterConduitAPIMethod.php', 1489 1489 'HarbormasterControlBuildStepGroup' => 'applications/harbormaster/stepgroup/HarbormasterControlBuildStepGroup.php', 1490 1490 'HarbormasterController' => 'applications/harbormaster/controller/HarbormasterController.php', ··· 1498 1498 'HarbormasterExternalBuildStepGroup' => 'applications/harbormaster/stepgroup/HarbormasterExternalBuildStepGroup.php', 1499 1499 'HarbormasterFileArtifact' => 'applications/harbormaster/artifact/HarbormasterFileArtifact.php', 1500 1500 'HarbormasterHTTPRequestBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterHTTPRequestBuildStepImplementation.php', 1501 + 'HarbormasterHookController' => 'applications/harbormaster/controller/HarbormasterHookController.php', 1502 + 'HarbormasterHookHandler' => 'applications/harbormaster/integration/HarbormasterHookHandler.php', 1501 1503 'HarbormasterHostArtifact' => 'applications/harbormaster/artifact/HarbormasterHostArtifact.php', 1502 1504 'HarbormasterLeaseWorkingCopyBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterLeaseWorkingCopyBuildStepImplementation.php', 1503 1505 'HarbormasterLintMessagesController' => 'applications/harbormaster/controller/HarbormasterLintMessagesController.php', ··· 7727 7729 'HarbormasterBuildableTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 7728 7730 'HarbormasterBuildableViewController' => 'HarbormasterController', 7729 7731 'HarbormasterBuildkiteBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 7730 - 'HarbormasterBuildkiteHookController' => 'HarbormasterController', 7732 + 'HarbormasterBuildkiteHookHandler' => 'HarbormasterHookHandler', 7731 7733 'HarbormasterBuiltinBuildStepGroup' => 'HarbormasterBuildStepGroup', 7732 7734 'HarbormasterCircleCIBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 7733 - 'HarbormasterCircleCIHookController' => 'HarbormasterController', 7735 + 'HarbormasterCircleCIHookHandler' => 'HarbormasterHookHandler', 7734 7736 'HarbormasterConduitAPIMethod' => 'ConduitAPIMethod', 7735 7737 'HarbormasterControlBuildStepGroup' => 'HarbormasterBuildStepGroup', 7736 7738 'HarbormasterController' => 'PhabricatorController', ··· 7744 7746 'HarbormasterExternalBuildStepGroup' => 'HarbormasterBuildStepGroup', 7745 7747 'HarbormasterFileArtifact' => 'HarbormasterArtifact', 7746 7748 'HarbormasterHTTPRequestBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 7749 + 'HarbormasterHookController' => 'HarbormasterController', 7750 + 'HarbormasterHookHandler' => 'Phobject', 7747 7751 'HarbormasterHostArtifact' => 'HarbormasterDrydockLeaseArtifact', 7748 7752 'HarbormasterLeaseWorkingCopyBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 7749 7753 'HarbormasterLintMessagesController' => 'HarbormasterController',
+1 -4
src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php
··· 94 94 'lint/' => array( 95 95 '(?P<id>\d+)/' => 'HarbormasterLintMessagesController', 96 96 ), 97 - 'hook/' => array( 98 - 'circleci/' => 'HarbormasterCircleCIHookController', 99 - 'buildkite/' => 'HarbormasterBuildkiteHookController', 100 - ), 97 + 'hook/(?P<handler>[^/]+)/' => 'HarbormasterHookController', 101 98 'log/' => array( 102 99 'view/(?P<id>\d+)/(?:\$(?P<lines>\d+(?:-\d+)?))?' 103 100 => 'HarbormasterBuildLogViewController',
+4 -4
src/applications/harbormaster/controller/HarbormasterBuildkiteHookController.php src/applications/harbormaster/integration/buildkite/HarbormasterBuildkiteHookHandler.php
··· 1 1 <?php 2 2 3 - final class HarbormasterBuildkiteHookController 4 - extends HarbormasterController { 3 + final class HarbormasterBuildkiteHookHandler 4 + extends HarbormasterHookHandler { 5 5 6 - public function shouldRequireLogin() { 7 - return false; 6 + public function getName() { 7 + return 'buildkite'; 8 8 } 9 9 10 10 /**
+4 -4
src/applications/harbormaster/controller/HarbormasterCircleCIHookController.php src/applications/harbormaster/integration/circleci/HarbormasterCircleCIHookHandler.php
··· 1 1 <?php 2 2 3 - final class HarbormasterCircleCIHookController 4 - extends HarbormasterController { 3 + final class HarbormasterCircleCIHookHandler 4 + extends HarbormasterHookHandler { 5 5 6 - public function shouldRequireLogin() { 7 - return false; 6 + public function getName() { 7 + return 'circleci'; 8 8 } 9 9 10 10 /**
+21
src/applications/harbormaster/controller/HarbormasterHookController.php
··· 1 + <?php 2 + 3 + final class HarbormasterHookController 4 + extends HarbormasterController { 5 + 6 + public function shouldRequireLogin() { 7 + return false; 8 + } 9 + 10 + public function handleRequest(AphrontRequest $request) { 11 + $name = $request->getURIData('handler'); 12 + $handler = HarbormasterHookHandler::getHandler($name); 13 + 14 + if (!$handler) { 15 + throw new Exception(pht('No handler found for %s', $name)); 16 + } 17 + 18 + return $handler->handleRequest($request); 19 + } 20 + 21 + }
+27
src/applications/harbormaster/integration/HarbormasterHookHandler.php
··· 1 + <?php 2 + 3 + abstract class HarbormasterHookHandler 4 + extends Phobject { 5 + 6 + public static function getHandlers() { 7 + return id(new PhutilClassMapQuery()) 8 + ->setAncestorClass(__CLASS__) 9 + ->setUniqueMethod('getName') 10 + ->execute(); 11 + } 12 + 13 + public static function getHandler($handler) { 14 + $base = idx(self::getHandlers(), $handler); 15 + 16 + if ($base) { 17 + return (clone $base); 18 + } 19 + 20 + return null; 21 + } 22 + 23 + abstract public function getName(); 24 + 25 + abstract public function handleRequest(AphrontRequest $request); 26 + 27 + }
src/applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php src/applications/harbormaster/integration/buildkite/HarbormasterBuildkiteBuildStepImplementation.php
src/applications/harbormaster/step/HarbormasterCircleCIBuildStepImplementation.php src/applications/harbormaster/integration/circleci/HarbormasterCircleCIBuildStepImplementation.php