mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +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;
|
||||
}
|
||||
|
||||
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() {
|
||||
return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix');
|
||||
}
|
||||
|
|
|
@ -6,24 +6,34 @@ final class PhabricatorDifferentialRevisionTestDataGenerator
|
|||
public function generate() {
|
||||
$author = $this->loadPhabrictorUser();
|
||||
$authorPHID = $author->getPHID();
|
||||
|
||||
$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->setSummary($this->generateDescription());
|
||||
$revision->setTestPlan($this->generateDescription());
|
||||
$revision->loadRelationships();
|
||||
$aux_fields = $this->loadAuxiliaryFields($author, $revision);
|
||||
|
||||
$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
|
||||
// functionality.
|
||||
$xactions = array();
|
||||
|
||||
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() {
|
||||
|
@ -92,20 +102,4 @@ final class PhabricatorDifferentialRevisionTestDataGenerator
|
|||
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:
|
||||
return pht('Commented On');
|
||||
case self::TYPE_UPDATE:
|
||||
return pht('Updated');
|
||||
$old = $this->getOldValue();
|
||||
if ($old === null) {
|
||||
return pht('Request');
|
||||
} else {
|
||||
return pht('Updated');
|
||||
}
|
||||
case self::TYPE_ACTION:
|
||||
$map = array(
|
||||
DifferentialAction::ACTION_ACCEPT => pht('Accepted'),
|
||||
|
|
|
@ -6,7 +6,7 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
protected function didConstruct() {
|
||||
$this
|
||||
->setName('generate')
|
||||
->setExamples('**generate** __key__')
|
||||
->setExamples('**generate**')
|
||||
->setSynopsis('Generate some lipsum.')
|
||||
->setArguments(
|
||||
array(
|
||||
|
@ -62,20 +62,16 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
while (true) {
|
||||
$type = $supported_types[array_rand($supported_types)];
|
||||
$admin = $this->getViewer();
|
||||
try {
|
||||
$taskgen = newv($type, array());
|
||||
$object = $taskgen->generate();
|
||||
$handle = id(new PhabricatorHandleQuery())
|
||||
->setViewer($admin)
|
||||
->withPHIDs(array($object->getPHID()))
|
||||
->executeOne();
|
||||
echo "Generated ".$handle->getTypeName().": ".
|
||||
$handle->getFullName()."\n";
|
||||
} catch (PhutilMissingSymbolException $ex) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
"Cannot generate content of type ".$type.
|
||||
" because the class does not exist.");
|
||||
}
|
||||
|
||||
$taskgen = newv($type, array());
|
||||
$object = $taskgen->generate();
|
||||
$handle = id(new PhabricatorHandleQuery())
|
||||
->setViewer($admin)
|
||||
->withPHIDs(array($object->getPHID()))
|
||||
->executeOne();
|
||||
echo "Generated ".$handle->getTypeName().": ".
|
||||
$handle->getFullName()."\n";
|
||||
|
||||
usleep(200000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ final class PhabricatorContentSource {
|
|||
const SOURCE_HERALD = 'herald';
|
||||
const SOURCE_LEGACY = 'legacy';
|
||||
const SOURCE_DAEMON = 'daemon';
|
||||
const SOURCE_LIPSUM = 'lipsum';
|
||||
|
||||
private $source;
|
||||
private $params = array();
|
||||
|
@ -74,6 +75,7 @@ final class PhabricatorContentSource {
|
|||
self::SOURCE_LEGACY => pht('Legacy'),
|
||||
self::SOURCE_HERALD => pht('Herald'),
|
||||
self::SOURCE_DAEMON => pht('Daemons'),
|
||||
self::SOURCE_LIPSUM => pht('Lipsum'),
|
||||
self::SOURCE_UNKNOWN => pht('Old World'),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1649,8 +1649,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
$body = $this->buildMailBody($object, $xactions);
|
||||
|
||||
$mail_tags = $this->getMailTags($object, $xactions);
|
||||
|
||||
$action = $this->getStrongestAction($object, $xactions)->getActionName();
|
||||
$action = $this->getMailAction($object, $xactions);
|
||||
|
||||
$template
|
||||
->setFrom($this->requireActor()->getPHID())
|
||||
|
@ -1745,6 +1744,15 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
return array_mergev($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @task mail
|
||||
*/
|
||||
protected function getMailAction(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
return $this->getStrongestAction($object, $xactions)->getActionName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task mail
|
||||
|
|
|
@ -851,6 +851,11 @@ abstract class PhabricatorBaseEnglishTranslation
|
|||
'%d older changes are hidden.',
|
||||
),
|
||||
|
||||
'%s, %d line(s)' => array(
|
||||
'%s, %d line',
|
||||
'%s, %d lines',
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue