Differential D19380 Diff 46383 src/applications/differential/editor/DifferentialTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/editor/DifferentialTransactionEditor.php
Show First 20 Lines • Show All 1,549 Lines • ▼ Show 20 Lines | protected function didApplyTransactions($object, array $xactions) { | ||||
// If a draft revision has no outstanding builds and we're automatically | // If a draft revision has no outstanding builds and we're automatically | ||||
// making drafts public after builds finish, make the revision public. | // making drafts public after builds finish, make the revision public. | ||||
if ($can_undraft) { | if ($can_undraft) { | ||||
$auto_undraft = !$object->getHoldAsDraft(); | $auto_undraft = !$object->getHoldAsDraft(); | ||||
} else { | } else { | ||||
$auto_undraft = false; | $auto_undraft = false; | ||||
} | } | ||||
if ($object->isDraft() && $auto_undraft) { | $can_promote = false; | ||||
$can_demote = false; | |||||
// "Draft" revisions can promote to "Review Requested" after builds pass, | |||||
// or demote to "Changes Planned" after builds fail. | |||||
if ($object->isDraft()) { | |||||
$can_promote = true; | |||||
$can_demote = true; | |||||
} | |||||
// See PHI584. "Changes Planned" revisions which are not yet broadcasting | |||||
// can promote to "Review Requested" if builds pass. | |||||
// This pass is presumably the result of someone restarting the builds and | |||||
// having them work this time, perhaps because the builds are not perfectly | |||||
// reliable or perhaps because someone fixed some issue with build hardware | |||||
// or some other dependency. | |||||
// Currently, there's no legitimate way to end up in this state except | |||||
// through automatic demotion, so this behavior should not generate an | |||||
// undue level of confusion or ambiguity. Also note that these changes can | |||||
// not demote again since they've already been demoted once. | |||||
if ($object->isChangePlanned()) { | |||||
if (!$object->getShouldBroadcast()) { | |||||
$can_promote = true; | |||||
} | |||||
} | |||||
if (($can_promote || $can_demote) && $auto_undraft) { | |||||
$status = $this->loadCompletedBuildableStatus($object); | $status = $this->loadCompletedBuildableStatus($object); | ||||
$is_passed = ($status === HarbormasterBuildableStatus::STATUS_PASSED); | $is_passed = ($status === HarbormasterBuildableStatus::STATUS_PASSED); | ||||
$is_failed = ($status === HarbormasterBuildableStatus::STATUS_FAILED); | $is_failed = ($status === HarbormasterBuildableStatus::STATUS_FAILED); | ||||
if ($is_passed) { | if ($is_passed && $can_promote) { | ||||
// When Harbormaster moves a revision out of the draft state, we | // When Harbormaster moves a revision out of the draft state, we | ||||
// attribute the action to the revision author since this is more | // attribute the action to the revision author since this is more | ||||
// natural and more useful. | // natural and more useful. | ||||
// Additionally, we change the acting PHID for the transaction set | // Additionally, we change the acting PHID for the transaction set | ||||
// to the author if it isn't already a user so that mail comes from | // to the author if it isn't already a user so that mail comes from | ||||
// the natural author. | // the natural author. | ||||
$acting_phid = $this->getActingAsPHID(); | $acting_phid = $this->getActingAsPHID(); | ||||
Show All 15 Lines | if (($can_promote || $can_demote) && $auto_undraft) { | ||||
if ($this->getIsNewObject()) { | if ($this->getIsNewObject()) { | ||||
$xaction->setIsCreateTransaction(true); | $xaction->setIsCreateTransaction(true); | ||||
} | } | ||||
// Queue this transaction and apply it separately after the current | // Queue this transaction and apply it separately after the current | ||||
// batch of transactions finishes so that Herald can fire on the new | // batch of transactions finishes so that Herald can fire on the new | ||||
// revision state. See T13027 for discussion. | // revision state. See T13027 for discussion. | ||||
$this->queueTransaction($xaction); | $this->queueTransaction($xaction); | ||||
} else if ($is_failed) { | } else if ($is_failed && $can_demote) { | ||||
// When demoting a revision, we act as "Harbormaster" instead of | // When demoting a revision, we act as "Harbormaster" instead of | ||||
// the author since this feels a little more natural. | // the author since this feels a little more natural. | ||||
$harbormaster_phid = id(new PhabricatorHarbormasterApplication()) | $harbormaster_phid = id(new PhabricatorHarbormasterApplication()) | ||||
->getPHID(); | ->getPHID(); | ||||
$xaction = $object->getApplicationTransactionTemplate() | $xaction = $object->getApplicationTransactionTemplate() | ||||
->setAuthorPHID($harbormaster_phid) | ->setAuthorPHID($harbormaster_phid) | ||||
->setMetadataValue('draft.demote', true) | ->setMetadataValue('draft.demote', true) | ||||
->setTransactionType( | ->setTransactionType( | ||||
DifferentialRevisionPlanChangesTransaction::TRANSACTIONTYPE) | DifferentialRevisionPlanChangesTransaction::TRANSACTIONTYPE) | ||||
->setNewValue(true); | ->setNewValue(true); | ||||
$this->queueTransaction($xaction); | $this->queueTransaction($xaction); | ||||
// TODO: Notify the author (only) that we did this. | |||||
epriestley: This got fixed elsewhere, it just didn't actually touch this piece of code so I never removed… | |||||
} | } | ||||
} | } | ||||
// If the revision is new or was a draft, and is no longer a draft, we | // If the revision is new or was a draft, and is no longer a draft, we | ||||
// might be sending the first email about it. | // might be sending the first email about it. | ||||
// This might mean it was created directly into a non-draft state, or | // This might mean it was created directly into a non-draft state, or | ||||
// it just automatically undrafted after builds finished, or a user | // it just automatically undrafted after builds finished, or a user | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
This got fixed elsewhere, it just didn't actually touch this piece of code so I never removed the comment.