1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-26 23:40:57 +01:00

Implement Build Plan "Hold Drafts" behavior

Summary: Ref T13258. Makes the new "Hold Drafts" behavior actually work.

Test Plan:
  - Created a build plan which does "Make HTTP Request" somewhere random and then waits for a message.
  - Created a Herald rule which "Always" runs this plan.
  - Created revisions, loaded them, then sent their build targets a "fail" message a short time later.
    - With "Always": Current behavior. Revision was held as a draft while building, and returned to me for changes when the build failed.
    - With "If Building": Revision was held as a draft while building, but promoted once the build failed.
    - With "Never": Revision promoted immediately, ignoring the build completely.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13258

Differential Revision: https://secure.phabricator.com/D20232
This commit is contained in:
epriestley 2019-02-28 13:02:14 -08:00
parent 578de333df
commit 718cdc2447
2 changed files with 45 additions and 5 deletions

View file

@ -877,7 +877,7 @@ final class DifferentialRevision extends DifferentialDAO
PhabricatorUser $viewer,
array $phids) {
return id(new HarbormasterBuildQuery())
$builds = id(new HarbormasterBuildQuery())
->setViewer($viewer)
->withBuildablePHIDs($phids)
->withAutobuilds(false)
@ -893,6 +893,41 @@ final class DifferentialRevision extends DifferentialDAO
HarbormasterBuildStatus::STATUS_DEADLOCKED,
))
->execute();
// Filter builds based on the "Hold Drafts" behavior of their associated
// build plans.
$hold_drafts = HarbormasterBuildPlanBehavior::BEHAVIOR_DRAFTS;
$behavior = HarbormasterBuildPlanBehavior::getBehavior($hold_drafts);
$key_never = HarbormasterBuildPlanBehavior::DRAFTS_NEVER;
$key_building = HarbormasterBuildPlanBehavior::DRAFTS_IF_BUILDING;
foreach ($builds as $key => $build) {
$plan = $build->getBuildPlan();
$hold_key = $behavior->getPlanOption($plan)->getKey();
$hold_never = ($hold_key === $key_never);
$hold_building = ($hold_key === $key_building);
// If the build "Never" holds drafts from promoting, we don't care what
// the status is.
if ($hold_never) {
unset($builds[$key]);
continue;
}
// If the build holds drafts from promoting "While Building", we only
// care about the status until it completes.
if ($hold_building) {
if ($build->isComplete()) {
unset($builds[$key]);
continue;
}
}
}
return $builds;
}

View file

@ -17,6 +17,11 @@ final class HarbormasterBuildPlanBehavior
const RESTARTABLE_ALWAYS = 'always';
const RESTARTABLE_NEVER = 'never';
const BEHAVIOR_DRAFTS = 'hold-drafts';
const DRAFTS_ALWAYS = 'always';
const DRAFTS_IF_BUILDING = 'building';
const DRAFTS_NEVER = 'never';
public function setKey($key) {
$this->key = $key;
return $this;
@ -138,7 +143,7 @@ final class HarbormasterBuildPlanBehavior
public static function newPlanBehaviors() {
$draft_options = array(
id(new HarbormasterBuildPlanBehaviorOption())
->setKey('always')
->setKey(self::DRAFTS_ALWAYS)
->setIcon('fa-check-circle-o green')
->setName(pht('Always'))
->setIsDefault(true)
@ -147,7 +152,7 @@ final class HarbormasterBuildPlanBehavior
'Revisions are not sent for review until the build completes, '.
'and are returned to the author for updates if the build fails.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey('building')
->setKey(self::DRAFTS_IF_BUILDING)
->setIcon('fa-pause-circle-o yellow')
->setName(pht('If Building'))
->setDescription(
@ -155,7 +160,7 @@ final class HarbormasterBuildPlanBehavior
'Revisions are not sent for review until the build completes, '.
'but they will be sent for review even if it fails.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey('never')
->setKey(self::DRAFTS_NEVER)
->setIcon('fa-circle-o red')
->setName(pht('Never'))
->setDescription(
@ -262,7 +267,7 @@ final class HarbormasterBuildPlanBehavior
$behaviors = array(
id(new self())
->setKey('hold-drafts')
->setKey(self::BEHAVIOR_DRAFTS)
->setName(pht('Hold Drafts'))
->setEditInstructions(
pht(