1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

Modularize "HarbormasterBuildableTransaction"

Summary: Ref T13072. Trivially convert this into a modular transaction type.

Test Plan: Issued commands to a buildable.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13072

Differential Revision: https://secure.phabricator.com/D21694
This commit is contained in:
epriestley 2021-07-16 08:44:14 -07:00
parent 706b91adf6
commit 346ffc51e1
6 changed files with 80 additions and 133 deletions

View file

@ -1475,6 +1475,7 @@ phutil_register_library_map(array(
'HarbormasterBuildableEngine' => 'applications/harbormaster/engine/HarbormasterBuildableEngine.php',
'HarbormasterBuildableInterface' => 'applications/harbormaster/interface/HarbormasterBuildableInterface.php',
'HarbormasterBuildableListController' => 'applications/harbormaster/controller/HarbormasterBuildableListController.php',
'HarbormasterBuildableMessageTransaction' => 'applications/harbormaster/xaction/buildable/HarbormasterBuildableMessageTransaction.php',
'HarbormasterBuildablePHIDType' => 'applications/harbormaster/phid/HarbormasterBuildablePHIDType.php',
'HarbormasterBuildableQuery' => 'applications/harbormaster/query/HarbormasterBuildableQuery.php',
'HarbormasterBuildableSearchAPIMethod' => 'applications/harbormaster/conduit/HarbormasterBuildableSearchAPIMethod.php',
@ -1483,6 +1484,7 @@ phutil_register_library_map(array(
'HarbormasterBuildableTransaction' => 'applications/harbormaster/storage/HarbormasterBuildableTransaction.php',
'HarbormasterBuildableTransactionEditor' => 'applications/harbormaster/editor/HarbormasterBuildableTransactionEditor.php',
'HarbormasterBuildableTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildableTransactionQuery.php',
'HarbormasterBuildableTransactionType' => 'applications/harbormaster/xaction/buildable/HarbormasterBuildableTransactionType.php',
'HarbormasterBuildableViewController' => 'applications/harbormaster/controller/HarbormasterBuildableViewController.php',
'HarbormasterBuildkiteBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php',
'HarbormasterBuildkiteBuildableInterface' => 'applications/harbormaster/interface/HarbormasterBuildkiteBuildableInterface.php',
@ -7730,14 +7732,16 @@ phutil_register_library_map(array(
'HarbormasterBuildableActionController' => 'HarbormasterController',
'HarbormasterBuildableEngine' => 'Phobject',
'HarbormasterBuildableListController' => 'HarbormasterController',
'HarbormasterBuildableMessageTransaction' => 'HarbormasterBuildableTransactionType',
'HarbormasterBuildablePHIDType' => 'PhabricatorPHIDType',
'HarbormasterBuildableQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'HarbormasterBuildableSearchAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'HarbormasterBuildableSearchEngine' => 'PhabricatorApplicationSearchEngine',
'HarbormasterBuildableStatus' => 'Phobject',
'HarbormasterBuildableTransaction' => 'PhabricatorApplicationTransaction',
'HarbormasterBuildableTransaction' => 'PhabricatorModularTransaction',
'HarbormasterBuildableTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
'HarbormasterBuildableTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'HarbormasterBuildableTransactionType' => 'PhabricatorModularTransactionType',
'HarbormasterBuildableViewController' => 'HarbormasterController',
'HarbormasterBuildkiteBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
'HarbormasterBuildkiteHookController' => 'HarbormasterController',

View file

@ -111,18 +111,14 @@ final class HarbormasterBuildableActionController
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
$xaction_type = HarbormasterBuildableMessageTransaction::TRANSACTIONTYPE;
$xaction = id(new HarbormasterBuildableTransaction())
->setTransactionType(HarbormasterBuildableTransaction::TYPE_COMMAND)
->setTransactionType($xaction_type)
->setNewValue($action);
$editor->applyTransactions($buildable, array($xaction));
$build_editor = id(new HarbormasterBuildTransactionEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
foreach ($can_send as $build) {
$build->sendMessage(
$viewer,

View file

@ -11,60 +11,4 @@ final class HarbormasterBuildableTransactionEditor
return pht('Harbormaster Buildables');
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = HarbormasterBuildableTransaction::TYPE_COMMAND;
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case HarbormasterBuildableTransaction::TYPE_COMMAND:
return null;
}
return parent::getCustomTransactionOldValue($object, $xaction);
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case HarbormasterBuildableTransaction::TYPE_COMMAND:
return $xaction->getNewValue();
}
return parent::getCustomTransactionNewValue($object, $xaction);
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case HarbormasterBuildableTransaction::TYPE_COMMAND:
return;
}
return parent::applyCustomInternalTransaction($object, $xaction);
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case HarbormasterBuildableTransaction::TYPE_COMMAND:
return;
}
return parent::applyCustomExternalTransaction($object, $xaction);
}
}

View file

@ -1,9 +1,7 @@
<?php
final class HarbormasterBuildableTransaction
extends PhabricatorApplicationTransaction {
const TYPE_COMMAND = 'harbormaster:buildable:command';
extends PhabricatorModularTransaction {
public function getApplicationName() {
return 'harbormaster';
@ -13,72 +11,8 @@ final class HarbormasterBuildableTransaction
return HarbormasterBuildablePHIDType::TYPECONST;
}
public function getTitle() {
$author_phid = $this->getAuthorPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_COMMAND:
switch ($new) {
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
return pht(
'%s restarted this buildable.',
$this->renderHandleLink($author_phid));
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
return pht(
'%s resumed this buildable.',
$this->renderHandleLink($author_phid));
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
return pht(
'%s paused this buildable.',
$this->renderHandleLink($author_phid));
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
return pht(
'%s aborted this buildable.',
$this->renderHandleLink($author_phid));
}
}
return parent::getTitle();
public function getBaseTransactionClass() {
return 'HarbormasterBuildableTransactionType';
}
public function getIcon() {
$author_phid = $this->getAuthorPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_COMMAND:
switch ($new) {
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
return 'fa-backward';
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
return 'fa-play';
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
return 'fa-pause';
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
return 'fa-exclamation-triangle';
}
}
return parent::getIcon();
}
public function getColor() {
$author_phid = $this->getAuthorPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_COMMAND:
switch ($new) {
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
return 'red';
}
}
return parent::getColor();
}
}

View file

@ -0,0 +1,65 @@
<?php
final class HarbormasterBuildableMessageTransaction
extends HarbormasterBuildableTransactionType {
const TRANSACTIONTYPE = 'harbormaster:buildable:command';
public function generateOldValue($object) {
return null;
}
public function getTitle() {
$new = $this->getNewValue();
switch ($new) {
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
return pht(
'%s restarted this buildable.',
$this->renderAuthor());
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
return pht(
'%s resumed this buildable.',
$this->renderAuthor());
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
return pht(
'%s paused this buildable.',
$this->renderAuthor());
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
return pht(
'%s aborted this buildable.',
$this->renderAuthor());
}
return parent::getTitle();
}
public function getIcon() {
$new = $this->getNewValue();
switch ($new) {
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
return 'fa-backward';
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
return 'fa-play';
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
return 'fa-pause';
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
return 'fa-exclamation-triangle';
}
return parent::getIcon();
}
public function getColor() {
$new = $this->getNewValue();
switch ($new) {
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
return 'red';
}
return parent::getColor();
}
}

View file

@ -0,0 +1,4 @@
<?php
abstract class HarbormasterBuildableTransactionType
extends PhabricatorModularTransactionType {}