mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-17 01:08:41 +01:00
When applying repository operations via Drydock, provide more context on OperationType
Summary: Ref T13195. See PHI845. For custom OperationTypes, provide access to the Interface and Operation via getters. This is just for convenience, since passing these around everywhere can be a bit of a pain if you have a deep-ish stack of things or love using callbacks or whatever. Test Plan: Landed a revision via upstream Drydock operations. Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13195 Differential Revision: https://secure.phabricator.com/D19636
This commit is contained in:
parent
041392988e
commit
e6ee5ee9a1
4 changed files with 32 additions and 9 deletions
|
@ -3,6 +3,8 @@
|
||||||
abstract class DrydockRepositoryOperationType extends Phobject {
|
abstract class DrydockRepositoryOperationType extends Phobject {
|
||||||
|
|
||||||
private $viewer;
|
private $viewer;
|
||||||
|
private $operation;
|
||||||
|
private $interface;
|
||||||
|
|
||||||
abstract public function applyOperation(
|
abstract public function applyOperation(
|
||||||
DrydockRepositoryOperation $operation,
|
DrydockRepositoryOperation $operation,
|
||||||
|
@ -29,6 +31,27 @@ abstract class DrydockRepositoryOperationType extends Phobject {
|
||||||
return $this->viewer;
|
return $this->viewer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public function setOperation(DrydockRepositoryOperation $operation) {
|
||||||
|
$this->operation = $operation;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function getOperation() {
|
||||||
|
return $this->operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function setInterface(DrydockInterface $interface) {
|
||||||
|
$this->interface = $interface;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function getInterface() {
|
||||||
|
if (!$this->interface) {
|
||||||
|
throw new PhutilInvalidStateException('setInterface');
|
||||||
|
}
|
||||||
|
return $this->interface;
|
||||||
|
}
|
||||||
|
|
||||||
final public function getOperationConstant() {
|
final public function getOperationConstant() {
|
||||||
return $this->getPhobjectClassConstant('OPCONST', 32);
|
return $this->getPhobjectClassConstant('OPCONST', 32);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,8 @@ final class DrydockRepositoryOperationQuery extends DrydockQuery {
|
||||||
protected function willFilterPage(array $operations) {
|
protected function willFilterPage(array $operations) {
|
||||||
$implementations = DrydockRepositoryOperationType::getAllOperationTypes();
|
$implementations = DrydockRepositoryOperationType::getAllOperationTypes();
|
||||||
|
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
foreach ($operations as $key => $operation) {
|
foreach ($operations as $key => $operation) {
|
||||||
$impl = idx($implementations, $operation->getOperationType());
|
$impl = idx($implementations, $operation->getOperationType());
|
||||||
if (!$impl) {
|
if (!$impl) {
|
||||||
|
@ -69,7 +71,10 @@ final class DrydockRepositoryOperationQuery extends DrydockQuery {
|
||||||
unset($operations[$key]);
|
unset($operations[$key]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$impl = clone $impl;
|
$impl = id(clone $impl)
|
||||||
|
->setViewer($viewer)
|
||||||
|
->setOperation($operation);
|
||||||
|
|
||||||
$operation->attachImplementation($impl);
|
$operation->attachImplementation($impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,9 +137,9 @@ final class DrydockRepositoryOperation extends DrydockDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyOperation(DrydockInterface $interface) {
|
public function applyOperation(DrydockInterface $interface) {
|
||||||
return $this->getImplementation()->applyOperation(
|
$impl = $this->getImplementation();
|
||||||
$this,
|
$impl->setInterface($interface);
|
||||||
$interface);
|
return $impl->applyOperation($this, $interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOperationDescription(PhabricatorUser $viewer) {
|
public function getOperationDescription(PhabricatorUser $viewer) {
|
||||||
|
|
|
@ -25,8 +25,6 @@ final class DrydockRepositoryOperationUpdateWorker
|
||||||
|
|
||||||
|
|
||||||
private function handleUpdate(DrydockRepositoryOperation $operation) {
|
private function handleUpdate(DrydockRepositoryOperation $operation) {
|
||||||
$viewer = $this->getViewer();
|
|
||||||
|
|
||||||
$operation_state = $operation->getOperationState();
|
$operation_state = $operation->getOperationState();
|
||||||
|
|
||||||
switch ($operation_state) {
|
switch ($operation_state) {
|
||||||
|
@ -53,9 +51,6 @@ final class DrydockRepositoryOperationUpdateWorker
|
||||||
// waiting for a lease we're holding.
|
// waiting for a lease we're holding.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$operation->getImplementation()
|
|
||||||
->setViewer($viewer);
|
|
||||||
|
|
||||||
$lease = $this->loadWorkingCopyLease($operation);
|
$lease = $this->loadWorkingCopyLease($operation);
|
||||||
|
|
||||||
$interface = $lease->getInterface(
|
$interface = $lease->getInterface(
|
||||||
|
|
Loading…
Add table
Reference in a new issue