@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refactor freeform field specification

Summary:
I want to attach the task also to revision, not only to commit by mentioning it in summary.
This is a preparation for it, useful by itself:

* One query instead of N.
* Lower CRAP score, yay!

Refs T945.

Test Plan:
My Test Plan is really //plan// this time.
I want to update Phabricator in the minute when I commit this.

Reviewers: 20after4, epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T945

Differential Revision: https://secure.phabricator.com/D3873

vrana 040fac06 197fad55

+32 -26
+32 -26
src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
··· 3 3 abstract class DifferentialFreeformFieldSpecification 4 4 extends DifferentialFieldSpecification { 5 5 6 - public function didParseCommit( 7 - PhabricatorRepository $repository, 8 - PhabricatorRepositoryCommit $commit, 9 - PhabricatorRepositoryCommitData $data) { 10 - 11 - $user = id(new PhabricatorUser())->loadOneWhere( 12 - 'phid = %s', 13 - $data->getCommitDetail('authorPHID')); 14 - if (!$user) { 15 - return; 16 - } 17 - 6 + private function findMentionedTasks($message) { 18 7 $prefixes = array( 19 8 'resolves' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, 20 9 'fixes' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, ··· 55 44 $suffix_regex = implode('|', $suffix_regex); 56 45 57 46 $matches = null; 58 - $ok = preg_match_all( 47 + preg_match_all( 59 48 "/({$prefix_regex})\s+T(\d+)\s*({$suffix_regex})/i", 60 - $this->renderValueForCommitMessage($is_edit = false), 49 + $message, 61 50 $matches, 62 51 PREG_SET_ORDER); 63 52 64 - if (!$ok) { 65 - return; 66 - } 67 - 53 + $tasks_statuses = array(); 68 54 foreach ($matches as $set) { 69 55 $prefix = strtolower($set[1]); 70 56 $task_id = (int)$set[2]; ··· 75 61 $status = idx($prefixes, $prefix); 76 62 } 77 63 78 - $tasks = id(new ManiphestTaskQuery()) 79 - ->withTaskIDs(array($task_id)) 80 - ->execute(); 81 - $task = idx($tasks, $task_id); 64 + $tasks_statuses[$task_id] = $status; 65 + } 82 66 83 - if (!$task) { 84 - // Task doesn't exist, or the user can't see it. 85 - continue; 86 - } 67 + return $tasks_statuses; 68 + } 69 + 70 + public function didParseCommit( 71 + PhabricatorRepository $repository, 72 + PhabricatorRepositoryCommit $commit, 73 + PhabricatorRepositoryCommitData $data) { 74 + 75 + $user = id(new PhabricatorUser())->loadOneWhere( 76 + 'phid = %s', 77 + $data->getCommitDetail('authorPHID')); 78 + if (!$user) { 79 + return; 80 + } 81 + 82 + $message = $this->renderValueForCommitMessage($is_edit = false); 83 + $tasks_statuses = $this->findMentionedTasks($message); 84 + if (!$tasks_statuses) { 85 + return; 86 + } 87 87 88 + $tasks = id(new ManiphestTaskQuery()) 89 + ->withTaskIDs(array_keys($tasks_statuses)) 90 + ->execute(); 91 + 92 + foreach ($tasks as $task_id => $task) { 88 93 id(new PhabricatorEdgeEditor()) 89 94 ->setActor($user) 90 95 ->addEdge( ··· 93 98 $commit->getPHID()) 94 99 ->save(); 95 100 101 + $status = $tasks_statuses[$task_id]; 96 102 if (!$status) { 97 103 // Text like "Ref T123", don't change the task status. 98 104 continue;