From c1a4bee4a1787f11292aa978ec42df68005cccc7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 4 Jun 2020 09:42:50 -0700 Subject: [PATCH] Add "Author" and "Parent Revision" hardpoints to RevisionRefs Summary: Ref T13546. These are used by a future "arc land" workflow to support the "Land changes you don't own?" and "Land changes with open dependencies?" prompts. Test Plan: Ran a future "arc land" flow, hit both prompts. Maniphest Tasks: T13546 Differential Revision: https://secure.phabricator.com/D21311 --- src/__phutil_library_map__.php | 4 + .../ArcanistRevisionAuthorHardpointQuery.php | 35 ++++++++ ...visionParentRevisionRefsHardpointQuery.php | 82 +++++++++++++++++++ src/ref/revision/ArcanistRevisionRef.php | 39 +++++++++ 4 files changed, 160 insertions(+) create mode 100644 src/ref/revision/ArcanistRevisionAuthorHardpointQuery.php create mode 100644 src/ref/revision/ArcanistRevisionParentRevisionRefsHardpointQuery.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d4f29121..0fd75f9c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -400,7 +400,9 @@ phutil_register_library_map(array( 'ArcanistReusedIteratorReferenceXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistReusedIteratorReferenceXHPASTLinterRuleTestCase.php', 'ArcanistReusedIteratorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistReusedIteratorXHPASTLinterRule.php', 'ArcanistReusedIteratorXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistReusedIteratorXHPASTLinterRuleTestCase.php', + 'ArcanistRevisionAuthorHardpointQuery' => 'ref/revision/ArcanistRevisionAuthorHardpointQuery.php', 'ArcanistRevisionCommitMessageHardpointQuery' => 'ref/revision/ArcanistRevisionCommitMessageHardpointQuery.php', + 'ArcanistRevisionParentRevisionRefsHardpointQuery' => 'ref/revision/ArcanistRevisionParentRevisionRefsHardpointQuery.php', 'ArcanistRevisionRef' => 'ref/revision/ArcanistRevisionRef.php', 'ArcanistRevisionRefSource' => 'ref/ArcanistRevisionRefSource.php', 'ArcanistRevisionSymbolRef' => 'ref/revision/ArcanistRevisionSymbolRef.php', @@ -1390,7 +1392,9 @@ phutil_register_library_map(array( 'ArcanistReusedIteratorReferenceXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase', 'ArcanistReusedIteratorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistReusedIteratorXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase', + 'ArcanistRevisionAuthorHardpointQuery' => 'ArcanistRuntimeHardpointQuery', 'ArcanistRevisionCommitMessageHardpointQuery' => 'ArcanistRuntimeHardpointQuery', + 'ArcanistRevisionParentRevisionRefsHardpointQuery' => 'ArcanistRuntimeHardpointQuery', 'ArcanistRevisionRef' => array( 'ArcanistRef', 'ArcanistDisplayRefInterface', diff --git a/src/ref/revision/ArcanistRevisionAuthorHardpointQuery.php b/src/ref/revision/ArcanistRevisionAuthorHardpointQuery.php new file mode 100644 index 00000000..df6e1261 --- /dev/null +++ b/src/ref/revision/ArcanistRevisionAuthorHardpointQuery.php @@ -0,0 +1,35 @@ + $ref) { + $symbols[$key] = id(new ArcanistUserSymbolRef()) + ->setSymbol($ref->getAuthorPHID()); + } + + yield $this->yieldRequests( + $symbols, + array( + ArcanistSymbolRef::HARDPOINT_OBJECT, + )); + + $results = mpull($symbols, 'getObject'); + + yield $this->yieldMap($results); + } + +} diff --git a/src/ref/revision/ArcanistRevisionParentRevisionRefsHardpointQuery.php b/src/ref/revision/ArcanistRevisionParentRevisionRefsHardpointQuery.php new file mode 100644 index 00000000..0fde2dd6 --- /dev/null +++ b/src/ref/revision/ArcanistRevisionParentRevisionRefsHardpointQuery.php @@ -0,0 +1,82 @@ + mpull($refs, 'getPHID'), + 'types' => array( + 'revision.parent', + ), + ); + + $data = array(); + while (true) { + $results = (yield $this->yieldConduit( + 'edge.search', + $parameters)); + + foreach ($results['data'] as $item) { + $data[] = $item; + } + + if ($results['cursor']['after'] === null) { + break; + } + + $parameters['after'] = $results['cursor']['after']; + } + + if (!$data) { + yield $this->yieldValue($refs, array()); + } + + $map = array(); + $symbols = array(); + foreach ($data as $edge) { + $src = $edge['sourcePHID']; + $dst = $edge['destinationPHID']; + + $map[$src][$dst] = $dst; + + $symbols[$dst] = id(new ArcanistRevisionSymbolRef()) + ->setSymbol($dst); + } + + yield $this->yieldRequests( + $symbols, + array( + ArcanistSymbolRef::HARDPOINT_OBJECT, + )); + + $objects = array(); + foreach ($symbols as $key => $symbol) { + $object = $symbol->getObject(); + if ($object) { + $objects[$key] = $object; + } + } + + $results = array_fill_keys(array_keys($refs), array()); + foreach ($refs as $ref_key => $ref) { + $revision_phid = $ref->getPHID(); + $parent_phids = idx($map, $revision_phid, array()); + $parent_refs = array_select_keys($objects, $parent_phids); + $results[$ref_key] = $parent_refs; + } + + yield $this->yieldMap($results); + } + +} diff --git a/src/ref/revision/ArcanistRevisionRef.php b/src/ref/revision/ArcanistRevisionRef.php index 96b05d45..4c0fd5f6 100644 --- a/src/ref/revision/ArcanistRevisionRef.php +++ b/src/ref/revision/ArcanistRevisionRef.php @@ -6,6 +6,8 @@ final class ArcanistRevisionRef ArcanistDisplayRefInterface { const HARDPOINT_COMMITMESSAGE = 'ref.revision.commitmessage'; + const HARDPOINT_AUTHORREF = 'ref.revision.authorRef'; + const HARDPOINT_PARENTREVISIONREFS = 'ref.revision.parentRevisionRefs'; private $parameters; private $sources = array(); @@ -15,8 +17,13 @@ final class ArcanistRevisionRef } protected function newHardpoints() { + $object_list = new ArcanistObjectListHardpoint(); return array( $this->newHardpoint(self::HARDPOINT_COMMITMESSAGE), + $this->newHardpoint(self::HARDPOINT_AUTHORREF), + $this->newTemplateHardpoint( + self::HARDPOINT_PARENTREVISIONREFS, + $object_list), ); } @@ -63,6 +70,30 @@ final class ArcanistRevisionRef return idxv($this->parameters, array('fields', 'status', 'name')); } + public function isStatusChangesPlanned() { + $status = $this->getStatus(); + return ($status === 'changes-planned'); + } + + public function isStatusAbandoned() { + $status = $this->getStatus(); + return ($status === 'abandoned'); + } + + public function isStatusClosed() { + $status = $this->getStatus(); + return ($status === 'closed'); + } + + public function isStatusAccepted() { + $status = $this->getStatus(); + return ($status === 'accepted'); + } + + public function getStatus() { + return idxv($this->parameters, array('fields', 'status', 'value')); + } + public function isClosed() { return idxv($this->parameters, array('fields', 'status', 'closed')); } @@ -114,6 +145,14 @@ final class ArcanistRevisionRef return $this->getHardpoint(self::HARDPOINT_COMMITMESSAGE); } + public function getAuthorRef() { + return $this->getHardpoint(self::HARDPOINT_AUTHORREF); + } + + public function getParentRevisionRefs() { + return $this->getHardpoint(self::HARDPOINT_PARENTREVISIONREFS); + } + public function getDisplayRefObjectName() { return $this->getMonogram(); }