1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Attach mentioned Maniphest task also to revision

Summary: Also disable this feature without 'maniphest.enabled'.

Test Plan:
Wrote "fixes T..." in `arc diff`, verified that the task is attached.
Add another "fixes T..." in edit revision on web, verified that it was added.
Deleted "fixes T..." in edit revision, verified that the attached task wasn't deleted.

Reviewers: 20after4, epriestley

Reviewed By: 20after4

CC: aran, Korvin

Maniphest Tasks: T945

Differential Revision: https://secure.phabricator.com/D3986
This commit is contained in:
vrana 2012-11-19 15:51:46 -08:00
parent 58716521bd
commit 97a97f5376

View file

@ -4,6 +4,10 @@ abstract class DifferentialFreeformFieldSpecification
extends DifferentialFieldSpecification {
private function findMentionedTasks($message) {
if (!PhabricatorEnv::getEnvConfig('maniphest.enabled')) {
return array();
}
$prefixes = array(
'resolves' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED,
'fixes' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED,
@ -67,6 +71,34 @@ abstract class DifferentialFreeformFieldSpecification
return $tasks_statuses;
}
public function didWriteRevision(DifferentialRevisionEditor $editor) {
$message = $this->renderValueForCommitMessage(false);
$tasks = $this->findMentionedTasks($message);
if (!$tasks) {
return;
}
$revision_phid = $editor->getRevision()->getPHID();
$edge_type = PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK;
$add_phids = id(new ManiphestTask())
->loadAllWhere('id IN (%Ld)', array_keys($tasks));
$add_phids = mpull($add_phids, 'getPHID');
$old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$revision_phid,
$edge_type);
$add_phids = array_diff($add_phids, $old_phids);
$edge_editor = id(new PhabricatorEdgeEditor())->setActor($this->getUser());
foreach ($add_phids as $phid) {
$edge_editor->addEdge($revision_phid, $edge_type, $phid);
}
// NOTE: Deletes only through Maniphest Tasks field.
$edge_editor->save();
}
public function didParseCommit(
PhabricatorRepository $repository,
PhabricatorRepositoryCommit $commit,