1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

Reduce callsites to "ArcanistDifferentialRevisionStatus" in Phabricator

Summary:
Ref T2543. These are currently numeric values, like "0" and "3". I want to replace them with strings, like "accepted", and move definitions from Arcanist to Phabricator.

To set the stage for this, reduce the number of callsites where Phabricator invokes `ArcanistDifferentialRevisionStatus`.

This is just the easy ones. I'll hold this until the release cut.

Test Plan:
- Called `differential.find`.
- Called `differential.getrevision`.
- Called `differential.query`.
- Removed all reviewers from a revision, saw warning.
- Abandoned the no-reviewers revision, no more warning.
- Attached a revision to a task to get it to show the state icon with the status on a tooltip.
- Viewed revision bucketing on dashboard.
- Used `bin/search index` to reindex a revision.
- Hit the "Land Revision" endpoint.

I didn't explicitly test these cases:

  - Doorkeeper Asana integration, since setup takes a thousand years.
  - Disambiguation logic when multiple hashes match, since setup is also very involved.
  - Releeph because it's Releeph.

Reviewers: chad

Reviewed By: chad

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T2543

Differential Revision: https://secure.phabricator.com/D18339
This commit is contained in:
epriestley 2017-08-04 05:29:49 -07:00
parent b1e3cf627d
commit 2e36653965
15 changed files with 49 additions and 69 deletions

View file

@ -88,9 +88,7 @@ final class DifferentialFindConduitAPIMethod
'uri' => PhabricatorEnv::getProductionURI('/D'.$id), 'uri' => PhabricatorEnv::getProductionURI('/D'.$id),
'dateCreated' => $revision->getDateCreated(), 'dateCreated' => $revision->getDateCreated(),
'authorPHID' => $revision->getAuthorPHID(), 'authorPHID' => $revision->getAuthorPHID(),
'statusName' => 'statusName' => $revision->getStatusDisplayName(),
ArcanistDifferentialRevisionStatus::getNameForRevisionStatus(
$revision->getStatus()),
'sourcePath' => $diff->getSourcePath(), 'sourcePath' => $diff->getSourcePath(),
); );
} }

View file

@ -83,9 +83,7 @@ final class DifferentialGetRevisionConduitAPIMethod
'uri' => PhabricatorEnv::getURI('/D'.$revision->getID()), 'uri' => PhabricatorEnv::getURI('/D'.$revision->getID()),
'title' => $revision->getTitle(), 'title' => $revision->getTitle(),
'status' => $revision->getStatus(), 'status' => $revision->getStatus(),
'statusName' => 'statusName' => $revision->getStatusDisplayName(),
ArcanistDifferentialRevisionStatus::getNameForRevisionStatus(
$revision->getStatus()),
'summary' => $revision->getSummary(), 'summary' => $revision->getSummary(),
'testPlan' => $revision->getTestPlan(), 'testPlan' => $revision->getTestPlan(),
'lineCount' => $revision->getLineCount(), 'lineCount' => $revision->getLineCount(),

View file

@ -221,9 +221,7 @@ final class DifferentialQueryConduitAPIMethod
'dateModified' => $revision->getDateModified(), 'dateModified' => $revision->getDateModified(),
'authorPHID' => $revision->getAuthorPHID(), 'authorPHID' => $revision->getAuthorPHID(),
'status' => $revision->getStatus(), 'status' => $revision->getStatus(),
'statusName' => 'statusName' => $revision->getStatusDisplayName(),
ArcanistDifferentialRevisionStatus::getNameForRevisionStatus(
$revision->getStatus()),
'properties' => $revision->getProperties(), 'properties' => $revision->getProperties(),
'branch' => $diff->getBranch(), 'branch' => $diff->getBranch(),
'summary' => $revision->getSummary(), 'summary' => $revision->getSummary(),

View file

@ -76,16 +76,17 @@ final class DifferentialBranchField
PhabricatorApplicationTransactionEditor $editor, PhabricatorApplicationTransactionEditor $editor,
array $xactions) { array $xactions) {
$status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED; $revision = $this->getObject();
// Show the "BRANCH" section only if there's a new diff or the revision // Show the "BRANCH" section only if there's a new diff or the revision
// is "Accepted". // is "Accepted".
if ((!$editor->getDiffUpdateTransaction($xactions)) && $is_update = (bool)$editor->getDiffUpdateTransaction($xactions);
($this->getObject()->getStatus() != $status_accepted)) { $is_accepted = $revision->isAccepted();
if (!$is_update && !$is_accepted) {
return; return;
} }
$branch = $this->getBranchDescription($this->getObject()->getActiveDiff()); $branch = $this->getBranchDescription($revision->getActiveDiff());
if ($branch === null) { if ($branch === null) {
return; return;
} }

View file

@ -68,8 +68,7 @@ final class DifferentialReviewersField
public function getWarningsForRevisionHeader(array $handles) { public function getWarningsForRevisionHeader(array $handles) {
$revision = $this->getObject(); $revision = $this->getObject();
$status_needs_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW; if (!$revision->isNeedsReview()) {
if ($revision->getStatus() != $status_needs_review) {
return array(); return array();
} }

View file

@ -35,8 +35,7 @@ final class DifferentialDoorkeeperRevisionFeedStoryPublisher
} }
public function getActiveUserPHIDs($object) { public function getActiveUserPHIDs($object) {
$status = $object->getStatus(); if ($object->isNeedsReview()) {
if ($status == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) {
return $object->getReviewerPHIDs(); return $object->getReviewerPHIDs();
} else { } else {
return array(); return array();
@ -44,8 +43,7 @@ final class DifferentialDoorkeeperRevisionFeedStoryPublisher
} }
public function getPassiveUserPHIDs($object) { public function getPassiveUserPHIDs($object) {
$status = $object->getStatus(); if ($object->isNeedsReview()) {
if ($status == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) {
return array(); return array();
} else { } else {
return $object->getReviewerPHIDs(); return $object->getReviewerPHIDs();

View file

@ -50,8 +50,7 @@ final class DifferentialRevisionPHIDType extends PhabricatorPHIDType {
$icon = DifferentialRevisionStatus::getRevisionStatusIcon($status); $icon = DifferentialRevisionStatus::getRevisionStatusIcon($status);
$color = DifferentialRevisionStatus::getRevisionStatusColor($status); $color = DifferentialRevisionStatus::getRevisionStatusColor($status);
$name = ArcanistDifferentialRevisionStatus::getNameForRevisionStatus( $name = $revision->getStatusDisplayName();
$status);
$handle $handle
->setStateIcon($icon) ->setStateIcon($icon)

View file

@ -134,13 +134,11 @@ final class DifferentialRevisionRequiredActionResultBucket
} }
private function filterShouldLand(array $phids) { private function filterShouldLand(array $phids) {
$status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED;
$objects = $this->getRevisionsAuthored($this->objects, $phids); $objects = $this->getRevisionsAuthored($this->objects, $phids);
$results = array(); $results = array();
foreach ($objects as $key => $object) { foreach ($objects as $key => $object) {
if ($object->getStatus() != $status_accepted) { if (!$object->isAccepted()) {
continue; continue;
} }
@ -175,13 +173,11 @@ final class DifferentialRevisionRequiredActionResultBucket
} }
private function filterWaitingForReview(array $phids) { private function filterWaitingForReview(array $phids) {
$status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW;
$objects = $this->getRevisionsAuthored($this->objects, $phids); $objects = $this->getRevisionsAuthored($this->objects, $phids);
$results = array(); $results = array();
foreach ($objects as $key => $object) { foreach ($objects as $key => $object) {
if ($object->getStatus() != $status_review) { if (!$object->isNeedsReview()) {
continue; continue;
} }
@ -217,16 +213,11 @@ final class DifferentialRevisionRequiredActionResultBucket
} }
private function filterWaitingOnOtherReviewers(array $phids) { private function filterWaitingOnOtherReviewers(array $phids) {
$statuses = array(
ArcanistDifferentialRevisionStatus::NEEDS_REVIEW,
);
$statuses = array_fuse($statuses);
$objects = $this->getRevisionsNotAuthored($this->objects, $phids); $objects = $this->getRevisionsNotAuthored($this->objects, $phids);
$results = array(); $results = array();
foreach ($objects as $key => $object) { foreach ($objects as $key => $object) {
if (!isset($statuses[$object->getStatus()])) { if (!$object->isNeedsReview()) {
continue; continue;
} }

View file

@ -15,9 +15,8 @@ abstract class DifferentialRevisionResultBucket
$objects = $this->getRevisionsNotAuthored($objects, $phids); $objects = $this->getRevisionsNotAuthored($objects, $phids);
$status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW;
foreach ($objects as $key => $object) { foreach ($objects as $key => $object) {
if ($object->getStatus() != $status_review) { if (!$object->isNeedsReview()) {
continue; continue;
} }

View file

@ -235,11 +235,9 @@ final class DifferentialRevisionSearchEngine
} }
private function loadUnlandedDependencies(array $revisions) { private function loadUnlandedDependencies(array $revisions) {
$status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED;
$phids = array(); $phids = array();
foreach ($revisions as $revision) { foreach ($revisions as $revision) {
if ($revision->getStatus() != $status_accepted) { if (!$revision->isAccepted()) {
continue; continue;
} }

View file

@ -34,8 +34,7 @@ final class DifferentialRevisionFulltextEngine
// If a revision needs review, the owners are the reviewers. Otherwise, the // If a revision needs review, the owners are the reviewers. Otherwise, the
// owner is the author (e.g., accepted, rejected, closed). // owner is the author (e.g., accepted, rejected, closed).
$status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW; if ($revision->isNeedsReview()) {
if ($revision->getStatus() == $status_review) {
$reviewers = $revision->getReviewerPHIDs(); $reviewers = $revision->getReviewerPHIDs();
$reviewers = array_fuse($reviewers); $reviewers = array_fuse($reviewers);

View file

@ -626,6 +626,11 @@ final class DifferentialRevision extends DifferentialDAO
return ($this->getStatus() == $status_accepted); return ($this->getStatus() == $status_accepted);
} }
public function isNeedsReview() {
$status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW;
return ($this->getStatus() == $status_review);
}
public function getStatusIcon() { public function getStatusIcon() {
$map = array( $map = array(
ArcanistDifferentialRevisionStatus::NEEDS_REVIEW ArcanistDifferentialRevisionStatus::NEEDS_REVIEW

View file

@ -122,9 +122,8 @@ final class DiffusionLowLevelCommitFieldsQuery
$revisions = array_reverse($revisions); $revisions = array_reverse($revisions);
// Try to find an accepted revision first. // Try to find an accepted revision first.
$status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED;
foreach ($revisions as $revision) { foreach ($revisions as $revision) {
if ($revision->getStatus() == $status_accepted) { if ($revision->isAccepted()) {
return $revision; return $revision;
} }
} }

View file

@ -289,31 +289,30 @@ final class DrydockLandRepositoryOperation
); );
} }
$status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED; if ($revision->isAccepted()) {
if ($revision->getStatus() != $status_accepted) { // We can land accepted revisions, so continue below. Otherwise, raise
switch ($revision->getStatus()) { // an error with tailored messaging for the most common cases.
case ArcanistDifferentialRevisionStatus::CLOSED: } else if ($revision->isAbandoned()) {
return array( return array(
'title' => pht('Revision Closed'), 'title' => pht('Revision Abandoned'),
'body' => pht( 'body' => pht(
'This revision has already been closed. Only open, accepted '. 'This revision has been abandoned. Only accepted revisions '.
'revisions may land.'), 'may land.'),
); );
case ArcanistDifferentialRevisionStatus::ABANDONED: } else if ($revision->isClosed()) {
return array( return array(
'title' => pht('Revision Abandoned'), 'title' => pht('Revision Closed'),
'body' => pht( 'body' => pht(
'This revision has been abandoned. Only accepted revisions '. 'This revision has already been closed. Only open, accepted '.
'may land.'), 'revisions may land.'),
); );
default: } else {
return array( return array(
'title' => pht('Revision Not Accepted'), 'title' => pht('Revision Not Accepted'),
'body' => pht( 'body' => pht(
'This revision is still under review. Only revisions which '. 'This revision is still under review. Only revisions which '.
'have been accepted may land.'), 'have been accepted may land.'),
); );
}
} }
// Check for other operations. Eventually this should probably be more // Check for other operations. Eventually this should probably be more

View file

@ -79,8 +79,7 @@ final class DifferentialReleephRequestFieldSpecification extends Phobject {
return null; return null;
} }
$status = $this->getRevision()->getStatus(); if ($this->getRevision()->isClosed()) {
if ($status == ArcanistDifferentialRevisionStatus::CLOSED) {
$verb = $tense[$this->releephAction]['past']; $verb = $tense[$this->releephAction]['past'];
} else { } else {
$verb = $tense[$this->releephAction]['future']; $verb = $tense[$this->releephAction]['future'];