From 9abc16df4df54532e25e2fcbb1eccb149cadb7f3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 13 May 2016 07:39:18 -0700 Subject: [PATCH] Give Owners packages the "O" monogram Summary: Ref T10939. This isn't ideal because it's easy to confuse with zero ("O" vs "0") but I think this will mostly be read-only so it's probably one of the least-bad uses we could make of "O". We haven't really gotten into trouble with "I" (vs "1") for initiatives. Still, open to better ideas. The goal here is to allow commit messages to include packages in some reasonable way, like `Reviewers: O123 Package Name, epriestley, alincoln`. The parser will ignore the "Package Name" part, that's just for humans. And I don't expect humans to type this, but when the use `arc diff --edit` or similar to update an //existing// revision, the reviewer needs to be represented somehow. It also needs to appear in the commit messages that `arc land` finalizes somehow. I didn't hook up `/O123` as a URI, but this should do everything else I think. Test Plan: - Viewed package list. - Viewed package detail. - Did global search for `O12`. - Used `O12` and `{O12}` remarkup rules. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10939 Differential Revision: https://secure.phabricator.com/D15910 --- src/__phutil_library_map__.php | 2 + .../PhabricatorOwnersApplication.php | 6 +++ .../PhabricatorOwnersDetailController.php | 2 +- .../phid/PhabricatorOwnersPackagePHIDType.php | 37 ++++++++++++++++++- .../PhabricatorOwnersPackageSearchEngine.php | 2 +- .../PhabricatorOwnersPackageRemarkupRule.php | 19 ++++++++++ .../storage/PhabricatorOwnersPackage.php | 4 ++ 7 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/applications/owners/remarkup/PhabricatorOwnersPackageRemarkupRule.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e11c20a33c..4b48d8c879 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2833,6 +2833,7 @@ phutil_register_library_map(array( 'PhabricatorOwnersPackageOwnerDatasource' => 'applications/owners/typeahead/PhabricatorOwnersPackageOwnerDatasource.php', 'PhabricatorOwnersPackagePHIDType' => 'applications/owners/phid/PhabricatorOwnersPackagePHIDType.php', 'PhabricatorOwnersPackageQuery' => 'applications/owners/query/PhabricatorOwnersPackageQuery.php', + 'PhabricatorOwnersPackageRemarkupRule' => 'applications/owners/remarkup/PhabricatorOwnersPackageRemarkupRule.php', 'PhabricatorOwnersPackageSearchEngine' => 'applications/owners/query/PhabricatorOwnersPackageSearchEngine.php', 'PhabricatorOwnersPackageTestCase' => 'applications/owners/storage/__tests__/PhabricatorOwnersPackageTestCase.php', 'PhabricatorOwnersPackageTransaction' => 'applications/owners/storage/PhabricatorOwnersPackageTransaction.php', @@ -7411,6 +7412,7 @@ phutil_register_library_map(array( 'PhabricatorOwnersPackageOwnerDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorOwnersPackagePHIDType' => 'PhabricatorPHIDType', 'PhabricatorOwnersPackageQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorOwnersPackageRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'PhabricatorOwnersPackageSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorOwnersPackageTestCase' => 'PhabricatorTestCase', 'PhabricatorOwnersPackageTransaction' => 'PhabricatorApplicationTransaction', diff --git a/src/applications/owners/application/PhabricatorOwnersApplication.php b/src/applications/owners/application/PhabricatorOwnersApplication.php index 4b4841390a..3ef5f974d9 100644 --- a/src/applications/owners/application/PhabricatorOwnersApplication.php +++ b/src/applications/owners/application/PhabricatorOwnersApplication.php @@ -39,6 +39,12 @@ final class PhabricatorOwnersApplication extends PhabricatorApplication { return self::GROUP_UTILITIES; } + public function getRemarkupRules() { + return array( + new PhabricatorOwnersPackageRemarkupRule(), + ); + } + public function getRoutes() { return array( '/owners/' => array( diff --git a/src/applications/owners/controller/PhabricatorOwnersDetailController.php b/src/applications/owners/controller/PhabricatorOwnersDetailController.php index 5da36ad473..8329e9f931 100644 --- a/src/applications/owners/controller/PhabricatorOwnersDetailController.php +++ b/src/applications/owners/controller/PhabricatorOwnersDetailController.php @@ -144,7 +144,7 @@ final class PhabricatorOwnersDetailController } $crumbs = $this->buildApplicationCrumbs(); - $crumbs->addTextCrumb($package->getName()); + $crumbs->addTextCrumb($package->getMonogram()); $crumbs->setBorder(true); $timeline = $this->buildTransactionTimeline( diff --git a/src/applications/owners/phid/PhabricatorOwnersPackagePHIDType.php b/src/applications/owners/phid/PhabricatorOwnersPackagePHIDType.php index fa667d4dcb..891a9726c8 100644 --- a/src/applications/owners/phid/PhabricatorOwnersPackagePHIDType.php +++ b/src/applications/owners/phid/PhabricatorOwnersPackagePHIDType.php @@ -36,12 +36,47 @@ final class PhabricatorOwnersPackagePHIDType extends PhabricatorPHIDType { foreach ($handles as $phid => $handle) { $package = $objects[$phid]; + $monogram = $package->getMonogram(); $name = $package->getName(); $id = $package->getID(); - $handle->setName($name); + $handle->setName($monogram); + $handle->setFullName("{$monogram}: {$name}"); $handle->setURI("/owners/package/{$id}/"); + + if ($package->isArchived()) { + $handle->setStatus(PhabricatorObjectHandle::STATUS_CLOSED); + } } } + public function canLoadNamedObject($name) { + return preg_match('/^O\d*[1-9]\d*$/i', $name); + } + + public function loadNamedObjects( + PhabricatorObjectQuery $query, + array $names) { + + $id_map = array(); + foreach ($names as $name) { + $id = (int)substr($name, 1); + $id_map[$id][] = $name; + } + + $objects = id(new PhabricatorOwnersPackageQuery()) + ->setViewer($query->getViewer()) + ->withIDs(array_keys($id_map)) + ->execute(); + + $results = array(); + foreach ($objects as $id => $object) { + foreach (idx($id_map, $id, array()) as $name) { + $results[$name] = $object; + } + } + + return $results; + } + } diff --git a/src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php b/src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php index f92817d79e..e74d3c6a63 100644 --- a/src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php +++ b/src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php @@ -136,7 +136,7 @@ final class PhabricatorOwnersPackageSearchEngine $item = id(new PHUIObjectItemView()) ->setObject($package) - ->setObjectName(pht('Package %d', $id)) + ->setObjectName($package->getMonogram()) ->setHeader($package->getName()) ->setHref('/owners/package/'.$id.'/'); diff --git a/src/applications/owners/remarkup/PhabricatorOwnersPackageRemarkupRule.php b/src/applications/owners/remarkup/PhabricatorOwnersPackageRemarkupRule.php new file mode 100644 index 0000000000..475f6c57be --- /dev/null +++ b/src/applications/owners/remarkup/PhabricatorOwnersPackageRemarkupRule.php @@ -0,0 +1,19 @@ +getEngine()->getConfig('viewer'); + + return id(new PhabricatorOwnersPackageQuery()) + ->setViewer($viewer) + ->withIDs($ids) + ->execute(); + } + +} diff --git a/src/applications/owners/storage/PhabricatorOwnersPackage.php b/src/applications/owners/storage/PhabricatorOwnersPackage.php index adfc4d94d8..83c007e170 100644 --- a/src/applications/owners/storage/PhabricatorOwnersPackage.php +++ b/src/applications/owners/storage/PhabricatorOwnersPackage.php @@ -289,6 +289,10 @@ final class PhabricatorOwnersPackage return isset($owner_phids[$phid]); } + public function getMonogram() { + return 'O'.$this->getID(); + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */