@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.

Remove remaining ArcanistDifferentialRevisionStatus references in revision state logic

Summary: Ref T2543. This cleans up all the "when no one is rejecting/blocking and someone accepted, mark the revision overall as accepted" logic to use more modern status stuff instead of `ArcanistDifferentialRevisionStatus`.

Test Plan:
- Updated revisions, saw them go to "Needs Review".
- Accepted, requested changes to revisions.
- Updated one with changes requested, saw it go to "needs review" again.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T2543

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

+118 -96
+99 -96
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 125 125 PhabricatorLiskDAO $object, 126 126 PhabricatorApplicationTransaction $xaction) { 127 127 128 - $status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW; 129 - $status_revision = ArcanistDifferentialRevisionStatus::NEEDS_REVISION; 130 - $status_plan = ArcanistDifferentialRevisionStatus::CHANGES_PLANNED; 131 - $status_abandoned = ArcanistDifferentialRevisionStatus::ABANDONED; 132 - $status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED; 133 - 134 128 switch ($xaction->getTransactionType()) { 135 129 case DifferentialTransaction::TYPE_INLINE: 136 130 return; 137 131 case DifferentialTransaction::TYPE_UPDATE: 138 132 if (!$this->getIsCloseByCommit()) { 139 - switch ($object->getStatus()) { 140 - case $status_revision: 141 - case $status_plan: 142 - case $status_abandoned: 143 - $object->setStatus($status_review); 144 - break; 133 + if ($object->isNeedsRevision() || 134 + $object->isChangePlanned() || 135 + $object->isAbandoned()) { 136 + $object->setModernRevisionStatus( 137 + DifferentialRevisionStatus::NEEDS_REVIEW); 145 138 } 146 139 } 147 140 ··· 196 189 $actor_phid = $this->getActingAsPHID(); 197 190 $type_edge = PhabricatorTransactions::TYPE_EDGE; 198 191 199 - $status_plan = ArcanistDifferentialRevisionStatus::CHANGES_PLANNED; 200 - 201 192 $edge_ref_task = DifferentialRevisionHasTaskEdgeType::EDGECONST; 202 193 203 194 $is_sticky_accept = PhabricatorEnv::getEnvConfig( ··· 220 211 case DifferentialRevisionRequestReviewTransaction::TRANSACTIONTYPE: 221 212 $downgrade_rejects = true; 222 213 if ((!$is_sticky_accept) || 223 - ($object->getStatus() != $status_plan)) { 214 + (!$object->isChangePlanned())) { 224 215 // If the old state isn't "changes planned", downgrade the accepts. 225 216 // This exception allows an accepted revision to go through 226 217 // "Plan Changes" -> "Request Review" and return to "accepted" if ··· 462 453 } 463 454 } 464 455 465 - $status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED; 466 - $status_revision = ArcanistDifferentialRevisionStatus::NEEDS_REVISION; 467 - $status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW; 456 + $xactions = $this->updateReviewStatus($object, $xactions); 457 + $this->markReviewerComments($object, $xactions); 468 458 469 - $is_sticky_accept = PhabricatorEnv::getEnvConfig( 470 - 'differential.sticky-accept'); 459 + return $xactions; 460 + } 471 461 472 - $old_status = $object->getStatus(); 473 - $active_diff = $object->getActiveDiff(); 474 - switch ($old_status) { 475 - case $status_accepted: 476 - case $status_revision: 477 - case $status_review: 478 - // Try to move a revision to "accepted". We look for: 479 - // 480 - // - at least one accepting reviewer who is a user; and 481 - // - no rejects; and 482 - // - no rejects of older diffs; and 483 - // - no blocking reviewers. 462 + private function updateReviewStatus( 463 + DifferentialRevision $revision, 464 + array $xactions) { 484 465 485 - $has_accepting_user = false; 486 - $has_rejecting_reviewer = false; 487 - $has_rejecting_older_reviewer = false; 488 - $has_blocking_reviewer = false; 489 - foreach ($object->getReviewers() as $reviewer) { 490 - $reviewer_status = $reviewer->getReviewerStatus(); 491 - switch ($reviewer_status) { 492 - case DifferentialReviewerStatus::STATUS_REJECTED: 493 - $active_phid = $active_diff->getPHID(); 494 - if ($reviewer->isRejected($active_phid)) { 495 - $has_rejecting_reviewer = true; 496 - } else { 497 - $has_rejecting_older_reviewer = true; 498 - } 499 - break; 500 - case DifferentialReviewerStatus::STATUS_REJECTED_OLDER: 501 - $has_rejecting_older_reviewer = true; 502 - break; 503 - case DifferentialReviewerStatus::STATUS_BLOCKING: 504 - $has_blocking_reviewer = true; 505 - break; 506 - case DifferentialReviewerStatus::STATUS_ACCEPTED: 507 - if ($reviewer->isUser()) { 508 - $active_phid = $active_diff->getPHID(); 509 - if ($reviewer->isAccepted($active_phid)) { 510 - $has_accepting_user = true; 511 - } 512 - } 513 - break; 514 - } 515 - } 466 + $was_accepted = $revision->isAccepted(); 467 + $was_revision = $revision->isNeedsRevision(); 468 + $was_review = $revision->isNeedsReview(); 469 + if (!$was_accepted && !$was_revision && !$was_review) { 470 + // Revisions can't transition out of other statuses (like closed or 471 + // abandoned) as a side effect of reviewer status changes. 472 + return $xactions; 473 + } 516 474 517 - $new_status = null; 518 - if ($has_accepting_user && 519 - !$has_rejecting_reviewer && 520 - !$has_rejecting_older_reviewer && 521 - !$has_blocking_reviewer) { 522 - $new_status = $status_accepted; 523 - } else if ($has_rejecting_reviewer) { 524 - // This isn't accepted, and there's at least one rejecting reviewer, 525 - // so the revision needs changes. This usually happens after a 526 - // "reject". 527 - $new_status = $status_revision; 528 - } else if ($old_status == $status_accepted) { 529 - // This revision was accepted, but it no longer satisfies the 530 - // conditions for acceptance. This usually happens after an accepting 531 - // reviewer resigns or is removed. 532 - $new_status = $status_review; 533 - } 475 + // Try to move a revision to "accepted". We look for: 476 + // 477 + // - at least one accepting reviewer who is a user; and 478 + // - no rejects; and 479 + // - no rejects of older diffs; and 480 + // - no blocking reviewers. 534 481 535 - if ($new_status !== null && ($new_status != $old_status)) { 536 - $xaction = id(new DifferentialTransaction()) 537 - ->setTransactionType( 538 - DifferentialRevisionStatusTransaction::TRANSACTIONTYPE) 539 - ->setOldValue($old_status) 540 - ->setNewValue($new_status); 482 + $has_accepting_user = false; 483 + $has_rejecting_reviewer = false; 484 + $has_rejecting_older_reviewer = false; 485 + $has_blocking_reviewer = false; 541 486 542 - $xaction = $this->populateTransaction($object, $xaction)->save(); 487 + $active_diff = $revision->getActiveDiff(); 488 + foreach ($revision->getReviewers() as $reviewer) { 489 + $reviewer_status = $reviewer->getReviewerStatus(); 490 + switch ($reviewer_status) { 491 + case DifferentialReviewerStatus::STATUS_REJECTED: 492 + $active_phid = $active_diff->getPHID(); 493 + if ($reviewer->isRejected($active_phid)) { 494 + $has_rejecting_reviewer = true; 495 + } else { 496 + $has_rejecting_older_reviewer = true; 497 + } 498 + break; 499 + case DifferentialReviewerStatus::STATUS_REJECTED_OLDER: 500 + $has_rejecting_older_reviewer = true; 501 + break; 502 + case DifferentialReviewerStatus::STATUS_BLOCKING: 503 + $has_blocking_reviewer = true; 504 + break; 505 + case DifferentialReviewerStatus::STATUS_ACCEPTED: 506 + if ($reviewer->isUser()) { 507 + $active_phid = $active_diff->getPHID(); 508 + if ($reviewer->isAccepted($active_phid)) { 509 + $has_accepting_user = true; 510 + } 511 + } 512 + break; 513 + } 514 + } 515 + 516 + $new_status = null; 517 + if ($has_accepting_user && 518 + !$has_rejecting_reviewer && 519 + !$has_rejecting_older_reviewer && 520 + !$has_blocking_reviewer) { 521 + $new_status = DifferentialRevisionStatus::ACCEPTED; 522 + } else if ($has_rejecting_reviewer) { 523 + // This isn't accepted, and there's at least one rejecting reviewer, 524 + // so the revision needs changes. This usually happens after a 525 + // "reject". 526 + $new_status = DifferentialRevisionStatus::NEEDS_REVISION; 527 + } else if ($was_accepted) { 528 + // This revision was accepted, but it no longer satisfies the 529 + // conditions for acceptance. This usually happens after an accepting 530 + // reviewer resigns or is removed. 531 + $new_status = DifferentialRevisionStatus::NEEDS_REVIEW; 532 + } 543 533 544 - $xactions[] = $xaction; 534 + if ($new_status === null) { 535 + return $xactions; 536 + } 545 537 546 - $object->setStatus($new_status)->save(); 547 - } 548 - break; 549 - default: 550 - // Revisions can't transition out of other statuses (like closed or 551 - // abandoned) as a side effect of reviewer status changes. 552 - break; 538 + $old_legacy_status = $revision->getStatus(); 539 + $revision->setModernRevisionStatus($new_status); 540 + $new_legacy_status = $revision->getStatus(); 541 + if ($new_legacy_status == $old_legacy_status) { 542 + return $xactions; 553 543 } 554 544 545 + $xaction = id(new DifferentialTransaction()) 546 + ->setTransactionType( 547 + DifferentialRevisionStatusTransaction::TRANSACTIONTYPE) 548 + ->setOldValue($old_legacy_status) 549 + ->setNewValue($new_legacy_status); 555 550 556 - $this->markReviewerComments($object, $xactions); 551 + $xaction = $this->populateTransaction($revision, $xaction) 552 + ->save(); 553 + $xactions[] = $xaction; 554 + 555 + // Save the status adjustment we made earlier. 556 + // TODO: This can be a little cleaner and more obvious once storage 557 + // migrates. 558 + $revision->save(); 557 559 558 560 return $xactions; 559 561 } 562 + 560 563 561 564 protected function validateTransaction( 562 565 PhabricatorLiskDAO $object,
+19
src/applications/differential/storage/DifferentialRevision.php
··· 612 612 return $this; 613 613 } 614 614 615 + public function setModernRevisionStatus($status) { 616 + $status_object = DifferentialRevisionStatus::newForStatus($status); 617 + 618 + if ($status_object->getKey() != $status) { 619 + throw new Exception( 620 + pht( 621 + 'Trying to set revision to invalid status "%s".', 622 + $status)); 623 + } 624 + 625 + $legacy_status = $status_object->getLegacyKey(); 626 + 627 + return $this->setStatus($legacy_status); 628 + } 629 + 615 630 public function isClosed() { 616 631 return $this->getStatusObject()->isClosedStatus(); 617 632 } ··· 626 641 627 642 public function isNeedsReview() { 628 643 return $this->getStatusObject()->isNeedsReview(); 644 + } 645 + 646 + public function isNeedsRevision() { 647 + return $this->getStatusObject()->isNeedsRevision(); 629 648 } 630 649 631 650 public function isChangePlanned() {