1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

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
This commit is contained in:
Amaury Séchet 2021-06-19 13:09:54 +00:00
parent 2258ba8535
commit e7740c8669
8 changed files with 67 additions and 18 deletions

View file

@ -1478,13 +1478,13 @@ phutil_register_library_map(array(
'HarbormasterBuildableTransactionEditor' => 'applications/harbormaster/editor/HarbormasterBuildableTransactionEditor.php',
'HarbormasterBuildableTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildableTransactionQuery.php',
'HarbormasterBuildableViewController' => 'applications/harbormaster/controller/HarbormasterBuildableViewController.php',
'HarbormasterBuildkiteBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php',
'HarbormasterBuildkiteBuildStepImplementation' => 'applications/harbormaster/integration/buildkite/HarbormasterBuildkiteBuildStepImplementation.php',
'HarbormasterBuildkiteBuildableInterface' => 'applications/harbormaster/interface/HarbormasterBuildkiteBuildableInterface.php',
'HarbormasterBuildkiteHookController' => 'applications/harbormaster/controller/HarbormasterBuildkiteHookController.php',
'HarbormasterBuildkiteHookHandler' => 'applications/harbormaster/integration/buildkite/HarbormasterBuildkiteHookHandler.php',
'HarbormasterBuiltinBuildStepGroup' => 'applications/harbormaster/stepgroup/HarbormasterBuiltinBuildStepGroup.php',
'HarbormasterCircleCIBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterCircleCIBuildStepImplementation.php',
'HarbormasterCircleCIBuildStepImplementation' => 'applications/harbormaster/integration/circleci/HarbormasterCircleCIBuildStepImplementation.php',
'HarbormasterCircleCIBuildableInterface' => 'applications/harbormaster/interface/HarbormasterCircleCIBuildableInterface.php',
'HarbormasterCircleCIHookController' => 'applications/harbormaster/controller/HarbormasterCircleCIHookController.php',
'HarbormasterCircleCIHookHandler' => 'applications/harbormaster/integration/circleci/HarbormasterCircleCIHookHandler.php',
'HarbormasterConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterConduitAPIMethod.php',
'HarbormasterControlBuildStepGroup' => 'applications/harbormaster/stepgroup/HarbormasterControlBuildStepGroup.php',
'HarbormasterController' => 'applications/harbormaster/controller/HarbormasterController.php',
@ -1498,6 +1498,8 @@ phutil_register_library_map(array(
'HarbormasterExternalBuildStepGroup' => 'applications/harbormaster/stepgroup/HarbormasterExternalBuildStepGroup.php',
'HarbormasterFileArtifact' => 'applications/harbormaster/artifact/HarbormasterFileArtifact.php',
'HarbormasterHTTPRequestBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterHTTPRequestBuildStepImplementation.php',
'HarbormasterHookController' => 'applications/harbormaster/controller/HarbormasterHookController.php',
'HarbormasterHookHandler' => 'applications/harbormaster/integration/HarbormasterHookHandler.php',
'HarbormasterHostArtifact' => 'applications/harbormaster/artifact/HarbormasterHostArtifact.php',
'HarbormasterLeaseWorkingCopyBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterLeaseWorkingCopyBuildStepImplementation.php',
'HarbormasterLintMessagesController' => 'applications/harbormaster/controller/HarbormasterLintMessagesController.php',
@ -7727,10 +7729,10 @@ phutil_register_library_map(array(
'HarbormasterBuildableTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'HarbormasterBuildableViewController' => 'HarbormasterController',
'HarbormasterBuildkiteBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
'HarbormasterBuildkiteHookController' => 'HarbormasterController',
'HarbormasterBuildkiteHookHandler' => 'HarbormasterHookHandler',
'HarbormasterBuiltinBuildStepGroup' => 'HarbormasterBuildStepGroup',
'HarbormasterCircleCIBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
'HarbormasterCircleCIHookController' => 'HarbormasterController',
'HarbormasterCircleCIHookHandler' => 'HarbormasterHookHandler',
'HarbormasterConduitAPIMethod' => 'ConduitAPIMethod',
'HarbormasterControlBuildStepGroup' => 'HarbormasterBuildStepGroup',
'HarbormasterController' => 'PhabricatorController',
@ -7744,6 +7746,8 @@ phutil_register_library_map(array(
'HarbormasterExternalBuildStepGroup' => 'HarbormasterBuildStepGroup',
'HarbormasterFileArtifact' => 'HarbormasterArtifact',
'HarbormasterHTTPRequestBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
'HarbormasterHookController' => 'HarbormasterController',
'HarbormasterHookHandler' => 'Phobject',
'HarbormasterHostArtifact' => 'HarbormasterDrydockLeaseArtifact',
'HarbormasterLeaseWorkingCopyBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
'HarbormasterLintMessagesController' => 'HarbormasterController',

View file

@ -94,10 +94,7 @@ final class PhabricatorHarbormasterApplication extends PhabricatorApplication {
'lint/' => array(
'(?P<id>\d+)/' => 'HarbormasterLintMessagesController',
),
'hook/' => array(
'circleci/' => 'HarbormasterCircleCIHookController',
'buildkite/' => 'HarbormasterBuildkiteHookController',
),
'hook/(?P<handler>[^/]+)/' => 'HarbormasterHookController',
'log/' => array(
'view/(?P<id>\d+)/(?:\$(?P<lines>\d+(?:-\d+)?))?'
=> 'HarbormasterBuildLogViewController',

View file

@ -0,0 +1,21 @@
<?php
final class HarbormasterHookController
extends HarbormasterController {
public function shouldRequireLogin() {
return false;
}
public function handleRequest(AphrontRequest $request) {
$name = $request->getURIData('handler');
$handler = HarbormasterHookHandler::getHandler($name);
if (!$handler) {
throw new Exception(pht('No handler found for %s', $name));
}
return $handler->handleRequest($request);
}
}

View file

@ -0,0 +1,27 @@
<?php
abstract class HarbormasterHookHandler
extends Phobject {
public static function getHandlers() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getName')
->execute();
}
public static function getHandler($handler) {
$base = idx(self::getHandlers(), $handler);
if ($base) {
return (clone $base);
}
return null;
}
abstract public function getName();
abstract public function handleRequest(AphrontRequest $request);
}

View file

@ -1,10 +1,10 @@
<?php
final class HarbormasterBuildkiteHookController
extends HarbormasterController {
final class HarbormasterBuildkiteHookHandler
extends HarbormasterHookHandler {
public function shouldRequireLogin() {
return false;
public function getName() {
return 'buildkite';
}
/**

View file

@ -1,10 +1,10 @@
<?php
final class HarbormasterCircleCIHookController
extends HarbormasterController {
final class HarbormasterCircleCIHookHandler
extends HarbormasterHookHandler {
public function shouldRequireLogin() {
return false;
public function getName() {
return 'circleci';
}
/**