Skip to content

Commit afd0473

Browse files
author
epriestley
committed
Add a "Create build step" transaction to Harbormaster
Summary: Without this, build steps that have no options (like "wait for previous commits") don't actually save, since the transaction array is empty. This also generally nice and consistent. Test Plan: Created a new "wait" step, viewed transaction log. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D8791
1 parent 78bf266 commit afd0473

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

src/applications/harbormaster/controller/HarbormasterStepEditController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ public function processRequest() {
8181
// if we create plans elsewhere.
8282
$steps = $plan->loadOrderedBuildSteps();
8383
$step->setSequence(count($steps) + 1);
84+
85+
// When creating a new step, make sure we have a create transaction
86+
// so we'll apply the transactions even if the step has no
87+
// configurable options.
88+
$create_xaction = id(new HarbormasterBuildStepTransaction())
89+
->setTransactionType(HarbormasterBuildStepTransaction::TYPE_CREATE);
90+
array_unshift($xactions, $create_xaction);
8491
}
8592

8693
try {

src/applications/harbormaster/editor/HarbormasterBuildStepEditor.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,60 @@
33
final class HarbormasterBuildStepEditor
44
extends PhabricatorApplicationTransactionEditor {
55

6+
public function getTransactionTypes() {
7+
$types = parent::getTransactionTypes();
8+
9+
$types[] = HarbormasterBuildStepTransaction::TYPE_CREATE;
10+
11+
return $types;
12+
}
13+
14+
protected function getCustomTransactionOldValue(
15+
PhabricatorLiskDAO $object,
16+
PhabricatorApplicationTransaction $xaction) {
17+
18+
switch ($xaction->getTransactionType()) {
19+
case HarbormasterBuildStepTransaction::TYPE_CREATE:
20+
return null;
21+
}
22+
23+
return parent::getCustomTransactionOldValue($object, $xaction);
24+
}
25+
26+
protected function getCustomTransactionNewValue(
27+
PhabricatorLiskDAO $object,
28+
PhabricatorApplicationTransaction $xaction) {
29+
30+
switch ($xaction->getTransactionType()) {
31+
case HarbormasterBuildStepTransaction::TYPE_CREATE:
32+
return true;
33+
}
34+
35+
return parent::getCustomTransactionNewValue($object, $xaction);
36+
}
37+
38+
protected function applyCustomInternalTransaction(
39+
PhabricatorLiskDAO $object,
40+
PhabricatorApplicationTransaction $xaction) {
41+
42+
switch ($xaction->getTransactionType()) {
43+
case HarbormasterBuildStepTransaction::TYPE_CREATE:
44+
return;
45+
}
46+
47+
return parent::applyCustomInternalTransaction($object, $xaction);
48+
}
49+
50+
protected function applyCustomExternalTransaction(
51+
PhabricatorLiskDAO $object,
52+
PhabricatorApplicationTransaction $xaction) {
53+
54+
switch ($xaction->getTransactionType()) {
55+
case HarbormasterBuildStepTransaction::TYPE_CREATE:
56+
return;
57+
}
58+
59+
return parent::applyCustomExternalTransaction($object, $xaction);
60+
}
61+
662
}

src/applications/harbormaster/storage/configuration/HarbormasterBuildStepTransaction.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
final class HarbormasterBuildStepTransaction
44
extends PhabricatorApplicationTransaction {
55

6+
const TYPE_CREATE = 'harbormaster:step:create';
7+
68
public function getApplicationName() {
79
return 'harbormaster';
810
}
@@ -11,4 +13,48 @@ public function getApplicationTransactionType() {
1113
return HarbormasterPHIDTypeBuildStep::TYPECONST;
1214
}
1315

16+
public function getTitle() {
17+
$author_phid = $this->getAuthorPHID();
18+
19+
$old = $this->getOldValue();
20+
$new = $this->getNewValue();
21+
22+
switch ($this->getTransactionType()) {
23+
case self::TYPE_CREATE:
24+
return pht(
25+
'%s created this build step.',
26+
$this->renderHandleLink($author_phid));
27+
}
28+
29+
return parent::getTitle();
30+
}
31+
32+
public function getIcon() {
33+
$author_phid = $this->getAuthorPHID();
34+
35+
$old = $this->getOldValue();
36+
$new = $this->getNewValue();
37+
38+
switch ($this->getTransactionType()) {
39+
case self::TYPE_CREATE:
40+
return 'create';
41+
}
42+
43+
return parent::getIcon();
44+
}
45+
46+
public function getColor() {
47+
$author_phid = $this->getAuthorPHID();
48+
49+
$old = $this->getOldValue();
50+
$new = $this->getNewValue();
51+
52+
switch ($this->getTransactionType()) {
53+
case self::TYPE_CREATE:
54+
return 'green';
55+
}
56+
57+
return parent::getColor();
58+
}
59+
1460
}

0 commit comments

Comments
 (0)