1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 18:22:41 +01:00

Parse "Depends on" in freeform Differential fields

Summary:
I considered also parsing "Depends On:" field in the commit message but it's more involved and I also prefer having this information in the summary where it's more visible.
I also didn't want the field displayed by default so user would have to write "Depends On:" anyway.

Test Plan: Used "Depends on D1" in summary, saw it in dependencies.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5300
This commit is contained in:
Jakub Vrana 2013-03-10 11:00:02 -07:00
parent 71d0465331
commit 47f6aecb72

View file

@ -79,31 +79,69 @@ abstract class DifferentialFreeformFieldSpecification
return $tasks_statuses; return $tasks_statuses;
} }
public function didWriteRevision(DifferentialRevisionEditor $editor) { private function findDependentRevisions($message) {
$message = $this->renderValueForCommitMessage(false); $dependents = array();
$tasks = $this->findMentionedTasks($message);
if (!$tasks) { $matches = null;
return; preg_match_all(
'/\b(?i:depends\s+on)\s+D(\d+(,\s+D\d++)*)\b/',
$message,
$matches);
foreach ($matches[1] as $revisions) {
foreach (preg_split('/,\s+D/', $revisions) as $id) {
$dependents[$id] = $id;
}
} }
$revision_phid = $editor->getRevision()->getPHID(); return $dependents;
$edge_type = PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK; }
$add_phids = id(new ManiphestTask()) public function didWriteRevision(DifferentialRevisionEditor $editor) {
->loadAllWhere('id IN (%Ld)', array_keys($tasks)); $message = $this->renderValueForCommitMessage(false);
$add_phids = mpull($add_phids, 'getPHID');
$tasks = $this->findMentionedTasks($message);
if ($tasks) {
$tasks = id(new ManiphestTask())
->loadAllWhere('id IN (%Ld)', array_keys($tasks));
$this->saveFieldEdges(
$editor->getRevision(),
PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK,
mpull($tasks, 'getPHID'));
}
$dependents = $this->findDependentRevisions($message);
if ($dependents) {
$dependents = id(new DifferentialRevision())
->loadAllWhere('id IN (%Ld)', $dependents);
$this->saveFieldEdges(
$editor->getRevision(),
PhabricatorEdgeConfig::TYPE_DREV_DEPENDS_ON_DREV,
mpull($dependents, 'getPHID'));
}
}
private function saveFieldEdges(
DifferentialRevision $revision,
$edge_type,
array $add_phids) {
$revision_phid = $revision->getPHID();
$old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( $old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$revision_phid, $revision_phid,
$edge_type); $edge_type);
$add_phids = array_diff($add_phids, $old_phids); $add_phids = array_diff($add_phids, $old_phids);
if (!$add_phids) {
return;
}
$edge_editor = id(new PhabricatorEdgeEditor())->setActor($this->getUser()); $edge_editor = id(new PhabricatorEdgeEditor())->setActor($this->getUser());
foreach ($add_phids as $phid) { foreach ($add_phids as $phid) {
$edge_editor->addEdge($revision_phid, $edge_type, $phid); $edge_editor->addEdge($revision_phid, $edge_type, $phid);
} }
// NOTE: Deletes only through Maniphest Tasks field. // NOTE: Deletes only through the fields.
$edge_editor->save(); $edge_editor->save();
} }