mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 14:30:56 +01:00
Use DifferentialRevisionEditor in lipsum
Summary: Ref T2222. Test Plan: Generated revisions with `bin/lipsum`. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2222 Differential Revision: https://secure.phabricator.com/D8453
This commit is contained in:
parent
a5fbe921b7
commit
fbaa12440e
7 changed files with 71 additions and 45 deletions
|
@ -896,6 +896,22 @@ final class DifferentialTransactionEditor
|
||||||
return $phids;
|
return $phids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getMailAction(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
array $xactions) {
|
||||||
|
$action = parent::getMailAction($object, $xactions);
|
||||||
|
|
||||||
|
$strongest = $this->getStrongestAction($object, $xactions);
|
||||||
|
switch ($strongest->getTransactionType()) {
|
||||||
|
case DifferentialTransaction::TYPE_UPDATE:
|
||||||
|
$count = new PhutilNumber($object->getLineCount());
|
||||||
|
$action = pht('%s, %s line(s)', $action, $count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $action;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getMailSubjectPrefix() {
|
protected function getMailSubjectPrefix() {
|
||||||
return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix');
|
return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix');
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,24 +6,34 @@ final class PhabricatorDifferentialRevisionTestDataGenerator
|
||||||
public function generate() {
|
public function generate() {
|
||||||
$author = $this->loadPhabrictorUser();
|
$author = $this->loadPhabrictorUser();
|
||||||
$authorPHID = $author->getPHID();
|
$authorPHID = $author->getPHID();
|
||||||
|
|
||||||
$revision = DifferentialRevision::initializeNewRevision($author);
|
$revision = DifferentialRevision::initializeNewRevision($author);
|
||||||
|
$revision->attachReviewerStatus(array());
|
||||||
|
$revision->attachActiveDiff(null);
|
||||||
|
|
||||||
|
// This could be a bit richer and more formal than it is.
|
||||||
$revision->setTitle($this->generateTitle());
|
$revision->setTitle($this->generateTitle());
|
||||||
$revision->setSummary($this->generateDescription());
|
$revision->setSummary($this->generateDescription());
|
||||||
$revision->setTestPlan($this->generateDescription());
|
$revision->setTestPlan($this->generateDescription());
|
||||||
$revision->loadRelationships();
|
|
||||||
$aux_fields = $this->loadAuxiliaryFields($author, $revision);
|
|
||||||
$diff = $this->generateDiff($author);
|
$diff = $this->generateDiff($author);
|
||||||
// Add Diff
|
|
||||||
$editor = new DifferentialRevisionEditor($revision);
|
|
||||||
$editor->setActor($author);
|
|
||||||
$editor->addDiff($diff, $this->generateDescription());
|
|
||||||
$editor->setAuxiliaryFields($aux_fields);
|
|
||||||
$editor->save();
|
|
||||||
|
|
||||||
// TODO: After T2222, it would be nice to revisit this and expand the
|
$xactions = array();
|
||||||
// functionality.
|
|
||||||
|
|
||||||
return $revision->save();
|
$xactions[] = id(new DifferentialTransaction())
|
||||||
|
->setTransactionType(DifferentialTransaction::TYPE_UPDATE)
|
||||||
|
->setNewValue($diff->getPHID());
|
||||||
|
|
||||||
|
$content_source = PhabricatorContentSource::newForSource(
|
||||||
|
PhabricatorContentSource::SOURCE_LIPSUM,
|
||||||
|
array());
|
||||||
|
|
||||||
|
id(new DifferentialTransactionEditor())
|
||||||
|
->setActor($author)
|
||||||
|
->setContentSource($content_source)
|
||||||
|
->applyTransactions($revision, $xactions);
|
||||||
|
|
||||||
|
return $revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCCPHIDs() {
|
public function getCCPHIDs() {
|
||||||
|
@ -92,20 +102,4 @@ final class PhabricatorDifferentialRevisionTestDataGenerator
|
||||||
return implode($newcode2, "\n");
|
return implode($newcode2, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadAuxiliaryFields($user, DifferentialRevision $revision) {
|
|
||||||
$aux_fields = DifferentialFieldSelector::newSelector()
|
|
||||||
->getFieldSpecifications();
|
|
||||||
foreach ($aux_fields as $key => $aux_field) {
|
|
||||||
$aux_field->setRevision($revision);
|
|
||||||
if (!$aux_field->shouldAppearOnEdit()) {
|
|
||||||
unset($aux_fields[$key]);
|
|
||||||
} else {
|
|
||||||
$aux_field->setUser($user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DifferentialAuxiliaryField::loadFromStorage(
|
|
||||||
$revision,
|
|
||||||
$aux_fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,12 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
|
||||||
case self::TYPE_INLINE:
|
case self::TYPE_INLINE:
|
||||||
return pht('Commented On');
|
return pht('Commented On');
|
||||||
case self::TYPE_UPDATE:
|
case self::TYPE_UPDATE:
|
||||||
|
$old = $this->getOldValue();
|
||||||
|
if ($old === null) {
|
||||||
|
return pht('Request');
|
||||||
|
} else {
|
||||||
return pht('Updated');
|
return pht('Updated');
|
||||||
|
}
|
||||||
case self::TYPE_ACTION:
|
case self::TYPE_ACTION:
|
||||||
$map = array(
|
$map = array(
|
||||||
DifferentialAction::ACTION_ACCEPT => pht('Accepted'),
|
DifferentialAction::ACTION_ACCEPT => pht('Accepted'),
|
||||||
|
|
|
@ -6,7 +6,7 @@ final class PhabricatorLipsumGenerateWorkflow
|
||||||
protected function didConstruct() {
|
protected function didConstruct() {
|
||||||
$this
|
$this
|
||||||
->setName('generate')
|
->setName('generate')
|
||||||
->setExamples('**generate** __key__')
|
->setExamples('**generate**')
|
||||||
->setSynopsis('Generate some lipsum.')
|
->setSynopsis('Generate some lipsum.')
|
||||||
->setArguments(
|
->setArguments(
|
||||||
array(
|
array(
|
||||||
|
@ -62,7 +62,7 @@ final class PhabricatorLipsumGenerateWorkflow
|
||||||
while (true) {
|
while (true) {
|
||||||
$type = $supported_types[array_rand($supported_types)];
|
$type = $supported_types[array_rand($supported_types)];
|
||||||
$admin = $this->getViewer();
|
$admin = $this->getViewer();
|
||||||
try {
|
|
||||||
$taskgen = newv($type, array());
|
$taskgen = newv($type, array());
|
||||||
$object = $taskgen->generate();
|
$object = $taskgen->generate();
|
||||||
$handle = id(new PhabricatorHandleQuery())
|
$handle = id(new PhabricatorHandleQuery())
|
||||||
|
@ -71,11 +71,7 @@ final class PhabricatorLipsumGenerateWorkflow
|
||||||
->executeOne();
|
->executeOne();
|
||||||
echo "Generated ".$handle->getTypeName().": ".
|
echo "Generated ".$handle->getTypeName().": ".
|
||||||
$handle->getFullName()."\n";
|
$handle->getFullName()."\n";
|
||||||
} catch (PhutilMissingSymbolException $ex) {
|
|
||||||
throw new PhutilArgumentUsageException(
|
|
||||||
"Cannot generate content of type ".$type.
|
|
||||||
" because the class does not exist.");
|
|
||||||
}
|
|
||||||
usleep(200000);
|
usleep(200000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ final class PhabricatorContentSource {
|
||||||
const SOURCE_HERALD = 'herald';
|
const SOURCE_HERALD = 'herald';
|
||||||
const SOURCE_LEGACY = 'legacy';
|
const SOURCE_LEGACY = 'legacy';
|
||||||
const SOURCE_DAEMON = 'daemon';
|
const SOURCE_DAEMON = 'daemon';
|
||||||
|
const SOURCE_LIPSUM = 'lipsum';
|
||||||
|
|
||||||
private $source;
|
private $source;
|
||||||
private $params = array();
|
private $params = array();
|
||||||
|
@ -74,6 +75,7 @@ final class PhabricatorContentSource {
|
||||||
self::SOURCE_LEGACY => pht('Legacy'),
|
self::SOURCE_LEGACY => pht('Legacy'),
|
||||||
self::SOURCE_HERALD => pht('Herald'),
|
self::SOURCE_HERALD => pht('Herald'),
|
||||||
self::SOURCE_DAEMON => pht('Daemons'),
|
self::SOURCE_DAEMON => pht('Daemons'),
|
||||||
|
self::SOURCE_LIPSUM => pht('Lipsum'),
|
||||||
self::SOURCE_UNKNOWN => pht('Old World'),
|
self::SOURCE_UNKNOWN => pht('Old World'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1649,8 +1649,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
$body = $this->buildMailBody($object, $xactions);
|
$body = $this->buildMailBody($object, $xactions);
|
||||||
|
|
||||||
$mail_tags = $this->getMailTags($object, $xactions);
|
$mail_tags = $this->getMailTags($object, $xactions);
|
||||||
|
$action = $this->getMailAction($object, $xactions);
|
||||||
$action = $this->getStrongestAction($object, $xactions)->getActionName();
|
|
||||||
|
|
||||||
$template
|
$template
|
||||||
->setFrom($this->requireActor()->getPHID())
|
->setFrom($this->requireActor()->getPHID())
|
||||||
|
@ -1745,6 +1744,15 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
return array_mergev($tags);
|
return array_mergev($tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @task mail
|
||||||
|
*/
|
||||||
|
protected function getMailAction(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
array $xactions) {
|
||||||
|
return $this->getStrongestAction($object, $xactions)->getActionName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @task mail
|
* @task mail
|
||||||
|
|
|
@ -851,6 +851,11 @@ abstract class PhabricatorBaseEnglishTranslation
|
||||||
'%d older changes are hidden.',
|
'%d older changes are hidden.',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'%s, %d line(s)' => array(
|
||||||
|
'%s, %d line',
|
||||||
|
'%s, %d lines',
|
||||||
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue