From 3d2e03d0e2f7102a47d24c1fe693c3e83ecab8e6 Mon Sep 17 00:00:00 2001 From: lkassianik Date: Wed, 12 Nov 2014 12:54:29 -0800 Subject: [PATCH] T5015, Allow Herald rules for Maniphest to act on task status changes Summary: Fixes T5015, Allow Herald rules for Maniphest to act on task status changes. Test Plan: Create Herald rule for Maniphest tasks to flag a task with status "wontfix". Change status of Maniphest task to "wontfix". Task should be flagged. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T5015 Differential Revision: https://secure.phabricator.com/D10842 --- src/__phutil_library_map__.php | 2 ++ .../herald/adapter/HeraldAdapter.php | 15 ++++++++++ .../adapter/HeraldManiphestTaskAdapter.php | 3 ++ .../controller/HeraldRuleController.php | 9 ++++++ .../herald/storage/HeraldRule.php | 2 +- .../ManiphestTaskStatusDatasource.php | 30 +++++++++++++++++++ .../js/application/herald/HeraldRuleEditor.js | 1 + 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/applications/maniphest/typeahead/ManiphestTaskStatusDatasource.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 80b236b932..24055a702c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1014,6 +1014,7 @@ phutil_register_library_map(array( 'ManiphestTaskResultListView' => 'applications/maniphest/view/ManiphestTaskResultListView.php', 'ManiphestTaskSearchEngine' => 'applications/maniphest/query/ManiphestTaskSearchEngine.php', 'ManiphestTaskStatus' => 'applications/maniphest/constants/ManiphestTaskStatus.php', + 'ManiphestTaskStatusDatasource' => 'applications/maniphest/typeahead/ManiphestTaskStatusDatasource.php', 'ManiphestTaskStatusTestCase' => 'applications/maniphest/constants/__tests__/ManiphestTaskStatusTestCase.php', 'ManiphestTaskSubscriber' => 'applications/maniphest/storage/ManiphestTaskSubscriber.php', 'ManiphestTransaction' => 'applications/maniphest/storage/ManiphestTransaction.php', @@ -4073,6 +4074,7 @@ phutil_register_library_map(array( 'ManiphestTaskResultListView' => 'ManiphestView', 'ManiphestTaskSearchEngine' => 'PhabricatorApplicationSearchEngine', 'ManiphestTaskStatus' => 'ManiphestConstants', + 'ManiphestTaskStatusDatasource' => 'PhabricatorTypeaheadDatasource', 'ManiphestTaskStatusTestCase' => 'PhabricatorTestCase', 'ManiphestTaskSubscriber' => 'ManiphestDAO', 'ManiphestTransaction' => 'PhabricatorApplicationTransaction', diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index c931923e2d..9c56a6001f 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -40,6 +40,7 @@ abstract class HeraldAdapter { const FIELD_COMMITTER_RAW = 'committer-raw'; const FIELD_IS_NEW_OBJECT = 'new-object'; const FIELD_TASK_PRIORITY = 'taskpriority'; + const FIELD_TASK_STATUS = 'taskstatus'; const FIELD_ARCANIST_PROJECT = 'arcanist-project'; const FIELD_PUSHER_IS_COMMITTER = 'pusher-is-committer'; const FIELD_PATH = 'path'; @@ -96,6 +97,7 @@ abstract class HeraldAdapter { const VALUE_USER_OR_PROJECT = 'userorproject'; const VALUE_BUILD_PLAN = 'buildplan'; const VALUE_TASK_PRIORITY = 'taskpriority'; + const VALUE_TASK_STATUS = 'taskstatus'; const VALUE_ARCANIST_PROJECT = 'arcanistprojects'; const VALUE_LEGAL_DOCUMENTS = 'legaldocuments'; @@ -311,6 +313,7 @@ abstract class HeraldAdapter { self::FIELD_COMMITTER_RAW => pht('Raw committer name'), self::FIELD_IS_NEW_OBJECT => pht('Is newly created?'), self::FIELD_TASK_PRIORITY => pht('Task priority'), + self::FIELD_TASK_STATUS => pht('Task status'), self::FIELD_ARCANIST_PROJECT => pht('Arcanist Project'), self::FIELD_PUSHER_IS_COMMITTER => pht('Pusher same as committer'), self::FIELD_PATH => pht('Path'), @@ -366,6 +369,7 @@ abstract class HeraldAdapter { case self::FIELD_REVIEWER: case self::FIELD_PUSHER: case self::FIELD_TASK_PRIORITY: + case self::FIELD_TASK_STATUS: case self::FIELD_ARCANIST_PROJECT: return array( self::CONDITION_IS_ANY, @@ -843,6 +847,8 @@ abstract class HeraldAdapter { return self::VALUE_REPOSITORY; case self::FIELD_TASK_PRIORITY: return self::VALUE_TASK_PRIORITY; + case self::FIELD_TASK_STATUS: + return self::VALUE_TASK_STATUS; case self::FIELD_ARCANIST_PROJECT: return self::VALUE_ARCANIST_PROJECT; default: @@ -1162,6 +1168,15 @@ abstract class HeraldAdapter { } } break; + case self::FIELD_TASK_STATUS: + $status_map = ManiphestTaskStatus::getTaskStatusMap(); + foreach ($value as $index => $val) { + $name = idx($status_map, $val); + if ($name) { + $value[$index] = $name; + } + } + break; case HeraldPreCommitRefAdapter::FIELD_REF_CHANGE: $change_map = PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions(); diff --git a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php index ac0bbcad93..5174ca34a9 100644 --- a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php +++ b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php @@ -89,6 +89,7 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { self::FIELD_CONTENT_SOURCE, self::FIELD_PROJECTS, self::FIELD_TASK_PRIORITY, + self::FIELD_TASK_STATUS, self::FIELD_IS_NEW_OBJECT, ), parent::getFields()); @@ -145,6 +146,8 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); case self::FIELD_TASK_PRIORITY: return $this->getTask()->getPriority(); + case self::FIELD_TASK_STATUS: + return $this->getTask()->getStatus(); } return parent::getHeraldField($field); diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php index beed090203..11bfd7fc8a 100644 --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -358,6 +358,14 @@ final class HeraldRuleController extends HeraldController { } $value = $value_map; break; + case HeraldAdapter::FIELD_TASK_STATUS: + $value_map = array(); + $status_map = ManiphestTaskStatus::getTaskStatusMap(); + foreach ($value as $status) { + $value_map[$status] = idx($status_map, $status); + } + $value = $value_map; + break; default: if (is_array($value)) { $value_map = array(); @@ -586,6 +594,7 @@ final class HeraldRuleController extends HeraldController { 'repository' => new DiffusionRepositoryDatasource(), 'legaldocuments' => new LegalpadDocumentDatasource(), 'taskpriority' => new ManiphestTaskPriorityDatasource(), + 'taskstatus' => new ManiphestTaskStatusDatasource(), 'buildplan' => new HarbormasterBuildPlanDatasource(), 'arcanistprojects' => new DiffusionArcanistProjectDatasource(), 'package' => new PhabricatorOwnersPackageDatasource(), diff --git a/src/applications/herald/storage/HeraldRule.php b/src/applications/herald/storage/HeraldRule.php index bc85bdd203..997dd25217 100644 --- a/src/applications/herald/storage/HeraldRule.php +++ b/src/applications/herald/storage/HeraldRule.php @@ -18,7 +18,7 @@ final class HeraldRule extends HeraldDAO protected $isDisabled = 0; protected $triggerObjectPHID; - protected $configVersion = 37; + protected $configVersion = 38; // PHIDs for which this rule has been applied private $ruleApplied = self::ATTACHABLE; diff --git a/src/applications/maniphest/typeahead/ManiphestTaskStatusDatasource.php b/src/applications/maniphest/typeahead/ManiphestTaskStatusDatasource.php new file mode 100644 index 0000000000..e7eba2923c --- /dev/null +++ b/src/applications/maniphest/typeahead/ManiphestTaskStatusDatasource.php @@ -0,0 +1,30 @@ +getViewer(); + $raw_query = $this->getRawQuery(); + + $results = array(); + + $status_map = ManiphestTaskStatus::getTaskStatusMap(); + foreach ($status_map as $value => $name) { + // NOTE: $value is not a PHID but is unique. This'll work. + $results[] = id(new PhabricatorTypeaheadResult()) + ->setPHID($value) + ->setName($name); + } + + return $results; + } +} diff --git a/webroot/rsrc/js/application/herald/HeraldRuleEditor.js b/webroot/rsrc/js/application/herald/HeraldRuleEditor.js index f9da34e0f6..30f34d27b3 100644 --- a/webroot/rsrc/js/application/herald/HeraldRuleEditor.js +++ b/webroot/rsrc/js/application/herald/HeraldRuleEditor.js @@ -219,6 +219,7 @@ JX.install('HeraldRuleEditor', { case 'userorproject': case 'buildplan': case 'taskpriority': + case 'taskstatus': case 'arcanistprojects': case 'legaldocuments': var tokenizer = this._newTokenizer(type);