1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-19 03:01:11 +01:00

Support "Test Plan" with modular transactions and EditEngine

Summary: Ref T11114. The only real trick here is that we respect configuration in `differential.fields`.

Test Plan: Turned plan on and off, tried to remove the plan, edited the plan.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11114

Differential Revision: https://secure.phabricator.com/D17048
This commit is contained in:
epriestley 2016-12-13 15:24:55 -08:00
parent 5349d6bd5c
commit 6c9af81f7a
3 changed files with 139 additions and 30 deletions

View file

@ -554,6 +554,7 @@ phutil_register_library_map(array(
'DifferentialRevisionStatus' => 'applications/differential/constants/DifferentialRevisionStatus.php', 'DifferentialRevisionStatus' => 'applications/differential/constants/DifferentialRevisionStatus.php',
'DifferentialRevisionSummaryHeraldField' => 'applications/differential/herald/DifferentialRevisionSummaryHeraldField.php', 'DifferentialRevisionSummaryHeraldField' => 'applications/differential/herald/DifferentialRevisionSummaryHeraldField.php',
'DifferentialRevisionSummaryTransaction' => 'applications/differential/xaction/DifferentialRevisionSummaryTransaction.php', 'DifferentialRevisionSummaryTransaction' => 'applications/differential/xaction/DifferentialRevisionSummaryTransaction.php',
'DifferentialRevisionTestPlanTransaction' => 'applications/differential/xaction/DifferentialRevisionTestPlanTransaction.php',
'DifferentialRevisionTitleHeraldField' => 'applications/differential/herald/DifferentialRevisionTitleHeraldField.php', 'DifferentialRevisionTitleHeraldField' => 'applications/differential/herald/DifferentialRevisionTitleHeraldField.php',
'DifferentialRevisionTitleTransaction' => 'applications/differential/xaction/DifferentialRevisionTitleTransaction.php', 'DifferentialRevisionTitleTransaction' => 'applications/differential/xaction/DifferentialRevisionTitleTransaction.php',
'DifferentialRevisionTransactionType' => 'applications/differential/xaction/DifferentialRevisionTransactionType.php', 'DifferentialRevisionTransactionType' => 'applications/differential/xaction/DifferentialRevisionTransactionType.php',
@ -5206,6 +5207,7 @@ phutil_register_library_map(array(
'DifferentialRevisionStatus' => 'Phobject', 'DifferentialRevisionStatus' => 'Phobject',
'DifferentialRevisionSummaryHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionSummaryHeraldField' => 'DifferentialRevisionHeraldField',
'DifferentialRevisionSummaryTransaction' => 'DifferentialRevisionTransactionType', 'DifferentialRevisionSummaryTransaction' => 'DifferentialRevisionTransactionType',
'DifferentialRevisionTestPlanTransaction' => 'DifferentialRevisionTransactionType',
'DifferentialRevisionTitleHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionTitleHeraldField' => 'DifferentialRevisionHeraldField',
'DifferentialRevisionTitleTransaction' => 'DifferentialRevisionTransactionType', 'DifferentialRevisionTitleTransaction' => 'DifferentialRevisionTransactionType',
'DifferentialRevisionTransactionType' => 'PhabricatorModularTransactionType', 'DifferentialRevisionTransactionType' => 'PhabricatorModularTransactionType',

View file

@ -60,8 +60,15 @@ final class DifferentialRevisionEditEngine
} }
protected function buildCustomEditFields($object) { protected function buildCustomEditFields($object) {
return array(
id(new PhabricatorTextEditField()) $plan_required = PhabricatorEnv::getEnvConfig(
'differential.require-test-plan-field');
$plan_enabled = $this->isCustomFieldEnabled(
$object,
'differential:test-plan');
$fields = array();
$fields[] = id(new PhabricatorTextEditField())
->setKey('title') ->setKey('title')
->setLabel(pht('Title')) ->setLabel(pht('Title'))
->setIsRequired(true) ->setIsRequired(true)
@ -70,8 +77,9 @@ final class DifferentialRevisionEditEngine
->setDescription(pht('The title of the revision.')) ->setDescription(pht('The title of the revision.'))
->setConduitDescription(pht('Retitle the revision.')) ->setConduitDescription(pht('Retitle the revision.'))
->setConduitTypeDescription(pht('New revision title.')) ->setConduitTypeDescription(pht('New revision title.'))
->setValue($object->getTitle()), ->setValue($object->getTitle());
id(new PhabricatorRemarkupEditField())
$fields[] = id(new PhabricatorRemarkupEditField())
->setKey('summary') ->setKey('summary')
->setLabel(pht('Summary')) ->setLabel(pht('Summary'))
->setTransactionType( ->setTransactionType(
@ -79,8 +87,23 @@ final class DifferentialRevisionEditEngine
->setDescription(pht('The summary of the revision.')) ->setDescription(pht('The summary of the revision.'))
->setConduitDescription(pht('Change the revision summary.')) ->setConduitDescription(pht('Change the revision summary.'))
->setConduitTypeDescription(pht('New revision summary.')) ->setConduitTypeDescription(pht('New revision summary.'))
->setValue($object->getSummary()), ->setValue($object->getSummary());
id(new PhabricatorDatasourceEditField())
if ($plan_enabled) {
$fields[] = id(new PhabricatorRemarkupEditField())
->setKey('testPlan')
->setLabel(pht('Test Plan'))
->setIsRequired($plan_required)
->setTransactionType(
DifferentialRevisionTestPlanTransaction::TRANSACTIONTYPE)
->setDescription(
pht('Actions performed to verify the behavior of the change.'))
->setConduitDescription(pht('Update the revision test plan.'))
->setConduitTypeDescription(pht('New test plan.'))
->setValue($object->getTestPlan());
}
$fields[] = id(new PhabricatorDatasourceEditField())
->setKey('repositoryPHID') ->setKey('repositoryPHID')
->setLabel(pht('Repository')) ->setLabel(pht('Repository'))
->setDatasource(new DiffusionRepositoryDatasource()) ->setDatasource(new DiffusionRepositoryDatasource())
@ -89,8 +112,18 @@ final class DifferentialRevisionEditEngine
->setDescription(pht('The repository the revision belongs to.')) ->setDescription(pht('The repository the revision belongs to.'))
->setConduitDescription(pht('Change the repository for this revision.')) ->setConduitDescription(pht('Change the repository for this revision.'))
->setConduitTypeDescription(pht('New repository.')) ->setConduitTypeDescription(pht('New repository.'))
->setSingleValue($object->getRepositoryPHID()), ->setSingleValue($object->getRepositoryPHID());
);
return $fields;
}
private function isCustomFieldEnabled(DifferentialRevision $revision, $key) {
$field_list = PhabricatorCustomField::getObjectFields(
$revision,
PhabricatorCustomField::ROLE_EDIT);
$fields = $field_list->getFields();
return isset($fields[$key]);
} }
} }

View file

@ -0,0 +1,74 @@
<?php
final class DifferentialRevisionTestPlanTransaction
extends DifferentialRevisionTransactionType {
const TRANSACTIONTYPE = 'differential.revision.testplan';
public function generateOldValue($object) {
return $object->getTestPlan();
}
public function applyInternalEffects($object, $value) {
$object->setTestPlan($value);
}
public function getTitle() {
return pht(
'%s edited the test plan for this revision.',
$this->renderAuthor());
}
public function getTitleForFeed() {
return pht(
'%s updated the test plan for %s.',
$this->renderAuthor(),
$this->renderObject());
}
public function hasChangeDetailView() {
return true;
}
public function getMailDiffSectionHeader() {
return pht('CHANGES TO TEST PLAN');
}
public function newChangeDetailView() {
$viewer = $this->getViewer();
return id(new PhabricatorApplicationTransactionTextDiffDetailView())
->setViewer($viewer)
->setOldText($this->getOldValue())
->setNewText($this->getNewValue());
}
public function newRemarkupChanges() {
$changes = array();
$changes[] = $this->newRemarkupChange()
->setOldValue($this->getOldValue())
->setNewValue($this->getNewValue());
return $changes;
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$is_required = PhabricatorEnv::getEnvConfig(
'differential.require-test-plan-field');
if ($is_required) {
if ($this->isEmptyTextTransaction($object->getTestPlan(), $xactions)) {
$errors[] = $this->newRequiredError(
pht(
'You must provide a test plan. Describe the actions you '.
'performed to verify the behavior of this change.'));
}
}
return $errors;
}
}