repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/plan/HarbormasterBuildPlanBehaviorOption.php | src/applications/harbormaster/plan/HarbormasterBuildPlanBehaviorOption.php | <?php
final class HarbormasterBuildPlanBehaviorOption
extends Phobject {
private $name;
private $key;
private $icon;
private $description;
private $isDefault;
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
public function setKey($key) {
$this->key = $key;
return $this;
}
public function getKey() {
return $this->key;
}
public function setDescription($description) {
$this->description = $description;
return $this;
}
public function getDescription() {
return $this->description;
}
public function setIsDefault($is_default) {
$this->isDefault = $is_default;
return $this;
}
public function getIsDefault() {
return $this->isDefault;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function getIcon() {
return $this->icon;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php | src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php | <?php
final class HarbormasterBuildPlanBehavior
extends Phobject {
private $key;
private $name;
private $options;
private $defaultKey;
private $editInstructions;
const BEHAVIOR_RUNNABLE = 'runnable';
const RUNNABLE_IF_VIEWABLE = 'view';
const RUNNABLE_IF_EDITABLE = 'edit';
const BEHAVIOR_RESTARTABLE = 'restartable';
const RESTARTABLE_ALWAYS = 'always';
const RESTARTABLE_IF_FAILED = 'failed';
const RESTARTABLE_NEVER = 'never';
const BEHAVIOR_DRAFTS = 'hold-drafts';
const DRAFTS_ALWAYS = 'always';
const DRAFTS_IF_BUILDING = 'building';
const DRAFTS_NEVER = 'never';
const BEHAVIOR_BUILDABLE = 'buildable';
const BUILDABLE_ALWAYS = 'always';
const BUILDABLE_IF_BUILDING = 'building';
const BUILDABLE_NEVER = 'never';
const BEHAVIOR_LANDWARNING = 'arc-land';
const LANDWARNING_ALWAYS = 'always';
const LANDWARNING_IF_BUILDING = 'building';
const LANDWARNING_IF_COMPLETE = 'complete';
const LANDWARNING_NEVER = 'never';
public function setKey($key) {
$this->key = $key;
return $this;
}
public function getKey() {
return $this->key;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
public function setEditInstructions($edit_instructions) {
$this->editInstructions = $edit_instructions;
return $this;
}
public function getEditInstructions() {
return $this->editInstructions;
}
public function getOptionMap() {
return mpull($this->options, 'getName', 'getKey');
}
public function setOptions(array $options) {
assert_instances_of($options, 'HarbormasterBuildPlanBehaviorOption');
$key_map = array();
$default = null;
foreach ($options as $option) {
$key = $option->getKey();
if (isset($key_map[$key])) {
throw new Exception(
pht(
'Multiple behavior options (for behavior "%s") have the same '.
'key ("%s"). Each option must have a unique key.',
$this->getKey(),
$key));
}
$key_map[$key] = true;
if ($option->getIsDefault()) {
if ($default === null) {
$default = $key;
} else {
throw new Exception(
pht(
'Multiple behavior options (for behavior "%s") are marked as '.
'default options ("%s" and "%s"). Exactly one option must be '.
'marked as the default option.',
$this->getKey(),
$default,
$key));
}
}
}
if ($default === null) {
throw new Exception(
pht(
'No behavior option is marked as the default option (for '.
'behavior "%s"). Exactly one option must be marked as the '.
'default option.',
$this->getKey()));
}
$this->options = mpull($options, null, 'getKey');
$this->defaultKey = $default;
return $this;
}
public function getOptions() {
return $this->options;
}
public function getPlanOption(HarbormasterBuildPlan $plan) {
$behavior_key = $this->getKey();
$storage_key = self::getStorageKeyForBehaviorKey($behavior_key);
$plan_value = $plan->getPlanProperty($storage_key);
if (isset($this->options[$plan_value])) {
return $this->options[$plan_value];
}
return idx($this->options, $this->defaultKey);
}
public static function getTransactionMetadataKey() {
return 'behavior-key';
}
public static function getStorageKeyForBehaviorKey($behavior_key) {
return sprintf('behavior.%s', $behavior_key);
}
public static function getBehavior($key) {
$behaviors = self::newPlanBehaviors();
if (!isset($behaviors[$key])) {
throw new Exception(
pht(
'No build plan behavior with key "%s" exists.',
$key));
}
return $behaviors[$key];
}
public static function newPlanBehaviors() {
$draft_options = array(
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::DRAFTS_ALWAYS)
->setIcon('fa-check-circle-o green')
->setName(pht('Always'))
->setIsDefault(true)
->setDescription(
pht(
'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(self::DRAFTS_IF_BUILDING)
->setIcon('fa-pause-circle-o yellow')
->setName(pht('If Building'))
->setDescription(
pht(
'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(self::DRAFTS_NEVER)
->setIcon('fa-circle-o red')
->setName(pht('Never'))
->setDescription(
pht(
'Revisions are sent for review regardless of the status of the '.
'build.')),
);
$land_options = array(
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::LANDWARNING_ALWAYS)
->setIcon('fa-check-circle-o green')
->setName(pht('Always'))
->setIsDefault(true)
->setDescription(
pht(
'"arc land" warns if the build is still running or has '.
'failed.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::LANDWARNING_IF_BUILDING)
->setIcon('fa-pause-circle-o yellow')
->setName(pht('If Building'))
->setDescription(
pht(
'"arc land" warns if the build is still running, but ignores '.
'the build if it has failed.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::LANDWARNING_IF_COMPLETE)
->setIcon('fa-dot-circle-o yellow')
->setName(pht('If Complete'))
->setDescription(
pht(
'"arc land" warns if the build has failed, but ignores the '.
'build if it is still running.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::LANDWARNING_NEVER)
->setIcon('fa-circle-o red')
->setName(pht('Never'))
->setDescription(
pht(
'"arc land" never warns that the build is still running or '.
'has failed.')),
);
$aggregate_options = array(
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::BUILDABLE_ALWAYS)
->setIcon('fa-check-circle-o green')
->setName(pht('Always'))
->setIsDefault(true)
->setDescription(
pht(
'The buildable waits for the build, and fails if the '.
'build fails.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::BUILDABLE_IF_BUILDING)
->setIcon('fa-pause-circle-o yellow')
->setName(pht('If Building'))
->setDescription(
pht(
'The buildable waits for the build, but does not fail '.
'if the build fails.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::BUILDABLE_NEVER)
->setIcon('fa-circle-o red')
->setName(pht('Never'))
->setDescription(
pht(
'The buildable does not wait for the build.')),
);
$restart_options = array(
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::RESTARTABLE_ALWAYS)
->setIcon('fa-repeat green')
->setName(pht('Always'))
->setIsDefault(true)
->setDescription(
pht('The build may be restarted.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::RESTARTABLE_IF_FAILED)
->setIcon('fa-times-circle-o yellow')
->setName(pht('If Failed'))
->setDescription(
pht('The build may be restarted if it has failed.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::RESTARTABLE_NEVER)
->setIcon('fa-times red')
->setName(pht('Never'))
->setDescription(
pht('The build may not be restarted.')),
);
$run_options = array(
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::RUNNABLE_IF_EDITABLE)
->setIcon('fa-pencil green')
->setName(pht('If Editable'))
->setIsDefault(true)
->setDescription(
pht('Only users who can edit the plan can run it manually.')),
id(new HarbormasterBuildPlanBehaviorOption())
->setKey(self::RUNNABLE_IF_VIEWABLE)
->setIcon('fa-exclamation-triangle yellow')
->setName(pht('If Viewable'))
->setDescription(
pht(
'Any user who can view the plan can run it manually.')),
);
$behaviors = array(
id(new self())
->setKey(self::BEHAVIOR_DRAFTS)
->setName(pht('Hold Drafts'))
->setEditInstructions(
pht(
'When users create revisions in Differential, the default '.
'behavior is to hold them in the "Draft" state until all builds '.
'pass. Once builds pass, the revisions promote and are sent for '.
'review, which notifies reviewers.'.
"\n\n".
'The general intent of this workflow is to make sure reviewers '.
'are only spending time on review once changes survive automated '.
'tests. If a change does not pass tests, it usually is not '.
'really ready for review.'.
"\n\n".
'If you want to promote revisions out of "Draft" before builds '.
'pass, or promote revisions even when builds fail, you can '.
'change the promotion behavior. This may be useful if you have '.
'very long-running builds, or some builds which are not very '.
'important.'.
"\n\n".
'Users may always use "Request Review" to promote a "Draft" '.
'revision, even if builds have failed or are still in progress.'))
->setOptions($draft_options),
id(new self())
->setKey(self::BEHAVIOR_LANDWARNING)
->setName(pht('Warn When Landing'))
->setEditInstructions(
pht(
'When a user attempts to `arc land` a revision and that revision '.
'has ongoing or failed builds, the default behavior of `arc` is '.
'to warn them about those builds and give them a chance to '.
'reconsider: they may want to wait for ongoing builds to '.
'complete, or fix failed builds before landing the change.'.
"\n\n".
'If you do not want to warn users about this build, you can '.
'change the warning behavior. This may be useful if the build '.
'takes a long time to run (so you do not expect users to wait '.
'for it) or the outcome is not important.'.
"\n\n".
'This warning is only advisory. Users may always elect to ignore '.
'this warning and continue, even if builds have failed.'.
"\n\n".
'This setting also affects the warning that is published to '.
'revisions when commits land with ongoing or failed builds.'))
->setOptions($land_options),
id(new self())
->setKey(self::BEHAVIOR_BUILDABLE)
->setEditInstructions(
pht(
'The overall state of a buildable (like a commit or revision) is '.
'normally the aggregation of the individual states of all builds '.
'that have run against it.'.
"\n\n".
'Buildables are "building" until all builds pass (which changes '.
'them to "pass"), or any build fails (which changes them to '.
'"fail").'.
"\n\n".
'You can change this behavior if you do not want to wait for this '.
'build, or do not care if it fails.'))
->setName(pht('Affects Buildable'))
->setOptions($aggregate_options),
id(new self())
->setKey(self::BEHAVIOR_RESTARTABLE)
->setEditInstructions(
pht(
'Usually, builds may be restarted by users who have permission '.
'to edit the related build plan. (You can change who is allowed '.
'to restart a build by adjusting the "Runnable" behavior.)'.
"\n\n".
'Restarting a build may be useful if you suspect it has failed '.
'for environmental or circumstantial reasons unrelated to the '.
'actual code, and want to give it another chance at glory.'.
"\n\n".
'If you want to prevent a build from being restarted, you can '.
'change when it may be restarted by adjusting this behavior. '.
'This may be useful to prevent accidents where a build with a '.
'dangerous side effect (like deployment) is restarted '.
'improperly.'))
->setName(pht('Restartable'))
->setOptions($restart_options),
id(new self())
->setKey(self::BEHAVIOR_RUNNABLE)
->setEditInstructions(
pht(
'To run a build manually, you normally must have permission to '.
'edit the related build plan. If you would prefer that anyone who '.
'can see the build plan be able to run and restart the build, you '.
'can change the behavior here.'.
"\n\n".
'Note that this controls access to all build management actions: '.
'"Run Plan Manually", "Restart", "Abort", "Pause", and "Resume".'.
"\n\n".
'WARNING: This may be unsafe, particularly if the build has '.
'side effects like deployment.'.
"\n\n".
'If you weaken this policy, an attacker with control of an '.
'account that has "Can View" permission but not "Can Edit" '.
'permission can manually run this build against any old version '.
'of the code, including versions with known security issues.'.
"\n\n".
'If running the build has a side effect like deploying code, '.
'they can force deployment of a vulnerable version and then '.
'escalate into an attack against the deployed service.'))
->setName(pht('Runnable'))
->setOptions($run_options),
);
return mpull($behaviors, null, 'getKey');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/editor/HarbormasterBuildEditEngine.php | src/applications/harbormaster/editor/HarbormasterBuildEditEngine.php | <?php
final class HarbormasterBuildEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'harbormaster.build';
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Harbormaster Builds');
}
public function getSummaryHeader() {
return pht('Edit Harbormaster Build Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Harbormaster builds.');
}
public function getEngineApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function newEditableObject() {
$viewer = $this->getViewer();
return HarbormasterBuild::initializeNewBuild($viewer);
}
protected function newObjectQuery() {
return new HarbormasterBuildQuery();
}
protected function newEditableObjectForDocumentation() {
$object = new DifferentialRevision();
$buildable = id(new HarbormasterBuildable())
->attachBuildableObject($object);
return $this->newEditableObject()
->attachBuildable($buildable);
}
protected function getObjectCreateTitleText($object) {
return pht('Create Build');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Build');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Build: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return pht('Edit Build');
}
protected function getObjectCreateShortText() {
return pht('Create Build');
}
protected function getObjectName() {
return pht('Build');
}
protected function getEditorURI() {
return '/harbormaster/build/edit/';
}
protected function getObjectCreateCancelURI($object) {
return '/harbormaster/';
}
protected function getObjectViewURI($object) {
return $object->getURI();
}
protected function buildCustomEditFields($object) {
return array();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/editor/HarbormasterBuildPlanEditEngine.php | src/applications/harbormaster/editor/HarbormasterBuildPlanEditEngine.php | <?php
final class HarbormasterBuildPlanEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'harbormaster.buildplan';
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Harbormaster Build Plans');
}
public function getSummaryHeader() {
return pht('Edit Harbormaster Build Plan Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Harbormaster build plans.');
}
public function getEngineApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function newEditableObject() {
$viewer = $this->getViewer();
return HarbormasterBuildPlan::initializeNewBuildPlan($viewer);
}
protected function newObjectQuery() {
return new HarbormasterBuildPlanQuery();
}
protected function getObjectCreateTitleText($object) {
return pht('Create Build Plan');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Build Plan');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Build Plan: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return pht('Edit Build Plan');
}
protected function getObjectCreateShortText() {
return pht('Create Build Plan');
}
protected function getObjectName() {
return pht('Build Plan');
}
protected function getEditorURI() {
return '/harbormaster/plan/edit/';
}
protected function getObjectCreateCancelURI($object) {
return '/harbormaster/plan/';
}
protected function getObjectViewURI($object) {
$id = $object->getID();
return "/harbormaster/plan/{$id}/";
}
protected function getCreateNewObjectPolicy() {
return $this->getApplication()->getPolicy(
HarbormasterCreatePlansCapability::CAPABILITY);
}
protected function buildCustomEditFields($object) {
$fields = array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setIsRequired(true)
->setTransactionType(
HarbormasterBuildPlanNameTransaction::TRANSACTIONTYPE)
->setDescription(pht('The build plan name.'))
->setConduitDescription(pht('Rename the plan.'))
->setConduitTypeDescription(pht('New plan name.'))
->setValue($object->getName()),
);
$metadata_key = HarbormasterBuildPlanBehavior::getTransactionMetadataKey();
$behaviors = HarbormasterBuildPlanBehavior::newPlanBehaviors();
foreach ($behaviors as $behavior) {
$key = $behavior->getKey();
// Get the raw key off the object so that we don't reset stuff to
// default values by mistake if a behavior goes missing somehow.
$storage_key = HarbormasterBuildPlanBehavior::getStorageKeyForBehaviorKey(
$key);
$behavior_option = $object->getPlanProperty($storage_key);
if ($behavior_option === null || !strlen($behavior_option)) {
$behavior_option = $behavior->getPlanOption($object)->getKey();
}
$fields[] = id(new PhabricatorSelectEditField())
->setIsFormField(false)
->setKey(sprintf('behavior.%s', $behavior->getKey()))
->setMetadataValue($metadata_key, $behavior->getKey())
->setLabel(pht('Behavior: %s', $behavior->getName()))
->setTransactionType(
HarbormasterBuildPlanBehaviorTransaction::TRANSACTIONTYPE)
->setValue($behavior_option)
->setOptions($behavior->getOptionMap());
}
return $fields;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/editor/HarbormasterBuildStepEditor.php | src/applications/harbormaster/editor/HarbormasterBuildStepEditor.php | <?php
final class HarbormasterBuildStepEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
public function getEditorObjectsDescription() {
return pht('Harbormaster Build Steps');
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = HarbormasterBuildStepTransaction::TYPE_CREATE;
$types[] = HarbormasterBuildStepTransaction::TYPE_NAME;
$types[] = HarbormasterBuildStepTransaction::TYPE_DEPENDS_ON;
$types[] = HarbormasterBuildStepTransaction::TYPE_DESCRIPTION;
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case HarbormasterBuildStepTransaction::TYPE_CREATE:
return null;
case HarbormasterBuildStepTransaction::TYPE_NAME:
if ($this->getIsNewObject()) {
return null;
}
return $object->getName();
case HarbormasterBuildStepTransaction::TYPE_DEPENDS_ON:
if ($this->getIsNewObject()) {
return null;
}
return $object->getDetail('dependsOn', array());
case HarbormasterBuildStepTransaction::TYPE_DESCRIPTION:
if ($this->getIsNewObject()) {
return null;
}
return $object->getDescription();
}
return parent::getCustomTransactionOldValue($object, $xaction);
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case HarbormasterBuildStepTransaction::TYPE_CREATE:
return true;
case HarbormasterBuildStepTransaction::TYPE_NAME:
case HarbormasterBuildStepTransaction::TYPE_DEPENDS_ON:
case HarbormasterBuildStepTransaction::TYPE_DESCRIPTION:
return $xaction->getNewValue();
}
return parent::getCustomTransactionNewValue($object, $xaction);
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case HarbormasterBuildStepTransaction::TYPE_CREATE:
return;
case HarbormasterBuildStepTransaction::TYPE_NAME:
return $object->setName($xaction->getNewValue());
case HarbormasterBuildStepTransaction::TYPE_DEPENDS_ON:
return $object->setDetail('dependsOn', $xaction->getNewValue());
case HarbormasterBuildStepTransaction::TYPE_DESCRIPTION:
return $object->setDescription($xaction->getNewValue());
}
return parent::applyCustomInternalTransaction($object, $xaction);
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case HarbormasterBuildStepTransaction::TYPE_CREATE:
case HarbormasterBuildStepTransaction::TYPE_NAME:
case HarbormasterBuildStepTransaction::TYPE_DEPENDS_ON:
case HarbormasterBuildStepTransaction::TYPE_DESCRIPTION:
return;
}
return parent::applyCustomExternalTransaction($object, $xaction);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/editor/HarbormasterBuildableTransactionEditor.php | src/applications/harbormaster/editor/HarbormasterBuildableTransactionEditor.php | <?php
final class HarbormasterBuildableTransactionEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
public function getEditorObjectsDescription() {
return pht('Harbormaster Buildables');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/editor/HarbormasterBuildTransactionEditor.php | src/applications/harbormaster/editor/HarbormasterBuildTransactionEditor.php | <?php
final class HarbormasterBuildTransactionEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
public function getEditorObjectsDescription() {
return pht('Harbormaster Builds');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/editor/HarbormasterBuildStepEditEngine.php | src/applications/harbormaster/editor/HarbormasterBuildStepEditEngine.php | <?php
final class HarbormasterBuildStepEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'harbormaster.buildstep';
private $buildPlan;
public function setBuildPlan(HarbormasterBuildPlan $build_plan) {
$this->buildPlan = $build_plan;
return $this;
}
public function getBuildPlan() {
if ($this->buildPlan === null) {
throw new PhutilInvalidStateException('setBuildPlan');
}
return $this->buildPlan;
}
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Harbormaster Build Steps');
}
public function getSummaryHeader() {
return pht('Edit Harbormaster Build Step Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Harbormaster build steps.');
}
public function getEngineApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function newEditableObject() {
$viewer = $this->getViewer();
$plan = HarbormasterBuildPlan::initializeNewBuildPlan($viewer);
$this->setBuildPlan($plan);
$plan = $this->getBuildPlan();
$step = HarbormasterBuildStep::initializeNewStep($viewer);
$step->setBuildPlanPHID($plan->getPHID());
$step->attachBuildPlan($plan);
return $step;
}
protected function newObjectQuery() {
return new HarbormasterBuildStepQuery();
}
protected function getObjectCreateTitleText($object) {
return pht('Create Build Step');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Build Step');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Build Step: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return pht('Edit Build Step');
}
protected function getObjectCreateShortText() {
return pht('Create Build Step');
}
protected function getObjectName() {
return pht('Build Step');
}
protected function getEditorURI() {
return '/harbormaster/step/edit/';
}
protected function getObjectCreateCancelURI($object) {
return '/harbormaster/step/';
}
protected function getObjectViewURI($object) {
$id = $object->getID();
return "/harbormaster/step/{$id}/";
}
protected function buildCustomEditFields($object) {
$fields = array();
return $fields;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/editor/HarbormasterBuildPlanEditor.php | src/applications/harbormaster/editor/HarbormasterBuildPlanEditor.php | <?php
final class HarbormasterBuildPlanEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
public function getEditorObjectsDescription() {
return pht('Harbormaster Build Plans');
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this build plan.', $author);
}
public function getCreateObjectTitleForFeed($author, $object) {
return pht('%s created %s.', $author, $object);
}
protected function supportsSearch() {
return true;
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/editor/HarbormasterBuildableEditEngine.php | src/applications/harbormaster/editor/HarbormasterBuildableEditEngine.php | <?php
final class HarbormasterBuildableEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'harbormaster.buildable';
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Harbormaster Buildables');
}
public function getSummaryHeader() {
return pht('Edit Harbormaster Buildable Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Harbormaster buildables.');
}
public function getEngineApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function newEditableObject() {
$viewer = $this->getViewer();
return HarbormasterBuildable::initializeNewBuildable($viewer);
}
protected function newObjectQuery() {
return new HarbormasterBuildableQuery();
}
protected function newEditableObjectForDocumentation() {
$object = new DifferentialRevision();
return $this->newEditableObject()
->attachBuildableObject($object);
}
protected function getObjectCreateTitleText($object) {
return pht('Create Buildable');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Buildable');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Buildable: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return pht('Edit Buildable');
}
protected function getObjectCreateShortText() {
return pht('Create Buildable');
}
protected function getObjectName() {
return pht('Buildable');
}
protected function getEditorURI() {
return '/harbormaster/buildable/edit/';
}
protected function getObjectCreateCancelURI($object) {
return '/harbormaster/';
}
protected function getObjectViewURI($object) {
return $object->getURI();
}
protected function buildCustomEditFields($object) {
return array();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanTransactionType.php | src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanTransactionType.php | <?php
abstract class HarbormasterBuildPlanTransactionType
extends PhabricatorModularTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanNameTransaction.php | src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanNameTransaction.php | <?php
final class HarbormasterBuildPlanNameTransaction
extends HarbormasterBuildPlanTransactionType {
const TRANSACTIONTYPE = 'harbormaster:name';
public function generateOldValue($object) {
return $object->getName();
}
public function applyInternalEffects($object, $value) {
$object->setName($value);
}
public function getTitle() {
return pht(
'%s renamed this build plan from "%s" to "%s".',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('You must choose a name for your build plan.'));
}
return $errors;
}
public function getTransactionTypeForConduit($xaction) {
return 'name';
}
public function getFieldValuesForConduit($xaction, $data) {
return array(
'old' => $xaction->getOldValue(),
'new' => $xaction->getNewValue(),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanStatusTransaction.php | src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanStatusTransaction.php | <?php
final class HarbormasterBuildPlanStatusTransaction
extends HarbormasterBuildPlanTransactionType {
const TRANSACTIONTYPE = 'harbormaster:status';
public function generateOldValue($object) {
return $object->getPlanStatus();
}
public function applyInternalEffects($object, $value) {
$object->setPlanStatus($value);
}
public function getTitle() {
$new = $this->getNewValue();
if ($new === HarbormasterBuildPlan::STATUS_DISABLED) {
return pht(
'%s disabled this build plan.',
$this->renderAuthor());
} else {
return pht(
'%s enabled this build plan.',
$this->renderAuthor());
}
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$options = array(
HarbormasterBuildPlan::STATUS_DISABLED,
HarbormasterBuildPlan::STATUS_ACTIVE,
);
$options = array_fuse($options);
foreach ($xactions as $xaction) {
$new = $xaction->getNewValue();
if (!isset($options[$new])) {
$errors[] = $this->newInvalidError(
pht(
'Status "%s" is not a valid build plan status. Valid '.
'statuses are: %s.',
$new,
implode(', ', $options)));
continue;
}
}
return $errors;
}
public function getTransactionTypeForConduit($xaction) {
return 'status';
}
public function getFieldValuesForConduit($xaction, $data) {
return array(
'old' => $xaction->getOldValue(),
'new' => $xaction->getNewValue(),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanBehaviorTransaction.php | src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanBehaviorTransaction.php | <?php
final class HarbormasterBuildPlanBehaviorTransaction
extends HarbormasterBuildPlanTransactionType {
const TRANSACTIONTYPE = 'behavior';
public function generateOldValue($object) {
$behavior = $this->getBehavior();
return $behavior->getPlanOption($object)->getKey();
}
public function applyInternalEffects($object, $value) {
$key = $this->getStorageKey();
return $object->setPlanProperty($key, $value);
}
public function getTitle() {
$old_value = $this->getOldValue();
$new_value = $this->getNewValue();
$behavior = $this->getBehavior();
if ($behavior) {
$behavior_name = $behavior->getName();
$options = $behavior->getOptions();
if (isset($options[$old_value])) {
$old_value = $options[$old_value]->getName();
}
if (isset($options[$new_value])) {
$new_value = $options[$new_value]->getName();
}
} else {
$behavior_name = $this->getBehaviorKey();
}
return pht(
'%s changed the %s behavior for this plan from %s to %s.',
$this->renderAuthor(),
$this->renderValue($behavior_name),
$this->renderValue($old_value),
$this->renderValue($new_value));
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$behaviors = HarbormasterBuildPlanBehavior::newPlanBehaviors();
$behaviors = mpull($behaviors, null, 'getKey');
foreach ($xactions as $xaction) {
$key = $this->getBehaviorKeyForTransaction($xaction);
if (!isset($behaviors[$key])) {
$errors[] = $this->newInvalidError(
pht(
'No behavior with key "%s" exists. Valid keys are: %s.',
$key,
implode(', ', array_keys($behaviors))),
$xaction);
continue;
}
$behavior = $behaviors[$key];
$options = $behavior->getOptions();
$storage_key = HarbormasterBuildPlanBehavior::getStorageKeyForBehaviorKey(
$key);
$old = $object->getPlanProperty($storage_key);
$new = $xaction->getNewValue();
if ($old === $new) {
continue;
}
if (!isset($options[$new])) {
$errors[] = $this->newInvalidError(
pht(
'Value "%s" is not a valid option for behavior "%s". Valid '.
'options are: %s.',
$new,
$key,
implode(', ', array_keys($options))),
$xaction);
continue;
}
}
return $errors;
}
public function getTransactionTypeForConduit($xaction) {
return 'behavior';
}
public function getFieldValuesForConduit($xaction, $data) {
return array(
'key' => $this->getBehaviorKeyForTransaction($xaction),
'old' => $xaction->getOldValue(),
'new' => $xaction->getNewValue(),
);
}
private function getBehaviorKeyForTransaction(
PhabricatorApplicationTransaction $xaction) {
$metadata_key = HarbormasterBuildPlanBehavior::getTransactionMetadataKey();
return $xaction->getMetadataValue($metadata_key);
}
private function getBehaviorKey() {
$metadata_key = HarbormasterBuildPlanBehavior::getTransactionMetadataKey();
return $this->getMetadataValue($metadata_key);
}
private function getBehavior() {
$behavior_key = $this->getBehaviorKey();
$behaviors = HarbormasterBuildPlanBehavior::newPlanBehaviors();
return idx($behaviors, $behavior_key);
}
private function getStorageKey() {
return HarbormasterBuildPlanBehavior::getStorageKeyForBehaviorKey(
$this->getBehaviorKey());
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php | src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php | <?php
final class HarbormasterBuildMessageRestartTransaction
extends HarbormasterBuildMessageTransaction {
const TRANSACTIONTYPE = 'message/restart';
const MESSAGETYPE = 'restart';
public function getHarbormasterBuildMessageName() {
return pht('Restart Build');
}
public function getHarbormasterBuildableMessageName() {
return pht('Restart Builds');
}
public function getHarbormasterBuildableMessageEffect() {
return pht('Build will restart.');
}
public function newConfirmPromptTitle() {
return pht('Really restart build?');
}
public function newConfirmPromptBody() {
return pht(
'Progress on this build will be discarded and the build will restart. '.
'Side effects of the build will occur again. Really restart build?');
}
public function getHarbormasterBuildMessageDescription() {
return pht('Restart the build, discarding all progress.');
}
public function newBuildableConfirmPromptTitle(
array $builds,
array $sendable) {
return pht(
'Really restart %s build(s)?',
phutil_count($builds));
}
public function newBuildableConfirmPromptBody(
array $builds,
array $sendable) {
if (count($sendable) === count($builds)) {
return pht(
'All builds will restart.');
} else {
return pht(
'You can only restart some builds.');
}
}
public function newBuildableConfirmPromptWarnings(
array $builds,
array $sendable) {
$building = false;
foreach ($sendable as $build) {
if ($build->isBuilding()) {
$building = true;
break;
}
}
$warnings = array();
if ($building) {
$warnings[] = pht(
'Progress on running builds will be discarded.');
}
if ($sendable) {
$warnings[] = pht(
'When a build is restarted, side effects associated with '.
'the build may occur again.');
}
return $warnings;
}
public function getTitle() {
return pht(
'%s restarted this build.',
$this->renderAuthor());
}
public function getIcon() {
return 'fa-repeat';
}
public function applyInternalEffects($object, $value) {
$actor = $this->getActor();
$build = $object;
$build->restartBuild($actor);
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING);
}
protected function newCanApplyMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
if ($build->isAutobuild()) {
throw new HarbormasterMessageException(
pht('Can Not Restart Autobuild'),
pht(
'This build can not be restarted because it is an automatic '.
'build.'));
}
$restartable = HarbormasterBuildPlanBehavior::BEHAVIOR_RESTARTABLE;
$plan = $build->getBuildPlan();
// See T13526. Users who can't see the "BuildPlan" can end up here with
// no object. This is highly questionable.
if (!$plan) {
throw new HarbormasterMessageException(
pht('No Build Plan Permission'),
pht(
'You can not restart this build because you do not have '.
'permission to access the build plan.'));
}
$option = HarbormasterBuildPlanBehavior::getBehavior($restartable)
->getPlanOption($plan);
$option_key = $option->getKey();
$never_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_NEVER;
$is_never = ($option_key === $never_restartable);
if ($is_never) {
throw new HarbormasterMessageException(
pht('Build Plan Prevents Restart'),
pht(
'This build can not be restarted because the build plan is '.
'configured to prevent the build from restarting.'));
}
$failed_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_IF_FAILED;
$is_failed = ($option_key === $failed_restartable);
if ($is_failed) {
if (!$this->isFailed()) {
throw new HarbormasterMessageException(
pht('Only Restartable if Failed'),
pht(
'This build can not be restarted because the build plan is '.
'configured to prevent the build from restarting unless it '.
'has failed, and it has not failed.'));
}
}
}
protected function newCanSendMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
if ($build->isRestarting()) {
throw new HarbormasterMessageException(
pht('Already Restarting'),
pht(
'This build is already restarting. You can not reissue a restart '.
'command to a restarting build.'));
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/build/HarbormasterBuildMessagePauseTransaction.php | src/applications/harbormaster/xaction/build/HarbormasterBuildMessagePauseTransaction.php | <?php
final class HarbormasterBuildMessagePauseTransaction
extends HarbormasterBuildMessageTransaction {
const TRANSACTIONTYPE = 'message/pause';
const MESSAGETYPE = 'pause';
public function getHarbormasterBuildMessageName() {
return pht('Pause Build');
}
public function getHarbormasterBuildableMessageName() {
return pht('Pause Builds');
}
public function newConfirmPromptTitle() {
return pht('Really pause build?');
}
public function getHarbormasterBuildableMessageEffect() {
return pht('Build will pause.');
}
public function newConfirmPromptBody() {
return pht(
'If you pause this build, work will halt once the current steps '.
'complete. You can resume the build later.');
}
public function getHarbormasterBuildMessageDescription() {
return pht('Pause the build.');
}
public function newBuildableConfirmPromptTitle(
array $builds,
array $sendable) {
return pht(
'Really pause %s build(s)?',
phutil_count($builds));
}
public function newBuildableConfirmPromptBody(
array $builds,
array $sendable) {
if (count($sendable) === count($builds)) {
return pht(
'If you pause all builds, work will halt once the current steps '.
'complete. You can resume the builds later.');
} else {
return pht(
'You can only pause some builds. Once the current steps complete, '.
'work will halt on builds you can pause. You can resume the builds '.
'later.');
}
}
public function getTitle() {
return pht(
'%s paused this build.',
$this->renderAuthor());
}
public function getIcon() {
return 'fa-pause';
}
public function getColor() {
return 'red';
}
public function applyInternalEffects($object, $value) {
$actor = $this->getActor();
$build = $object;
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_PAUSED);
}
protected function newCanApplyMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
if ($build->isAutobuild()) {
throw new HarbormasterMessageException(
pht('Unable to Pause Build'),
pht('You can not pause a build that uses an autoplan.'));
}
if ($build->isPaused()) {
throw new HarbormasterMessageException(
pht('Unable to Pause Build'),
pht('You can not pause this build because it is already paused.'));
}
if ($build->isComplete()) {
throw new HarbormasterMessageException(
pht('Unable to Pause Build'),
pht('You can not pause this build because it has already completed.'));
}
}
protected function newCanSendMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
if ($build->isPausing()) {
throw new HarbormasterMessageException(
pht('Unable to Pause Build'),
pht('You can not pause this build because it is already pausing.'));
}
if ($build->isRestarting()) {
throw new HarbormasterMessageException(
pht('Unable to Pause Build'),
pht('You can not pause this build because it is already restarting.'));
}
if ($build->isAborting()) {
throw new HarbormasterMessageException(
pht('Unable to Pause Build'),
pht('You can not pause this build because it is already aborting.'));
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageAbortTransaction.php | src/applications/harbormaster/xaction/build/HarbormasterBuildMessageAbortTransaction.php | <?php
final class HarbormasterBuildMessageAbortTransaction
extends HarbormasterBuildMessageTransaction {
const TRANSACTIONTYPE = 'message/abort';
const MESSAGETYPE = 'abort';
public function getHarbormasterBuildMessageName() {
return pht('Abort Build');
}
public function getHarbormasterBuildableMessageName() {
return pht('Abort Builds');
}
public function newConfirmPromptTitle() {
return pht('Really abort build?');
}
public function getHarbormasterBuildableMessageEffect() {
return pht('Build will abort.');
}
public function newConfirmPromptBody() {
return pht(
'Progress on this build will be discarded. Really abort build?');
}
public function getHarbormasterBuildMessageDescription() {
return pht('Abort the build, discarding progress.');
}
public function newBuildableConfirmPromptTitle(
array $builds,
array $sendable) {
return pht(
'Really abort %s build(s)?',
phutil_count($builds));
}
public function newBuildableConfirmPromptBody(
array $builds,
array $sendable) {
if (count($sendable) === count($builds)) {
return pht(
'If you abort all builds, work will halt immediately. Work '.
'will be discarded, and builds must be completely restarted.');
} else {
return pht(
'You can only abort some builds. Work will halt immediately on '.
'builds you can abort. Progress will be discarded, and builds must '.
'be completely restarted if you want them to complete.');
}
}
public function getTitle() {
return pht(
'%s aborted this build.',
$this->renderAuthor());
}
public function getIcon() {
return 'fa-exclamation-triangle';
}
public function getColor() {
return 'red';
}
public function applyInternalEffects($object, $value) {
$actor = $this->getActor();
$build = $object;
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_ABORTED);
}
public function applyExternalEffects($object, $value) {
$actor = $this->getActor();
$build = $object;
$build->releaseAllArtifacts($actor);
}
protected function newCanApplyMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
if ($build->isAutobuild()) {
throw new HarbormasterMessageException(
pht('Unable to Abort Build'),
pht(
'You can not abort a build that uses an autoplan.'));
}
if ($build->isComplete()) {
throw new HarbormasterMessageException(
pht('Unable to Abort Build'),
pht(
'You can not abort this biuld because it is already complete.'));
}
}
protected function newCanSendMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
if ($build->isAborting()) {
throw new HarbormasterMessageException(
pht('Unable to Abort Build'),
pht(
'You can not abort this build because it is already aborting.'));
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php | src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php | <?php
abstract class HarbormasterBuildMessageTransaction
extends HarbormasterBuildTransactionType {
final public function getHarbormasterBuildMessageType() {
return $this->getPhobjectClassConstant('MESSAGETYPE');
}
abstract public function getHarbormasterBuildMessageName();
abstract public function getHarbormasterBuildMessageDescription();
abstract public function getHarbormasterBuildableMessageName();
abstract public function getHarbormasterBuildableMessageEffect();
abstract public function newConfirmPromptTitle();
abstract public function newConfirmPromptBody();
abstract public function newBuildableConfirmPromptTitle(
array $builds,
array $sendable);
abstract public function newBuildableConfirmPromptBody(
array $builds,
array $sendable);
public function newBuildableConfirmPromptWarnings(
array $builds,
array $sendable) {
return array();
}
final public function generateOldValue($object) {
return null;
}
final public function getTransactionTypeForConduit($xaction) {
return 'message';
}
final public function getFieldValuesForConduit($xaction, $data) {
return array(
'type' => $xaction->getNewValue(),
);
}
final public static function getAllMessages() {
$message_xactions = id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->execute();
return $message_xactions;
}
final public static function getTransactionObjectForMessageType(
$message_type) {
$message_xactions = self::getAllMessages();
foreach ($message_xactions as $message_xaction) {
$xaction_type = $message_xaction->getHarbormasterBuildMessageType();
if ($xaction_type === $message_type) {
return $message_xaction;
}
}
return null;
}
final public static function getTransactionTypeForMessageType($message_type) {
$message_xaction = self::getTransactionObjectForMessageType($message_type);
if ($message_xaction) {
return $message_xaction->getTransactionTypeConstant();
}
return null;
}
final public function getTransactionHasEffect($object, $old, $new) {
return $this->canApplyMessage($this->getActor(), $object);
}
final public function canApplyMessage(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
try {
$this->assertCanApplyMessage($viewer, $build);
return true;
} catch (HarbormasterMessageException $ex) {
return false;
}
}
final public function canSendMessage(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
try {
$this->assertCanSendMessage($viewer, $build);
return true;
} catch (HarbormasterMessageException $ex) {
return false;
}
}
final public function assertCanApplyMessage(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
$this->newCanApplyMessageAssertion($viewer, $build);
}
final public function assertCanSendMessage(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
$plan = $build->getBuildPlan();
// See T13526. Users without permission to access the build plan can
// currently end up here with no "BuildPlan" object.
if (!$plan) {
throw new HarbormasterMessageException(
pht('No Build Plan Permission'),
pht(
'You can not issue this command because you do not have '.
'permission to access the build plan for this build.'));
}
// Issuing these commands requires that you be able to edit the build, to
// prevent enemy engineers from sabotaging your builds. See T9614.
if (!$plan->canRunWithoutEditCapability()) {
try {
PhabricatorPolicyFilter::requireCapability(
$viewer,
$plan,
PhabricatorPolicyCapability::CAN_EDIT);
} catch (PhabricatorPolicyException $ex) {
throw new HarbormasterMessageException(
pht('Insufficent Build Plan Permission'),
pht(
'The build plan for this build is configured to prevent '.
'users who can not edit it from issuing commands to the '.
'build, and you do not have permission to edit the build '.
'plan.'));
}
}
$this->newCanSendMessageAssertion($viewer, $build);
$this->assertCanApplyMessage($viewer, $build);
}
abstract protected function newCanSendMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build);
abstract protected function newCanApplyMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build);
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageResumeTransaction.php | src/applications/harbormaster/xaction/build/HarbormasterBuildMessageResumeTransaction.php | <?php
final class HarbormasterBuildMessageResumeTransaction
extends HarbormasterBuildMessageTransaction {
const TRANSACTIONTYPE = 'message/resume';
const MESSAGETYPE = 'resume';
public function getHarbormasterBuildMessageName() {
return pht('Resume Build');
}
public function getHarbormasterBuildableMessageName() {
return pht('Resume Builds');
}
public function getHarbormasterBuildableMessageEffect() {
return pht('Build will resume.');
}
public function newConfirmPromptTitle() {
return pht('Really resume build?');
}
public function newConfirmPromptBody() {
return pht(
'Work will continue on the build. Really resume?');
}
public function getHarbormasterBuildMessageDescription() {
return pht('Resume work on a previously paused build.');
}
public function newBuildableConfirmPromptTitle(
array $builds,
array $sendable) {
return pht(
'Really resume %s build(s)?',
phutil_count($builds));
}
public function newBuildableConfirmPromptBody(
array $builds,
array $sendable) {
if (count($sendable) === count($builds)) {
return pht(
'Work will continue on all builds. Really resume?');
} else {
return pht(
'You can only resume some builds. Work will continue on builds '.
'you have permission to resume.');
}
}
public function getTitle() {
return pht(
'%s resumed this build.',
$this->renderAuthor());
}
public function getIcon() {
return 'fa-play';
}
public function applyInternalEffects($object, $value) {
$actor = $this->getActor();
$build = $object;
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING);
}
protected function newCanApplyMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
if ($build->isAutobuild()) {
throw new HarbormasterMessageException(
pht('Unable to Resume Build'),
pht(
'You can not resume a build that uses an autoplan.'));
}
if (!$build->isPaused() && !$build->isPausing()) {
throw new HarbormasterMessageException(
pht('Unable to Resume Build'),
pht(
'You can not resume this build because it is not paused. You can '.
'only resume a paused build.'));
}
}
protected function newCanSendMessageAssertion(
PhabricatorUser $viewer,
HarbormasterBuild $build) {
if ($build->isResuming()) {
throw new HarbormasterMessageException(
pht('Unable to Resume Build'),
pht(
'You can not resume this build beacuse it is already resuming.'));
}
if ($build->isRestarting()) {
throw new HarbormasterMessageException(
pht('Unable to Resume Build'),
pht('You can not resume this build because it is already restarting.'));
}
if ($build->isAborting()) {
throw new HarbormasterMessageException(
pht('Unable to Resume Build'),
pht('You can not resume this build because it is already aborting.'));
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/build/HarbormasterBuildTransactionType.php | src/applications/harbormaster/xaction/build/HarbormasterBuildTransactionType.php | <?php
abstract class HarbormasterBuildTransactionType
extends PhabricatorModularTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/buildable/HarbormasterBuildableMessageTransaction.php | src/applications/harbormaster/xaction/buildable/HarbormasterBuildableMessageTransaction.php | <?php
final class HarbormasterBuildableMessageTransaction
extends HarbormasterBuildableTransactionType {
const TRANSACTIONTYPE = 'harbormaster:buildable:command';
public function generateOldValue($object) {
return null;
}
public function getTitle() {
$new = $this->getNewValue();
switch ($new) {
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
return pht(
'%s restarted this buildable.',
$this->renderAuthor());
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
return pht(
'%s resumed this buildable.',
$this->renderAuthor());
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
return pht(
'%s paused this buildable.',
$this->renderAuthor());
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
return pht(
'%s aborted this buildable.',
$this->renderAuthor());
}
return parent::getTitle();
}
public function getIcon() {
$new = $this->getNewValue();
switch ($new) {
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
return 'fa-backward';
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
return 'fa-play';
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
return 'fa-pause';
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
return 'fa-exclamation-triangle';
}
return parent::getIcon();
}
public function getColor() {
$new = $this->getNewValue();
switch ($new) {
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
return 'red';
}
return parent::getColor();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/xaction/buildable/HarbormasterBuildableTransactionType.php | src/applications/harbormaster/xaction/buildable/HarbormasterBuildableTransactionType.php | <?php
abstract class HarbormasterBuildableTransactionType
extends PhabricatorModularTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/exception/HarbormasterMessageException.php | src/applications/harbormaster/exception/HarbormasterMessageException.php | <?php
final class HarbormasterMessageException extends Exception {
private $title;
private $body = array();
public function __construct($title, $body = null) {
$this->setTitle($title);
$this->appendParagraph($body);
parent::__construct(
pht(
'%s: %s',
$title,
$body));
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function getTitle() {
return $this->title;
}
public function appendParagraph($description) {
$this->body[] = $description;
return $this;
}
public function getBody() {
return $this->body;
}
public function newDisplayString() {
$title = $this->getTitle();
$body = $this->getBody();
$body = implode("\n\n", $body);
return pht('%s: %s', $title, $body);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/exception/HarbormasterBuildFailureException.php | src/applications/harbormaster/exception/HarbormasterBuildFailureException.php | <?php
final class HarbormasterBuildFailureException extends Exception {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/exception/HarbormasterBuildAbortedException.php | src/applications/harbormaster/exception/HarbormasterBuildAbortedException.php | <?php
final class HarbormasterBuildAbortedException extends Exception {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php | src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php | <?php
final class PhabricatorHarbormasterApplication extends PhabricatorApplication {
public function getBaseURI() {
return '/harbormaster/';
}
public function getName() {
return pht('Harbormaster');
}
public function getShortDescription() {
return pht('Build/CI');
}
public function getIcon() {
return 'fa-ship';
}
public function getTitleGlyph() {
return "\xE2\x99\xBB";
}
public function getFlavorText() {
return pht('Ship Some Freight');
}
public function getApplicationGroup() {
return self::GROUP_UTILITIES;
}
public function getEventListeners() {
return array(
new HarbormasterUIEventListener(),
);
}
public function getRemarkupRules() {
return array(
new HarbormasterRemarkupRule(),
);
}
public function getHelpDocumentationArticles(PhabricatorUser $viewer) {
return array(
array(
'name' => pht('Harbormaster User Guide'),
'href' => PhabricatorEnv::getDoclink('Harbormaster User Guide'),
),
);
}
public function getRoutes() {
return array(
'/B(?P<id>[1-9]\d*)' => 'HarbormasterBuildableViewController',
'/harbormaster/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'HarbormasterBuildableListController',
'step/' => array(
'add/(?:(?P<id>\d+)/)?' => 'HarbormasterStepAddController',
'new/(?P<plan>\d+)/(?P<class>[^/]+)/'
=> 'HarbormasterStepEditController',
'view/(?P<id>\d+)/' => 'HarbormasterStepViewController',
'edit/(?:(?P<id>\d+)/)?' => 'HarbormasterStepEditController',
'delete/(?:(?P<id>\d+)/)?' => 'HarbormasterStepDeleteController',
),
'buildable/' => array(
'(?P<id>\d+)/(?P<action>pause|resume|restart|abort)/'
=> 'HarbormasterBuildableActionController',
),
'build/' => array(
$this->getQueryRoutePattern() => 'HarbormasterBuildListController',
'(?P<id>\d+)/(?:(?P<generation>\d+)/)?'
=> 'HarbormasterBuildViewController',
'(?P<action>pause|resume|restart|abort)/'.
'(?P<id>\d+)/(?:(?P<via>[^/]+)/)?'
=> 'HarbormasterBuildActionController',
),
'plan/' => array(
$this->getQueryRoutePattern() => 'HarbormasterPlanListController',
$this->getEditRoutePattern('edit/')
=> 'HarbormasterPlanEditController',
'disable/(?P<id>\d+)/' => 'HarbormasterPlanDisableController',
'behavior/(?P<id>\d+)/(?P<behaviorKey>[^/]+)/' =>
'HarbormasterPlanBehaviorController',
'run/(?P<id>\d+)/' => 'HarbormasterPlanRunController',
'(?P<id>\d+)/' => 'HarbormasterPlanViewController',
),
'unit/' => array(
'(?P<id>\d+)/' => 'HarbormasterUnitMessageListController',
'view/(?P<id>\d+)/' => 'HarbormasterUnitMessageViewController',
),
'lint/' => array(
'(?P<id>\d+)/' => 'HarbormasterLintMessagesController',
),
'hook/' => array(
'circleci/' => 'HarbormasterCircleCIHookController',
'buildkite/' => 'HarbormasterBuildkiteHookController',
),
'log/' => array(
'view/(?P<id>\d+)/(?:\$(?P<lines>\d+(?:-\d+)?))?'
=> 'HarbormasterBuildLogViewController',
'render/(?P<id>\d+)/(?:\$(?P<lines>\d+(?:-\d+)?))?'
=> 'HarbormasterBuildLogRenderController',
'download/(?P<id>\d+)/' => 'HarbormasterBuildLogDownloadController',
),
),
);
}
protected function getCustomCapabilities() {
return array(
HarbormasterCreatePlansCapability::CAPABILITY => array(
'default' => PhabricatorPolicies::POLICY_ADMIN,
),
HarbormasterBuildPlanDefaultViewCapability::CAPABILITY => array(
'template' => HarbormasterBuildPlanPHIDType::TYPECONST,
'capability' => PhabricatorPolicyCapability::CAN_VIEW,
),
HarbormasterBuildPlanDefaultEditCapability::CAPABILITY => array(
'template' => HarbormasterBuildPlanPHIDType::TYPECONST,
'capability' => PhabricatorPolicyCapability::CAN_EDIT,
'default' => PhabricatorPolicies::POLICY_ADMIN,
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/__tests__/HarbormasterBuildLogTestCase.php | src/applications/harbormaster/__tests__/HarbormasterBuildLogTestCase.php | <?php
final class HarbormasterBuildLogTestCase
extends PhabricatorTestCase {
public function testBuildLogLineMaps() {
$snowman = "\xE2\x98\x83";
$inputs = array(
'no_newlines.log' => array(
64,
array(
str_repeat('AAAAAAAA', 32),
),
array(
array(64, 0),
array(128, 0),
array(192, 0),
array(255, 0),
),
),
'no_newlines_updated.log' => array(
64,
array_fill(0, 32, 'AAAAAAAA'),
array(
array(64, 0),
array(128, 0),
array(192, 0),
),
),
'one_newline.log' => array(
64,
array(
str_repeat('AAAAAAAA', 16),
"\n",
str_repeat('AAAAAAAA', 16),
),
array(
array(64, 0),
array(127, 0),
array(191, 1),
array(255, 1),
),
),
'several_newlines.log' => array(
64,
array_fill(0, 12, "AAAAAAAAAAAAAAAAAA\n"),
array(
array(56, 2),
array(113, 5),
array(170, 8),
array(227, 11),
),
),
'mixed_newlines.log' => array(
64,
array(
str_repeat('A', 63)."\r",
str_repeat('A', 63)."\r\n",
str_repeat('A', 63)."\n",
str_repeat('A', 63),
),
array(
array(63, 0),
array(127, 1),
array(191, 2),
array(255, 3),
),
),
'more_mixed_newlines.log' => array(
64,
array(
str_repeat('A', 63)."\r",
str_repeat('A', 62)."\r\n",
str_repeat('A', 63)."\n",
str_repeat('A', 63),
),
array(
array(63, 0),
array(128, 2),
array(191, 2),
array(254, 3),
),
),
'emoji.log' => array(
64,
array(
str_repeat($snowman, 64),
),
array(
array(63, 0),
array(126, 0),
array(189, 0),
),
),
);
foreach ($inputs as $label => $input) {
list($distance, $parts, $expect) = $input;
$log = id(new HarbormasterBuildLog())
->setByteLength(0);
foreach ($parts as $part) {
$log->updateLineMap($part, $distance);
}
list($actual) = $log->getLineMap();
$this->assertEqual(
$expect,
$actual,
pht('Line Map for "%s"', $label));
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/__tests__/HarbormasterAutotargetsTestCase.php | src/applications/harbormaster/__tests__/HarbormasterAutotargetsTestCase.php | <?php
final class HarbormasterAutotargetsTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testGenerateHarbormasterAutotargets() {
$viewer = $this->generateNewTestUser();
$raw_diff = <<<EODIFF
diff --git a/fruit b/fruit
new file mode 100644
index 0000000..1c0f49d
--- /dev/null
+++ b/fruit
@@ -0,0 +1,2 @@
+apal
+banan
EODIFF;
$parser = new ArcanistDiffParser();
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($viewer, $changes)
->setLintStatus(DifferentialLintStatus::LINT_AUTO_SKIP)
->setUnitStatus(DifferentialUnitStatus::UNIT_AUTO_SKIP)
->attachRevision(null)
->save();
$params = array(
'objectPHID' => $diff->getPHID(),
'targetKeys' => array(
HarbormasterArcLintBuildStepImplementation::STEPKEY,
HarbormasterArcUnitBuildStepImplementation::STEPKEY,
),
);
// Creation of autotargets should work from an empty state.
$result = id(new ConduitCall('harbormaster.queryautotargets', $params))
->setUser($viewer)
->execute();
$targets = idx($result, 'targetMap');
foreach ($params['targetKeys'] as $target_key) {
$this->assertTrue((bool)$result['targetMap'][$target_key]);
}
// Querying the same autotargets again should produce the same results,
// not make new ones.
$retry = id(new ConduitCall('harbormaster.queryautotargets', $params))
->setUser($viewer)
->execute();
$this->assertEqual($result, $retry);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/artifact/HarbormasterURIArtifact.php | src/applications/harbormaster/artifact/HarbormasterURIArtifact.php | <?php
final class HarbormasterURIArtifact extends HarbormasterArtifact {
const ARTIFACTCONST = 'uri';
public function getArtifactTypeName() {
return pht('URI');
}
public function getArtifactTypeSummary() {
return pht('Stores a URI.');
}
public function getArtifactTypeDescription() {
return pht(
"Stores a URI.\n\n".
"With `ui.external`, you can use this artifact type to add links to ".
"build results in an external build system.");
}
public function getArtifactParameterSpecification() {
return array(
'uri' => 'string',
'name' => 'optional string',
'ui.external' => 'optional bool',
);
}
public function readArtifactHTTPParameter($key, $value) {
// TODO: This is hacky and artifact parameters should be replaced more
// broadly, likely with EditFields. See T11887.
switch ($key) {
case 'ui.external':
return (bool)$value;
}
return $value;
}
public function getArtifactParameterDescriptions() {
return array(
'uri' => pht('The URI to store.'),
'name' => pht('Optional label for this URI.'),
'ui.external' => pht(
'If true, display this URI in the UI as an link to '.
'additional build details in an external build system.'),
);
}
public function getArtifactDataExample() {
return array(
'uri' => 'https://buildserver.mycompany.com/build/123/',
'name' => pht('View External Build Results'),
'ui.external' => true,
);
}
public function renderArtifactSummary(PhabricatorUser $viewer) {
return $this->renderLink();
}
public function isExternalLink() {
$artifact = $this->getBuildArtifact();
return (bool)$artifact->getProperty('ui.external', false);
}
public function renderLink() {
$artifact = $this->getBuildArtifact();
$uri = $artifact->getProperty('uri');
try {
$this->validateURI($uri);
} catch (Exception $ex) {
return pht('<Invalid URI>');
}
$name = $artifact->getProperty('name', $uri);
return phutil_tag(
'a',
array(
'href' => $uri,
'target' => '_blank',
'rel' => 'noreferrer',
),
$name);
}
public function willCreateArtifact(PhabricatorUser $actor) {
$artifact = $this->getBuildArtifact();
$uri = $artifact->getProperty('uri');
$this->validateURI($uri);
}
private function validateURI($raw_uri) {
$uri = new PhutilURI($raw_uri);
$protocol = $uri->getProtocol();
if (!strlen($protocol)) {
throw new Exception(
pht(
'Unable to identify the protocol for URI "%s". URIs must be '.
'fully qualified and have an identifiable protocol.',
$raw_uri));
}
$protocol_key = 'uri.allowed-protocols';
$protocols = PhabricatorEnv::getEnvConfig($protocol_key);
if (empty($protocols[$protocol])) {
throw new Exception(
pht(
'URI "%s" does not have an allowable protocol. Configure '.
'protocols in `%s`. Allowed protocols are: %s.',
$raw_uri,
$protocol_key,
implode(', ', array_keys($protocols))));
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/artifact/HarbormasterFileArtifact.php | src/applications/harbormaster/artifact/HarbormasterFileArtifact.php | <?php
final class HarbormasterFileArtifact extends HarbormasterArtifact {
const ARTIFACTCONST = 'file';
public function getArtifactTypeName() {
return pht('File');
}
public function getArtifactTypeDescription() {
return pht(
'Stores a reference to file data.');
}
public function getArtifactParameterSpecification() {
return array(
'filePHID' => 'string',
);
}
public function getArtifactParameterDescriptions() {
return array(
'filePHID' => pht('File to create an artifact from.'),
);
}
public function getArtifactDataExample() {
return array(
'filePHID' => 'PHID-FILE-abcdefghijklmnopqrst',
);
}
public function renderArtifactSummary(PhabricatorUser $viewer) {
$artifact = $this->getBuildArtifact();
$file_phid = $artifact->getProperty('filePHID');
return $viewer->renderHandle($file_phid);
}
public function willCreateArtifact(PhabricatorUser $actor) {
// NOTE: This is primarily making sure the actor has permission to view the
// file. We don't want to let you run builds using files you don't have
// permission to see, since this could let you violate permissions.
$this->loadArtifactFile($actor);
}
public function loadArtifactFile(PhabricatorUser $viewer) {
$artifact = $this->getBuildArtifact();
$file_phid = $artifact->getProperty('filePHID');
$file = id(new PhabricatorFileQuery())
->setViewer($viewer)
->withPHIDs(array($file_phid))
->executeOne();
if (!$file) {
throw new Exception(
pht(
'File PHID "%s" does not correspond to a valid file.',
$file_phid));
}
return $file;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/artifact/HarbormasterWorkingCopyArtifact.php | src/applications/harbormaster/artifact/HarbormasterWorkingCopyArtifact.php | <?php
final class HarbormasterWorkingCopyArtifact
extends HarbormasterDrydockLeaseArtifact {
const ARTIFACTCONST = 'working-copy';
public function getArtifactTypeName() {
return pht('Drydock Working Copy');
}
public function getArtifactTypeDescription() {
return pht('References a working copy lease from Drydock.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/artifact/HarbormasterArtifact.php | src/applications/harbormaster/artifact/HarbormasterArtifact.php | <?php
abstract class HarbormasterArtifact extends Phobject {
private $buildArtifact;
abstract public function getArtifactTypeName();
public function getArtifactTypeSummary() {
return $this->getArtifactTypeDescription();
}
abstract public function getArtifactTypeDescription();
abstract public function getArtifactParameterSpecification();
abstract public function getArtifactParameterDescriptions();
abstract public function willCreateArtifact(PhabricatorUser $actor);
public function readArtifactHTTPParameter($key, $value) {
return $value;
}
public function validateArtifactData(array $artifact_data) {
$artifact_spec = $this->getArtifactParameterSpecification();
PhutilTypeSpec::checkMap($artifact_data, $artifact_spec);
}
public function renderArtifactSummary(PhabricatorUser $viewer) {
return null;
}
public function releaseArtifact(PhabricatorUser $actor) {
return;
}
public function getArtifactDataExample() {
return null;
}
public function setBuildArtifact(HarbormasterBuildArtifact $build_artifact) {
$this->buildArtifact = $build_artifact;
return $this;
}
public function getBuildArtifact() {
return $this->buildArtifact;
}
final public function getArtifactConstant() {
return $this->getPhobjectClassConstant('ARTIFACTCONST', 32);
}
final public static function getAllArtifactTypes() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getArtifactConstant')
->execute();
}
final public static function getArtifactType($type) {
return idx(self::getAllArtifactTypes(), $type);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/artifact/HarbormasterDrydockLeaseArtifact.php | src/applications/harbormaster/artifact/HarbormasterDrydockLeaseArtifact.php | <?php
abstract class HarbormasterDrydockLeaseArtifact
extends HarbormasterArtifact {
public function getArtifactParameterSpecification() {
return array(
'drydockLeasePHID' => 'string',
);
}
public function getArtifactParameterDescriptions() {
return array(
'drydockLeasePHID' => pht(
'Drydock working copy lease to create an artifact from.'),
);
}
public function getArtifactDataExample() {
return array(
'drydockLeasePHID' => 'PHID-DRYL-abcdefghijklmnopqrst',
);
}
public function renderArtifactSummary(PhabricatorUser $viewer) {
$artifact = $this->getBuildArtifact();
$lease_phid = $artifact->getProperty('drydockLeasePHID');
return $viewer->renderHandle($lease_phid);
}
public function willCreateArtifact(PhabricatorUser $actor) {
// We don't load the lease here because it's expected that artifacts are
// created before leases actually exist. This guarantees that the leases
// will be cleaned up.
}
public function loadArtifactLease(PhabricatorUser $viewer) {
$artifact = $this->getBuildArtifact();
$lease_phid = $artifact->getProperty('drydockLeasePHID');
$lease = id(new DrydockLeaseQuery())
->setViewer($viewer)
->withPHIDs(array($lease_phid))
->executeOne();
if (!$lease) {
throw new Exception(
pht(
'Drydock lease PHID "%s" does not correspond to a valid lease.',
$lease_phid));
}
return $lease;
}
public function releaseArtifact(PhabricatorUser $actor) {
try {
$lease = $this->loadArtifactLease($actor);
} catch (Exception $ex) {
// If we can't load the lease, treat it as already released. Artifacts
// are generated before leases are queued, so it's possible to arrive
// here under normal conditions.
return;
}
if (!$lease->canRelease()) {
return;
}
$author_phid = $actor->getPHID();
if (!$author_phid) {
$author_phid = id(new PhabricatorHarbormasterApplication())->getPHID();
}
$command = DrydockCommand::initializeNewCommand($actor)
->setTargetPHID($lease->getPHID())
->setAuthorPHID($author_phid)
->setCommand(DrydockCommand::COMMAND_RELEASE)
->save();
$lease->scheduleUpdate();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/artifact/HarbormasterHostArtifact.php | src/applications/harbormaster/artifact/HarbormasterHostArtifact.php | <?php
final class HarbormasterHostArtifact
extends HarbormasterDrydockLeaseArtifact {
const ARTIFACTCONST = 'host';
public function getArtifactTypeName() {
return pht('Drydock Host');
}
public function getArtifactTypeDescription() {
return pht('References a host lease from Drydock.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterArcLintBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterArcLintBuildStepImplementation.php | <?php
final class HarbormasterArcLintBuildStepImplementation
extends HarbormasterBuildStepImplementation {
const STEPKEY = 'arcanist.lint';
public function getBuildStepAutotargetPlanKey() {
return HarbormasterBuildArcanistAutoplan::PLANKEY;
}
public function getBuildStepAutotargetStepKey() {
return self::STEPKEY;
}
public function shouldRequireAutotargeting() {
return true;
}
public function getName() {
return pht('Arcanist Lint Results');
}
public function getGenericDescription() {
return pht('Automatic `arc lint` step.');
}
public function getBuildStepGroupKey() {
return HarbormasterBuiltinBuildStepGroup::GROUPKEY;
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
return;
}
public function shouldWaitForMessage(HarbormasterBuildTarget $target) {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterThrowExceptionBuildStep.php | src/applications/harbormaster/step/HarbormasterThrowExceptionBuildStep.php | <?php
final class HarbormasterThrowExceptionBuildStep
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Throw Exception');
}
public function getGenericDescription() {
return pht('Throw an exception.');
}
public function getBuildStepGroupKey() {
return HarbormasterTestBuildStepGroup::GROUPKEY;
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
throw new Exception(pht('(This is an explicit exception.)'));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php | <?php
final class HarbormasterWaitForPreviousBuildStepImplementation
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Wait for Previous Commits to Build');
}
public function getGenericDescription() {
return pht(
'Wait for previous commits to finish building the current plan '.
'before continuing.');
}
public function getBuildStepGroupKey() {
return HarbormasterControlBuildStepGroup::GROUPKEY;
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
// We can only wait when building against commits.
$buildable = $build->getBuildable();
$object = $buildable->getBuildableObject();
if (!($object instanceof PhabricatorRepositoryCommit)) {
return;
}
// Block until all previous builds of the same build plan have
// finished.
$plan = $build->getBuildPlan();
$blockers = $this->getBlockers($object, $plan, $build);
if ($blockers) {
throw new PhabricatorWorkerYieldException(15);
}
}
private function getBlockers(
PhabricatorRepositoryCommit $commit,
HarbormasterBuildPlan $plan,
HarbormasterBuild $source) {
$call = new ConduitCall(
'diffusion.commitparentsquery',
array(
'commit' => $commit->getCommitIdentifier(),
'repository' => $commit->getRepository()->getPHID(),
));
$call->setUser(PhabricatorUser::getOmnipotentUser());
$parents = $call->execute();
$parents = id(new DiffusionCommitQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withRepository($commit->getRepository())
->withIdentifiers($parents)
->execute();
$blockers = array();
$build_objects = array();
foreach ($parents as $parent) {
if (!$parent->isImported()) {
$blockers[] = pht('Commit %s', $parent->getCommitIdentifier());
} else {
$build_objects[] = $parent->getPHID();
}
}
if ($build_objects) {
$buildables = id(new HarbormasterBuildableQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withBuildablePHIDs($build_objects)
->withManualBuildables(false)
->execute();
$buildable_phids = mpull($buildables, 'getPHID');
if ($buildable_phids) {
$builds = id(new HarbormasterBuildQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withBuildablePHIDs($buildable_phids)
->withBuildPlanPHIDs(array($plan->getPHID()))
->execute();
foreach ($builds as $build) {
if (!$build->isComplete()) {
$blockers[] = pht('Build %d', $build->getID());
}
}
}
}
return $blockers;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php | <?php
final class HarbormasterBuildkiteBuildStepImplementation
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Build with Buildkite');
}
public function getGenericDescription() {
return pht('Trigger a build in Buildkite.');
}
public function getBuildStepGroupKey() {
return HarbormasterExternalBuildStepGroup::GROUPKEY;
}
public function getDescription() {
return pht('Run a build in Buildkite.');
}
public function getEditInstructions() {
$hook_uri = '/harbormaster/hook/buildkite/';
$hook_uri = PhabricatorEnv::getProductionURI($hook_uri);
return pht(<<<EOTEXT
WARNING: This build step is new and experimental!
To build **revisions** with Buildkite, they must:
- belong to a tracked repository;
- the repository must have a Staging Area configured;
- you must configure a Buildkite pipeline for that Staging Area; and
- you must configure the webhook described below.
To build **commits** with Buildkite, they must:
- belong to a tracked repository;
- you must configure a Buildkite pipeline for that repository; and
- you must configure the webhook described below.
Webhook Configuration
=====================
In {nav Settings} for your Organization in Buildkite, under
{nav Notification Services}, add a new **Webook Notification**.
Use these settings:
- **Webhook URL**: %s
- **Token**: The "Webhook Token" field below and the "Token" field in
Buildkite should both be set to the same nonempty value (any random
secret). You can use copy/paste the value Buildkite generates into
this form.
- **Events**: Only **build.finish** needs to be active.
Environment
===========
These variables will be available in the build environment:
| Variable | Description |
|----------|-------------|
| `HARBORMASTER_BUILD_TARGET_PHID` | PHID of the Build Target.
EOTEXT
,
$hook_uri);
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
$this->logSilencedCall($build, $build_target, pht('Buildkite'));
throw new HarbormasterBuildFailureException();
}
$buildable = $build->getBuildable();
$object = $buildable->getBuildableObject();
if (!($object instanceof HarbormasterBuildkiteBuildableInterface)) {
throw new Exception(
pht('This object does not support builds with Buildkite.'));
}
$organization = $this->getSetting('organization');
$pipeline = $this->getSetting('pipeline');
$uri = urisprintf(
'https://api.buildkite.com/v2/organizations/%s/pipelines/%s/builds',
$organization,
$pipeline);
$data_structure = array(
'commit' => $object->getBuildkiteCommit(),
'branch' => $object->getBuildkiteBranch(),
'message' => pht(
'Harbormaster Build %s ("%s") for %s',
$build->getID(),
$build->getName(),
$buildable->getMonogram()),
'env' => array(
'HARBORMASTER_BUILD_TARGET_PHID' => $build_target->getPHID(),
),
'meta_data' => array(
'buildTargetPHID' => $build_target->getPHID(),
// See PHI611. These are undocumented secret magic.
'phabricator:build:id' => (int)$build->getID(),
'phabricator:build:url' =>
PhabricatorEnv::getProductionURI($build->getURI()),
'phabricator:buildable:id' => (int)$buildable->getID(),
'phabricator:buildable:url' =>
PhabricatorEnv::getProductionURI($buildable->getURI()),
),
);
$engine = HarbormasterBuildableEngine::newForObject(
$object,
$viewer);
$author_identity = $engine->getAuthorIdentity();
if ($author_identity) {
$data_structure += array(
'author' => array(
'name' => $author_identity->getIdentityDisplayName(),
'email' => $author_identity->getIdentityEmailAddress(),
),
);
}
$json_data = phutil_json_encode($data_structure);
$credential_phid = $this->getSetting('token');
$api_token = id(new PassphraseCredentialQuery())
->setViewer($viewer)
->withPHIDs(array($credential_phid))
->needSecrets(true)
->executeOne();
if (!$api_token) {
throw new Exception(
pht(
'Unable to load API token ("%s")!',
$credential_phid));
}
$token = $api_token->getSecret()->openEnvelope();
$future = id(new HTTPSFuture($uri, $json_data))
->setMethod('POST')
->addHeader('Content-Type', 'application/json')
->addHeader('Accept', 'application/json')
->addHeader('Authorization', "Bearer {$token}")
->setTimeout(60);
$this->resolveFutures(
$build,
$build_target,
array($future));
$this->logHTTPResponse($build, $build_target, $future, pht('Buildkite'));
list($status, $body) = $future->resolve();
if ($status->isError()) {
throw new HarbormasterBuildFailureException();
}
$response = phutil_json_decode($body);
$uri_key = 'web_url';
$build_uri = idx($response, $uri_key);
if (!$build_uri) {
throw new Exception(
pht(
'Buildkite did not return a "%s"!',
$uri_key));
}
$target_phid = $build_target->getPHID();
$api_method = 'harbormaster.createartifact';
$api_params = array(
'buildTargetPHID' => $target_phid,
'artifactType' => HarbormasterURIArtifact::ARTIFACTCONST,
'artifactKey' => 'buildkite.uri',
'artifactData' => array(
'uri' => $build_uri,
'name' => pht('View in Buildkite'),
'ui.external' => true,
),
);
id(new ConduitCall($api_method, $api_params))
->setUser($viewer)
->execute();
}
public function getFieldSpecifications() {
return array(
'token' => array(
'name' => pht('API Token'),
'type' => 'credential',
'credential.type'
=> PassphraseTokenCredentialType::CREDENTIAL_TYPE,
'credential.provides'
=> PassphraseTokenCredentialType::PROVIDES_TYPE,
'required' => true,
),
'organization' => array(
'name' => pht('Organization Name'),
'type' => 'text',
'required' => true,
),
'pipeline' => array(
'name' => pht('Pipeline Name'),
'type' => 'text',
'required' => true,
),
'webhook.token' => array(
'name' => pht('Webhook Token'),
'type' => 'text',
'required' => true,
),
);
}
public function supportsWaitForMessage() {
return false;
}
public function shouldWaitForMessage(HarbormasterBuildTarget $target) {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterHTTPRequestBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterHTTPRequestBuildStepImplementation.php | <?php
final class HarbormasterHTTPRequestBuildStepImplementation
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Make HTTP Request');
}
public function getGenericDescription() {
return pht('Make an HTTP request.');
}
public function getBuildStepGroupKey() {
return HarbormasterExternalBuildStepGroup::GROUPKEY;
}
public function getDescription() {
$domain = null;
$uri = $this->getSetting('uri');
if ($uri) {
$domain = id(new PhutilURI($uri))->getDomain();
}
$method = $this->formatSettingForDescription('method', 'POST');
$domain = $this->formatValueForDescription($domain);
if ($this->getSetting('credential')) {
return pht(
'Make an authenticated HTTP %s request to %s.',
$method,
$domain);
} else {
return pht(
'Make an HTTP %s request to %s.',
$method,
$domain);
}
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
$this->logSilencedCall($build, $build_target, pht('HTTP Request'));
throw new HarbormasterBuildFailureException();
}
$settings = $this->getSettings();
$variables = $build_target->getVariables();
$uri = $this->mergeVariables(
'vurisprintf',
$settings['uri'],
$variables);
$method = nonempty(idx($settings, 'method'), 'POST');
$future = id(new HTTPSFuture($uri))
->setMethod($method)
->setTimeout(60);
$credential_phid = $this->getSetting('credential');
if ($credential_phid) {
$key = PassphrasePasswordKey::loadFromPHID(
$credential_phid,
$viewer);
$future->setHTTPBasicAuthCredentials(
$key->getUsernameEnvelope()->openEnvelope(),
$key->getPasswordEnvelope());
}
$this->resolveFutures(
$build,
$build_target,
array($future));
$this->logHTTPResponse($build, $build_target, $future, $uri);
list($status) = $future->resolve();
if ($status->isError()) {
throw new HarbormasterBuildFailureException();
}
}
public function getFieldSpecifications() {
return array(
'uri' => array(
'name' => pht('URI'),
'type' => 'text',
'required' => true,
),
'method' => array(
'name' => pht('HTTP Method'),
'type' => 'select',
'options' => array_fuse(array('POST', 'GET', 'PUT', 'DELETE')),
),
'credential' => array(
'name' => pht('Credentials'),
'type' => 'credential',
'credential.type'
=> PassphrasePasswordCredentialType::CREDENTIAL_TYPE,
'credential.provides'
=> PassphrasePasswordCredentialType::PROVIDES_TYPE,
),
);
}
public function supportsWaitForMessage() {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterAbortOlderBuildsBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterAbortOlderBuildsBuildStepImplementation.php | <?php
final class HarbormasterAbortOlderBuildsBuildStepImplementation
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Abort Older Builds');
}
public function getGenericDescription() {
return pht(
'When building a revision, abort copies of this build plan which are '.
'currently running against older diffs.');
}
public function getBuildStepGroupKey() {
return HarbormasterControlBuildStepGroup::GROUPKEY;
}
public function getEditInstructions() {
return pht(<<<EOTEXT
When run against a revision, this build step will abort any older copies of
the same build plan which are currently running against older diffs.
There are some nuances to the behavior:
- if this build step is triggered manually, it won't abort anything;
- this build step won't abort manual builds;
- this build step won't abort anything if the diff it is building isn't
the active diff when it runs.
Build results on outdated diffs often aren't very important, so this may
reduce build queue load without any substantial cost.
EOTEXT
);
}
public function willStartBuild(
PhabricatorUser $viewer,
HarbormasterBuildable $buildable,
HarbormasterBuild $build,
HarbormasterBuildPlan $plan,
HarbormasterBuildStep $step) {
if ($buildable->getIsManualBuildable()) {
// Don't abort anything if this is a manual buildable.
return;
}
$object_phid = $buildable->getBuildablePHID();
if (phid_get_type($object_phid) !== DifferentialDiffPHIDType::TYPECONST) {
// If this buildable isn't building a diff, bail out. For example, we
// might be building a commit. In this case, this step has no effect.
return;
}
$diff = id(new DifferentialDiffQuery())
->setViewer($viewer)
->withPHIDs(array($object_phid))
->executeOne();
if (!$diff) {
return;
}
$revision_id = $diff->getRevisionID();
$revision = id(new DifferentialRevisionQuery())
->setViewer($viewer)
->withIDs(array($revision_id))
->executeOne();
if (!$revision) {
return;
}
$active_phid = $revision->getActiveDiffPHID();
if ($active_phid !== $object_phid) {
// If we aren't building the active diff, bail out.
return;
}
$diffs = id(new DifferentialDiffQuery())
->setViewer($viewer)
->withRevisionIDs(array($revision_id))
->execute();
$abort_diff_phids = array();
foreach ($diffs as $diff) {
if ($diff->getPHID() !== $active_phid) {
$abort_diff_phids[] = $diff->getPHID();
}
}
if (!$abort_diff_phids) {
return;
}
// We're fetching buildables even if they have "passed" or "failed"
// because they may still have ongoing builds. At the time of writing
// only "failed" buildables may still be ongoing, but it seems likely that
// "passed" buildables may be ongoing in the future.
$abort_buildables = id(new HarbormasterBuildableQuery())
->setViewer($viewer)
->withBuildablePHIDs($abort_diff_phids)
->withManualBuildables(false)
->execute();
if (!$abort_buildables) {
return;
}
$statuses = HarbormasterBuildStatus::getIncompleteStatusConstants();
$abort_builds = id(new HarbormasterBuildQuery())
->setViewer($viewer)
->withBuildablePHIDs(mpull($abort_buildables, 'getPHID'))
->withBuildPlanPHIDs(array($plan->getPHID()))
->withBuildStatuses($statuses)
->execute();
if (!$abort_builds) {
return;
}
foreach ($abort_builds as $abort_build) {
$abort_build->sendMessage(
$viewer,
HarbormasterBuildMessageAbortTransaction::MESSAGETYPE);
}
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
return;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterLeaseWorkingCopyBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterLeaseWorkingCopyBuildStepImplementation.php | <?php
final class HarbormasterLeaseWorkingCopyBuildStepImplementation
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Lease Working Copy');
}
public function getGenericDescription() {
return pht('Build a working copy in Drydock.');
}
public function getBuildStepGroupKey() {
return HarbormasterDrydockBuildStepGroup::GROUPKEY;
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
$settings = $this->getSettings();
// TODO: We should probably have a separate temporary storage area for
// execution stuff that doesn't step on configuration state?
$lease_phid = $build_target->getDetail('exec.leasePHID');
if ($lease_phid) {
$lease = id(new DrydockLeaseQuery())
->setViewer($viewer)
->withPHIDs(array($lease_phid))
->executeOne();
if (!$lease) {
throw new PhabricatorWorkerPermanentFailureException(
pht(
'Lease "%s" could not be loaded.',
$lease_phid));
}
} else {
$working_copy_type = id(new DrydockWorkingCopyBlueprintImplementation())
->getType();
$allowed_phids = $build_target->getFieldValue('blueprintPHIDs');
if (!is_array($allowed_phids)) {
$allowed_phids = array();
}
$authorizing_phid = $build_target->getBuildStep()->getPHID();
$lease = DrydockLease::initializeNewLease()
->setResourceType($working_copy_type)
->setOwnerPHID($build_target->getPHID())
->setAuthorizingPHID($authorizing_phid)
->setAllowedBlueprintPHIDs($allowed_phids);
$map = $this->buildRepositoryMap($build_target);
$lease->setAttribute('repositories.map', $map);
$task_id = $this->getCurrentWorkerTaskID();
if ($task_id) {
$lease->setAwakenTaskIDs(array($task_id));
}
// TODO: Maybe add a method to mark artifacts like this as pending?
// Create the artifact now so that the lease is always disposed of, even
// if this target is aborted.
$build_target->createArtifact(
$viewer,
$settings['name'],
HarbormasterWorkingCopyArtifact::ARTIFACTCONST,
array(
'drydockLeasePHID' => $lease->getPHID(),
));
$lease->queueForActivation();
$build_target
->setDetail('exec.leasePHID', $lease->getPHID())
->save();
}
if ($lease->isActivating()) {
// TODO: Smart backoff?
throw new PhabricatorWorkerYieldException(15);
}
if (!$lease->isActive()) {
// TODO: We could just forget about this lease and retry?
throw new PhabricatorWorkerPermanentFailureException(
pht(
'Lease "%s" never activated.',
$lease->getPHID()));
}
}
public function getArtifactOutputs() {
return array(
array(
'name' => pht('Working Copy'),
'key' => $this->getSetting('name'),
'type' => HarbormasterWorkingCopyArtifact::ARTIFACTCONST,
),
);
}
public function getFieldSpecifications() {
return array(
'name' => array(
'name' => pht('Artifact Name'),
'type' => 'text',
'required' => true,
),
'blueprintPHIDs' => array(
'name' => pht('Use Blueprints'),
'type' => 'blueprints',
'required' => true,
),
'repositoryPHIDs' => array(
'name' => pht('Also Clone'),
'type' => 'datasource',
'datasource.class' => 'DiffusionRepositoryDatasource',
),
);
}
private function buildRepositoryMap(HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
$variables = $build_target->getVariables();
$repository_phid = idx($variables, 'repository.phid');
if (!$repository_phid) {
throw new Exception(
pht(
'Unable to determine how to clone the repository for this '.
'buildable: it is not associated with a tracked repository.'));
}
$also_phids = $build_target->getFieldValue('repositoryPHIDs');
if (!is_array($also_phids)) {
$also_phids = array();
}
$all_phids = $also_phids;
$all_phids[] = $repository_phid;
$repositories = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withPHIDs($all_phids)
->execute();
$repositories = mpull($repositories, null, 'getPHID');
foreach ($all_phids as $phid) {
if (empty($repositories[$phid])) {
throw new PhabricatorWorkerPermanentFailureException(
pht(
'Unable to load repository with PHID "%s".',
$phid));
}
}
$map = array();
foreach ($also_phids as $also_phid) {
$also_repo = $repositories[$also_phid];
$map[$also_repo->getCloneName()] = array(
'phid' => $also_repo->getPHID(),
'branch' => 'master',
);
}
$repository = $repositories[$repository_phid];
$commit = idx($variables, 'buildable.commit');
$ref_uri = idx($variables, 'repository.staging.uri');
$ref_ref = idx($variables, 'repository.staging.ref');
if ($commit) {
$spec = array(
'commit' => $commit,
);
} else if ($ref_uri && $ref_ref) {
$spec = array(
'ref' => array(
'uri' => $ref_uri,
'ref' => $ref_ref,
),
);
} else {
throw new Exception(
pht(
'Unable to determine how to fetch changes: this buildable does not '.
'identify a commit or a staging ref. You may need to configure a '.
'repository staging area.'));
}
$directory = $repository->getCloneName();
$map[$directory] = array(
'phid' => $repository->getPHID(),
'default' => true,
) + $spec;
return $map;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterBuildStepImplementation.php | <?php
/**
* @task autotarget Automatic Targets
*/
abstract class HarbormasterBuildStepImplementation extends Phobject {
private $settings;
private $currentWorkerTaskID;
public function setCurrentWorkerTaskID($id) {
$this->currentWorkerTaskID = $id;
return $this;
}
public function getCurrentWorkerTaskID() {
return $this->currentWorkerTaskID;
}
public static function getImplementations() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->execute();
}
public static function getImplementation($class) {
$base = idx(self::getImplementations(), $class);
if ($base) {
return (clone $base);
}
return null;
}
public static function requireImplementation($class) {
if (!$class) {
throw new Exception(pht('No implementation is specified!'));
}
$implementation = self::getImplementation($class);
if (!$implementation) {
throw new Exception(pht('No such implementation "%s" exists!', $class));
}
return $implementation;
}
/**
* The name of the implementation.
*/
abstract public function getName();
public function getBuildStepGroupKey() {
return HarbormasterOtherBuildStepGroup::GROUPKEY;
}
/**
* The generic description of the implementation.
*/
public function getGenericDescription() {
return '';
}
/**
* The description of the implementation, based on the current settings.
*/
public function getDescription() {
return $this->getGenericDescription();
}
public function getEditInstructions() {
return null;
}
/**
* Run the build target against the specified build.
*/
abstract public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target);
/**
* Gets the settings for this build step.
*/
public function getSettings() {
return $this->settings;
}
public function getSetting($key, $default = null) {
return idx($this->settings, $key, $default);
}
/**
* Loads the settings for this build step implementation from a build
* step or target.
*/
final public function loadSettings($build_object) {
$this->settings = $build_object->getDetails();
return $this;
}
/**
* Return the name of artifacts produced by this command.
*
* Future steps will calculate all available artifact mappings
* before them and filter on the type.
*
* @return array The mappings of artifact names to their types.
*/
public function getArtifactInputs() {
return array();
}
public function getArtifactOutputs() {
return array();
}
public function getDependencies(HarbormasterBuildStep $build_step) {
$dependencies = $build_step->getDetail('dependsOn', array());
$inputs = $build_step->getStepImplementation()->getArtifactInputs();
$inputs = ipull($inputs, null, 'key');
$artifacts = $this->getAvailableArtifacts(
$build_step->getBuildPlan(),
$build_step,
null);
foreach ($artifacts as $key => $type) {
if (!array_key_exists($key, $inputs)) {
unset($artifacts[$key]);
}
}
$artifact_steps = ipull($artifacts, 'step');
$artifact_steps = mpull($artifact_steps, 'getPHID');
$dependencies = array_merge($dependencies, $artifact_steps);
return $dependencies;
}
/**
* Returns a list of all artifacts made available in the build plan.
*/
public static function getAvailableArtifacts(
HarbormasterBuildPlan $build_plan,
$current_build_step,
$artifact_type) {
$steps = id(new HarbormasterBuildStepQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withBuildPlanPHIDs(array($build_plan->getPHID()))
->execute();
$artifacts = array();
$artifact_arrays = array();
foreach ($steps as $step) {
if ($current_build_step !== null &&
$step->getPHID() === $current_build_step->getPHID()) {
continue;
}
$implementation = $step->getStepImplementation();
$array = $implementation->getArtifactOutputs();
$array = ipull($array, 'type', 'key');
foreach ($array as $name => $type) {
if ($type !== $artifact_type && $artifact_type !== null) {
continue;
}
$artifacts[$name] = array('type' => $type, 'step' => $step);
}
}
return $artifacts;
}
/**
* Convert a user-provided string with variables in it, like:
*
* ls ${dirname}
*
* ...into a string with variables merged into it safely:
*
* ls 'dir with spaces'
*
* @param string Name of a `vxsprintf` function, like @{function:vcsprintf}.
* @param string User-provided pattern string containing `${variables}`.
* @param dict List of available replacement variables.
* @return string String with variables replaced safely into it.
*/
protected function mergeVariables($function, $pattern, array $variables) {
$regexp = '@\\$\\{(?P<name>[a-z\\./_-]+)\\}@';
$matches = null;
preg_match_all($regexp, $pattern, $matches);
$argv = array();
foreach ($matches['name'] as $name) {
if (!array_key_exists($name, $variables)) {
throw new Exception(pht("No such variable '%s'!", $name));
}
$argv[] = $variables[$name];
}
$pattern = str_replace('%', '%%', $pattern);
$pattern = preg_replace($regexp, '%s', $pattern);
return call_user_func($function, $pattern, $argv);
}
public function getFieldSpecifications() {
return array();
}
protected function formatSettingForDescription($key, $default = null) {
return $this->formatValueForDescription($this->getSetting($key, $default));
}
protected function formatValueForDescription($value) {
if (strlen($value)) {
return phutil_tag('strong', array(), $value);
} else {
return phutil_tag('em', array(), pht('(null)'));
}
}
public function supportsWaitForMessage() {
return false;
}
public function shouldWaitForMessage(HarbormasterBuildTarget $target) {
if (!$this->supportsWaitForMessage()) {
return false;
}
$wait = $target->getDetail('builtin.wait-for-message');
return ($wait == 'wait');
}
protected function shouldAbort(
HarbormasterBuild $build,
HarbormasterBuildTarget $target) {
return $build->getBuildGeneration() !== $target->getBuildGeneration();
}
protected function resolveFutures(
HarbormasterBuild $build,
HarbormasterBuildTarget $target,
array $futures) {
$did_close = false;
$wait_start = PhabricatorTime::getNow();
$futures = new FutureIterator($futures);
foreach ($futures->setUpdateInterval(5) as $key => $future) {
if ($future !== null) {
continue;
}
$build->reload();
if ($this->shouldAbort($build, $target)) {
throw new HarbormasterBuildAbortedException();
}
// See PHI916. If we're waiting on a remote system for a while, clean
// up database connections to reduce the cost of having a large number
// of processes babysitting an `ssh ... ./run-huge-build.sh` process on
// a build host.
if (!$did_close) {
$now = PhabricatorTime::getNow();
$elapsed = ($now - $wait_start);
$idle_limit = 5;
if ($elapsed >= $idle_limit) {
LiskDAO::closeIdleConnections();
$did_close = true;
}
}
}
}
protected function logHTTPResponse(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target,
BaseHTTPFuture $future,
$label) {
list($status, $body, $headers) = $future->resolve();
$header_lines = array();
// TODO: We don't currently preserve the entire "HTTP" response header, but
// should. Once we do, reproduce it here faithfully.
$status_code = $status->getStatusCode();
$header_lines[] = "HTTP {$status_code}";
foreach ($headers as $header) {
list($head, $tail) = $header;
$header_lines[] = "{$head}: {$tail}";
}
$header_lines = implode("\n", $header_lines);
$build_target
->newLog($label, 'http.head')
->append($header_lines);
$build_target
->newLog($label, 'http.body')
->append($body);
}
protected function logSilencedCall(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target,
$label) {
$build_target
->newLog($label, 'silenced')
->append(
pht(
'Declining to make service call because `phabricator.silent` is '.
'enabled in configuration.'));
}
public function willStartBuild(
PhabricatorUser $viewer,
HarbormasterBuildable $buildable,
HarbormasterBuild $build,
HarbormasterBuildPlan $plan,
HarbormasterBuildStep $step) {
return;
}
/* -( Automatic Targets )-------------------------------------------------- */
public function getBuildStepAutotargetStepKey() {
return null;
}
public function getBuildStepAutotargetPlanKey() {
throw new PhutilMethodNotImplementedException();
}
public function shouldRequireAutotargeting() {
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterArcUnitBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterArcUnitBuildStepImplementation.php | <?php
final class HarbormasterArcUnitBuildStepImplementation
extends HarbormasterBuildStepImplementation {
const STEPKEY = 'arcanist.unit';
public function getBuildStepAutotargetPlanKey() {
return HarbormasterBuildArcanistAutoplan::PLANKEY;
}
public function getBuildStepAutotargetStepKey() {
return self::STEPKEY;
}
public function shouldRequireAutotargeting() {
return true;
}
public function getName() {
return pht('Arcanist Unit Results');
}
public function getGenericDescription() {
return pht('Automatic `arc unit` step.');
}
public function getBuildStepGroupKey() {
return HarbormasterBuiltinBuildStepGroup::GROUPKEY;
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
return;
}
public function shouldWaitForMessage(HarbormasterBuildTarget $target) {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterSleepBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterSleepBuildStepImplementation.php | <?php
final class HarbormasterSleepBuildStepImplementation
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Sleep');
}
public function getGenericDescription() {
return pht('Sleep for a specified number of seconds.');
}
public function getBuildStepGroupKey() {
return HarbormasterTestBuildStepGroup::GROUPKEY;
}
public function getDescription() {
return pht(
'Sleep for %s seconds.',
$this->formatSettingForDescription('seconds'));
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
$settings = $this->getSettings();
$target = time() + $settings['seconds'];
// Use $build_update so that we only reload every 5 seconds, but
// the sleep mechanism remains accurate.
$build_update = 5;
while (time() < $target) {
sleep(1);
if ($build_update <= 0) {
$build->reload();
$build_update = 5;
if ($this->shouldAbort($build, $build_target)) {
throw new HarbormasterBuildAbortedException();
}
} else {
$build_update -= 1;
}
}
}
public function getFieldSpecifications() {
return array(
'seconds' => array(
'name' => pht('Seconds'),
'type' => 'int',
'required' => true,
'caption' => pht('The number of seconds to sleep for.'),
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterCircleCIBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterCircleCIBuildStepImplementation.php | <?php
final class HarbormasterCircleCIBuildStepImplementation
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Build with CircleCI');
}
public function getGenericDescription() {
return pht('Trigger a build in CircleCI.');
}
public function getBuildStepGroupKey() {
return HarbormasterExternalBuildStepGroup::GROUPKEY;
}
public function getDescription() {
return pht('Run a build in CircleCI.');
}
public function getEditInstructions() {
$hook_uri = '/harbormaster/hook/circleci/';
$hook_uri = PhabricatorEnv::getProductionURI($hook_uri);
return pht(<<<EOTEXT
WARNING: This build step is new and experimental!
To build **revisions** with CircleCI, they must:
- belong to a tracked repository;
- the repository must have a Staging Area configured;
- the Staging Area must be hosted on GitHub; and
- you must configure the webhook described below.
To build **commits** with CircleCI, they must:
- belong to a repository that is being imported from GitHub; and
- you must configure the webhook described below.
Webhook Configuration
=====================
Add this webhook to your `circle.yml` file to make CircleCI report results
to Harbormaster. Until you install this hook, builds will hang waiting for
a response from CircleCI.
```lang=yml
notify:
webhooks:
- url: %s
```
Environment
===========
These variables will be available in the build environment:
| Variable | Description |
|----------|-------------|
| `HARBORMASTER_BUILD_TARGET_PHID` | PHID of the Build Target.
EOTEXT
,
$hook_uri);
}
public static function getGitHubPath($uri) {
$uri_object = new PhutilURI($uri);
$domain = $uri_object->getDomain();
$domain = phutil_utf8_strtolower($domain);
switch ($domain) {
case 'github.com':
case 'www.github.com':
return $uri_object->getPath();
default:
return null;
}
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
$this->logSilencedCall($build, $build_target, pht('CircleCI'));
throw new HarbormasterBuildFailureException();
}
$buildable = $build->getBuildable();
$object = $buildable->getBuildableObject();
$object_phid = $object->getPHID();
if (!($object instanceof HarbormasterCircleCIBuildableInterface)) {
throw new Exception(
pht(
'Object ("%s") does not implement interface "%s". Only objects '.
'which implement this interface can be built with CircleCI.',
$object_phid,
'HarbormasterCircleCIBuildableInterface'));
}
$github_uri = $object->getCircleCIGitHubRepositoryURI();
$build_type = $object->getCircleCIBuildIdentifierType();
$build_identifier = $object->getCircleCIBuildIdentifier();
$path = self::getGitHubPath($github_uri);
if ($path === null) {
throw new Exception(
pht(
'Object ("%s") claims "%s" is a GitHub repository URI, but the '.
'domain does not appear to be GitHub.',
$object_phid,
$github_uri));
}
$path_parts = trim($path, '/');
$path_parts = explode('/', $path_parts);
if (count($path_parts) < 2) {
throw new Exception(
pht(
'Object ("%s") claims "%s" is a GitHub repository URI, but the '.
'path ("%s") does not have enough components (expected at least '.
'two).',
$object_phid,
$github_uri,
$path));
}
list($github_namespace, $github_name) = $path_parts;
$github_name = preg_replace('(\\.git$)', '', $github_name);
$credential_phid = $this->getSetting('token');
$api_token = id(new PassphraseCredentialQuery())
->setViewer($viewer)
->withPHIDs(array($credential_phid))
->needSecrets(true)
->executeOne();
if (!$api_token) {
throw new Exception(
pht(
'Unable to load API token ("%s")!',
$credential_phid));
}
// When we pass "revision", the branch is ignored (and does not even need
// to exist), and only shows up in the UI. Use a cute string which will
// certainly never break anything or cause any kind of problem.
$ship = "\xF0\x9F\x9A\xA2";
$branch = "{$ship}Harbormaster";
$token = $api_token->getSecret()->openEnvelope();
$parts = array(
'https://circleci.com/api/v1/project',
phutil_escape_uri($github_namespace),
phutil_escape_uri($github_name)."?circle-token={$token}",
);
$uri = implode('/', $parts);
$data_structure = array();
switch ($build_type) {
case 'tag':
$data_structure['tag'] = $build_identifier;
break;
case 'revision':
$data_structure['revision'] = $build_identifier;
break;
default:
throw new Exception(
pht(
'Unknown CircleCI build type "%s". Expected "%s" or "%s".',
$build_type,
'tag',
'revision'));
}
$data_structure['build_parameters'] = array(
'HARBORMASTER_BUILD_TARGET_PHID' => $build_target->getPHID(),
);
$json_data = phutil_json_encode($data_structure);
$future = id(new HTTPSFuture($uri, $json_data))
->setMethod('POST')
->addHeader('Content-Type', 'application/json')
->addHeader('Accept', 'application/json')
->setTimeout(60);
$this->resolveFutures(
$build,
$build_target,
array($future));
$this->logHTTPResponse($build, $build_target, $future, pht('CircleCI'));
list($status, $body) = $future->resolve();
if ($status->isError()) {
throw new HarbormasterBuildFailureException();
}
$response = phutil_json_decode($body);
$build_uri = idx($response, 'build_url');
if (!$build_uri) {
throw new Exception(
pht(
'CircleCI did not return a "%s"!',
'build_url'));
}
$target_phid = $build_target->getPHID();
// Write an artifact to create a link to the external build in CircleCI.
$api_method = 'harbormaster.createartifact';
$api_params = array(
'buildTargetPHID' => $target_phid,
'artifactType' => HarbormasterURIArtifact::ARTIFACTCONST,
'artifactKey' => 'circleci.uri',
'artifactData' => array(
'uri' => $build_uri,
'name' => pht('View in CircleCI'),
'ui.external' => true,
),
);
id(new ConduitCall($api_method, $api_params))
->setUser($viewer)
->execute();
}
public function getFieldSpecifications() {
return array(
'token' => array(
'name' => pht('API Token'),
'type' => 'credential',
'credential.type'
=> PassphraseTokenCredentialType::CREDENTIAL_TYPE,
'credential.provides'
=> PassphraseTokenCredentialType::PROVIDES_TYPE,
'required' => true,
),
);
}
public function supportsWaitForMessage() {
// NOTE: We always wait for a message, but don't need to show the UI
// control since "Wait" is the only valid choice.
return false;
}
public function shouldWaitForMessage(HarbormasterBuildTarget $target) {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterDrydockCommandBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterDrydockCommandBuildStepImplementation.php | <?php
final class HarbormasterDrydockCommandBuildStepImplementation
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Drydock: Run Command');
}
public function getGenericDescription() {
return pht('Run a command on Drydock resource.');
}
public function getBuildStepGroupKey() {
return HarbormasterDrydockBuildStepGroup::GROUPKEY;
}
public function getDescription() {
return pht(
'Run command %s on %s.',
$this->formatSettingForDescription('command'),
$this->formatSettingForDescription('artifact'));
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
$settings = $this->getSettings();
$variables = $build_target->getVariables();
$artifact = $build_target->loadArtifact($settings['artifact']);
$impl = $artifact->getArtifactImplementation();
$lease = $impl->loadArtifactLease($viewer);
// TODO: Require active lease.
$command = $this->mergeVariables(
'vcsprintf',
$settings['command'],
$variables);
$interface = $lease->getInterface(DrydockCommandInterface::INTERFACE_TYPE);
$exec_future = $interface->getExecFuture('%C', $command);
$harbor_future = id(new HarbormasterExecFuture())
->setFuture($exec_future)
->setLogs(
$build_target->newLog('remote', 'stdout'),
$build_target->newLog('remote', 'stderr'));
$this->resolveFutures(
$build,
$build_target,
array($harbor_future));
list($err) = $harbor_future->resolve();
if ($err) {
throw new HarbormasterBuildFailureException();
}
}
public function getArtifactInputs() {
return array(
array(
'name' => pht('Drydock Lease'),
'key' => $this->getSetting('artifact'),
'type' => HarbormasterWorkingCopyArtifact::ARTIFACTCONST,
),
);
}
public function getFieldSpecifications() {
return array(
'command' => array(
'name' => pht('Command'),
'type' => 'text',
'required' => true,
),
'artifact' => array(
'name' => pht('Drydock Lease'),
'type' => 'text',
'required' => true,
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/HarbormasterUploadArtifactBuildStepImplementation.php | src/applications/harbormaster/step/HarbormasterUploadArtifactBuildStepImplementation.php | <?php
final class HarbormasterUploadArtifactBuildStepImplementation
extends HarbormasterBuildStepImplementation {
public function getName() {
return pht('Upload File');
}
public function getGenericDescription() {
return pht('Upload a file.');
}
public function getBuildStepGroupKey() {
return HarbormasterPrototypeBuildStepGroup::GROUPKEY;
}
public function getDescription() {
return pht(
'Upload %s from %s.',
$this->formatSettingForDescription('path'),
$this->formatSettingForDescription('hostartifact'));
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
$settings = $this->getSettings();
$variables = $build_target->getVariables();
$path = $this->mergeVariables(
'vsprintf',
$settings['path'],
$variables);
$artifact = $build_target->loadArtifact($settings['hostartifact']);
$impl = $artifact->getArtifactImplementation();
$lease = $impl->loadArtifactLease($viewer);
$interface = $lease->getInterface('filesystem');
// TODO: Handle exceptions.
$file = $interface->saveFile($path, $settings['name']);
// Insert the artifact record.
$artifact = $build_target->createArtifact(
$viewer,
$settings['name'],
HarbormasterFileArtifact::ARTIFACTCONST,
array(
'filePHID' => $file->getPHID(),
));
}
public function getArtifactInputs() {
return array(
array(
'name' => pht('Upload From Host'),
'key' => $this->getSetting('hostartifact'),
'type' => HarbormasterHostArtifact::ARTIFACTCONST,
),
);
}
public function getArtifactOutputs() {
return array(
array(
'name' => pht('Uploaded File'),
'key' => $this->getSetting('name'),
'type' => HarbormasterHostArtifact::ARTIFACTCONST,
),
);
}
public function getFieldSpecifications() {
return array(
'path' => array(
'name' => pht('Path'),
'type' => 'text',
'required' => true,
),
'name' => array(
'name' => pht('Local Name'),
'type' => 'text',
'required' => true,
),
'hostartifact' => array(
'name' => pht('Host Artifact'),
'type' => 'text',
'required' => true,
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/step/__tests__/HarbormasterBuildStepImplementationTestCase.php | src/applications/harbormaster/step/__tests__/HarbormasterBuildStepImplementationTestCase.php | <?php
final class HarbormasterBuildStepImplementationTestCase
extends PhabricatorTestCase {
public function testGetImplementations() {
HarbormasterBuildStepImplementation::getImplementations();
$this->assertTrue(true);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/view/HarbormasterUnitPropertyView.php | src/applications/harbormaster/view/HarbormasterUnitPropertyView.php | <?php
final class HarbormasterUnitPropertyView extends AphrontView {
private $pathURIMap = array();
private $unitMessages = array();
private $limit;
private $fullResultsURI;
private $notice;
public function setPathURIMap(array $map) {
$this->pathURIMap = $map;
return $this;
}
public function setUnitMessages(array $messages) {
assert_instances_of($messages, 'HarbormasterBuildUnitMessage');
$this->unitMessages = $messages;
return $this;
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function setFullResultsURI($full_results_uri) {
$this->fullResultsURI = $full_results_uri;
return $this;
}
public function setNotice($notice) {
$this->notice = $notice;
return $this;
}
public function render() {
$viewer = $this->getViewer();
$messages = $this->unitMessages;
$messages = msort($messages, 'getSortKey');
$limit = $this->limit;
if ($this->limit) {
$display_messages = array_slice($messages, 0, $limit);
} else {
$display_messages = $messages;
}
$rows = array();
$any_duration = false;
foreach ($display_messages as $message) {
$status = $message->getResult();
$icon_icon = HarbormasterUnitStatus::getUnitStatusIcon($status);
$icon_color = HarbormasterUnitStatus::getUnitStatusColor($status);
$icon_label = HarbormasterUnitStatus::getUnitStatusLabel($status);
$result_icon = id(new PHUIIconView())
->setIcon("{$icon_icon} {$icon_color}")
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => $icon_label,
));
$duration = $message->getDuration();
if ($duration !== null) {
$any_duration = true;
$duration = pht('%s ms', new PhutilNumber((int)(1000 * $duration)));
}
$name = $message->getUnitMessageDisplayName();
$uri = $message->getURI();
if ($uri) {
$name = phutil_tag(
'a',
array(
'href' => $uri,
),
$name);
}
$name = array(
$name,
$message->newUnitMessageDetailsView($viewer, true),
);
$rows[] = array(
$result_icon,
$duration,
$name,
);
}
$full_uri = $this->fullResultsURI;
if ($full_uri && (count($messages) > $limit)) {
$counts = array();
$groups = mgroup($messages, 'getResult');
foreach ($groups as $status => $group) {
$counts[] = HarbormasterUnitStatus::getUnitStatusCountLabel(
$status,
count($group));
}
$link_text = pht(
'View Full Test Results (%s)',
implode(" \xC2\xB7 ", $counts));
$full_link = phutil_tag(
'a',
array(
'href' => $full_uri,
),
$link_text);
$link_icon = id(new PHUIIconView())
->setIcon('fa-ellipsis-h lightgreytext');
$rows[] = array($link_icon, null, $full_link);
}
$table = id(new AphrontTableView($rows))
->setHeaders(
array(
null,
pht('Time'),
pht('Test'),
))
->setColumnClasses(
array(
'top center',
'top right',
'top wide',
))
->setColumnWidths(
array(
'32px',
'64px',
))
->setColumnVisibility(
array(
true,
$any_duration,
));
if ($this->notice) {
$table->setNotice($this->notice);
}
return $table;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/view/HarbormasterUnitSummaryView.php | src/applications/harbormaster/view/HarbormasterUnitSummaryView.php | <?php
final class HarbormasterUnitSummaryView extends AphrontView {
private $buildable;
private $messages;
private $limit;
private $showViewAll;
public function setBuildable(HarbormasterBuildable $buildable) {
$this->buildable = $buildable;
return $this;
}
public function setUnitMessages(array $messages) {
$this->messages = $messages;
return $this;
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function setShowViewAll($show_view_all) {
$this->showViewAll = $show_view_all;
return $this;
}
public function render() {
$messages = $this->messages;
$buildable = $this->buildable;
$id = $buildable->getID();
$full_uri = "/harbormaster/unit/{$id}/";
$messages = msort($messages, 'getSortKey');
$head_unit = head($messages);
if ($head_unit) {
$status = $head_unit->getResult();
$tag_text = HarbormasterUnitStatus::getUnitStatusLabel($status);
$tag_color = HarbormasterUnitStatus::getUnitStatusColor($status);
$tag_icon = HarbormasterUnitStatus::getUnitStatusIcon($status);
} else {
$tag_text = pht('No Unit Tests');
$tag_color = 'grey';
$tag_icon = 'fa-ban';
}
$tag = id(new PHUITagView())
->setType(PHUITagView::TYPE_SHADE)
->setColor($tag_color)
->setIcon($tag_icon)
->setName($tag_text);
$header = id(new PHUIHeaderView())
->setHeader(array(pht('Unit Tests'), $tag));
if ($this->showViewAll) {
$view_all = id(new PHUIButtonView())
->setTag('a')
->setHref($full_uri)
->setIcon('fa-list-ul')
->setText('View All');
$header->addActionLink($view_all);
}
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
$table = id(new HarbormasterUnitPropertyView())
->setViewer($this->getViewer())
->setUnitMessages($messages);
if ($this->showViewAll) {
$table->setFullResultsURI($full_uri);
}
if ($this->limit) {
$table->setLimit($this->limit);
}
$box->setTable($table);
return $box;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/view/ShellLogView.php | src/applications/harbormaster/view/ShellLogView.php | <?php
final class ShellLogView extends AphrontView {
private $start = 1;
private $lines;
private $limit;
private $highlights = array();
public function setStart($start) {
$this->start = $start;
return $this;
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function setLines(array $lines) {
$this->lines = $lines;
return $this;
}
public function setHighlights(array $highlights) {
$this->highlights = array_fuse($highlights);
return $this;
}
public function render() {
require_celerity_resource('phabricator-source-code-view-css');
require_celerity_resource('syntax-highlighting-css');
Javelin::initBehavior('phabricator-oncopy', array());
$line_number = $this->start;
$rows = array();
foreach ($this->lines as $line) {
$hit_limit = $this->limit &&
($line_number == $this->limit) &&
(count($this->lines) != $this->limit);
if ($hit_limit) {
$content_number = '';
$content_line = phutil_tag(
'span',
array(
'class' => 'c',
),
pht('...'));
} else {
$content_number = $line_number;
$content_line = $line;
}
$row_attributes = array();
if (isset($this->highlights[$line_number])) {
$row_attributes['class'] = 'phabricator-source-highlight';
}
// TODO: Provide nice links.
$th = phutil_tag(
'th',
array(
'class' => 'phabricator-source-line',
),
$content_number);
$td = phutil_tag(
'td',
array('class' => 'phabricator-source-code'),
$content_line);
$rows[] = phutil_tag(
'tr',
$row_attributes,
array($th, $td));
if ($hit_limit) {
break;
}
$line_number++;
}
$classes = array();
$classes[] = 'phabricator-source-code-view';
$classes[] = 'remarkup-code';
$classes[] = 'PhabricatorMonospaced';
return phutil_tag(
'div',
array(
'class' => 'phabricator-source-code-container',
),
phutil_tag(
'table',
array(
'class' => implode(' ', $classes),
),
phutil_implode_html('', $rows)));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/view/HarbormasterBuildLogView.php | src/applications/harbormaster/view/HarbormasterBuildLogView.php | <?php
final class HarbormasterBuildLogView extends AphrontView {
private $log;
private $highlightedLineRange;
private $enableHighlighter;
public function setBuildLog(HarbormasterBuildLog $log) {
$this->log = $log;
return $this;
}
public function getBuildLog() {
return $this->log;
}
public function setHighlightedLineRange($range) {
$this->highlightedLineRange = $range;
return $this;
}
public function getHighlightedLineRange() {
return $this->highlightedLineRange;
}
public function setEnableHighlighter($enable) {
$this->enableHighlighter = $enable;
return $this;
}
public function render() {
$viewer = $this->getViewer();
$log = $this->getBuildLog();
$id = $log->getID();
$header = id(new PHUIHeaderView())
->setViewer($viewer)
->setHeader(pht('Build Log %d', $id));
$download_uri = "/harbormaster/log/download/{$id}/";
$can_download = (bool)$log->getFilePHID();
$download_button = id(new PHUIButtonView())
->setTag('a')
->setHref($download_uri)
->setIcon('fa-download')
->setDisabled(!$can_download)
->setWorkflow(!$can_download)
->setText(pht('Download Log'));
$header->addActionLink($download_button);
$box_view = id(new PHUIObjectBoxView())
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setHeader($header);
if ($this->enableHighlighter) {
Javelin::initBehavior('phabricator-line-linker');
}
$has_linemap = $log->getLineMap();
if ($has_linemap) {
$content_id = celerity_generate_unique_node_id();
$content_div = javelin_tag(
'div',
array(
'id' => $content_id,
'class' => 'harbormaster-log-view-loading',
),
pht('Loading...'));
require_celerity_resource('harbormaster-css');
Javelin::initBehavior(
'harbormaster-log',
array(
'contentNodeID' => $content_id,
'initialURI' => $log->getRenderURI($this->getHighlightedLineRange()),
'renderURI' => $log->getRenderURI(null),
));
$box_view->appendChild($content_div);
} else {
$box_view->setFormErrors(
array(
pht(
'This older log is missing required rendering data. To rebuild '.
'rendering data, run: %s',
phutil_tag(
'tt',
array(),
'$ bin/harbormaster rebuild-log --force --id '.$log->getID())),
));
}
return $box_view;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/view/HarbormasterLintPropertyView.php | src/applications/harbormaster/view/HarbormasterLintPropertyView.php | <?php
final class HarbormasterLintPropertyView extends AphrontView {
private $pathURIMap = array();
private $lintMessages = array();
private $limit;
public function setPathURIMap(array $map) {
$this->pathURIMap = $map;
return $this;
}
public function setLintMessages(array $messages) {
assert_instances_of($messages, 'HarbormasterBuildLintMessage');
$this->lintMessages = $messages;
return $this;
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function render() {
$messages = $this->lintMessages;
$messages = msort($messages, 'getSortKey');
if ($this->limit) {
$messages = array_slice($messages, 0, $this->limit);
}
$rows = array();
foreach ($messages as $message) {
$path = $message->getPath();
$line = $message->getLine();
$href = null;
if (strlen(idx($this->pathURIMap, $path))) {
$href = $this->pathURIMap[$path].max($line, 1);
}
$severity = $this->renderSeverity($message->getSeverity());
$location = $path.':'.$line;
if (strlen($href)) {
$location = phutil_tag(
'a',
array(
'href' => $href,
),
$location);
}
$rows[] = array(
$severity,
$location,
$message->getCode(),
$message->getName(),
);
}
$table = id(new AphrontTableView($rows))
->setHeaders(
array(
pht('Severity'),
pht('Location'),
pht('Code'),
pht('Message'),
))
->setColumnClasses(
array(
null,
'pri',
null,
'wide',
));
return $table;
}
private function renderSeverity($severity) {
$names = ArcanistLintSeverity::getLintSeverities();
$name = idx($names, $severity, $severity);
// TODO: Add some color here?
return $name;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/view/HarbormasterBuildView.php | src/applications/harbormaster/view/HarbormasterBuildView.php | <?php
final class HarbormasterBuildView
extends AphrontView {
private $builds = array();
public function setBuilds(array $builds) {
assert_instances_of($builds, 'HarbormasterBuild');
$this->builds = $builds;
return $this;
}
public function getBuilds() {
return $this->builds;
}
public function render() {
return $this->newObjectList();
}
public function newObjectList() {
$viewer = $this->getViewer();
$builds = $this->getBuilds();
$buildables = mpull($builds, 'getBuildable');
$object_phids = mpull($buildables, 'getBuildablePHID');
$initiator_phids = mpull($builds, 'getInitiatorPHID');
$phids = array_mergev(array($initiator_phids, $object_phids));
$phids = array_unique(array_filter($phids));
$handles = $viewer->loadHandles($phids);
$list = new PHUIObjectItemListView();
foreach ($builds as $build) {
$id = $build->getID();
$buildable_object = $handles[$build->getBuildable()->getBuildablePHID()];
$item = id(new PHUIObjectItemView())
->setViewer($viewer)
->setObject($build)
->setObjectName($build->getObjectName())
->setHeader($build->getName())
->setHref($build->getURI())
->setEpoch($build->getDateCreated())
->addAttribute($buildable_object->getName());
$initiator_phid = $build->getInitiatorPHID();
if ($initiator_phid) {
$initiator = $handles[$initiator_phid];
$item->addByline($initiator->renderLink());
}
$status = $build->getBuildStatus();
$status_icon = HarbormasterBuildStatus::getBuildStatusIcon($status);
$status_color = HarbormasterBuildStatus::getBuildStatusColor($status);
$status_label = HarbormasterBuildStatus::getBuildStatusName($status);
$item->setStatusIcon("{$status_icon} {$status_color}", $status_label);
$list->addItem($item);
}
return $list;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/stepgroup/HarbormasterOtherBuildStepGroup.php | src/applications/harbormaster/stepgroup/HarbormasterOtherBuildStepGroup.php | <?php
final class HarbormasterOtherBuildStepGroup
extends HarbormasterBuildStepGroup {
const GROUPKEY = 'harbormaster.other';
public function getGroupName() {
return pht('Other Build Steps');
}
public function getGroupOrder() {
return 9000;
}
public function shouldShowIfEmpty() {
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/stepgroup/HarbormasterPrototypeBuildStepGroup.php | src/applications/harbormaster/stepgroup/HarbormasterPrototypeBuildStepGroup.php | <?php
final class HarbormasterPrototypeBuildStepGroup
extends HarbormasterBuildStepGroup {
const GROUPKEY = 'harbormaster.prototype';
public function getGroupName() {
return pht('Prototypes');
}
public function getGroupOrder() {
return 8000;
}
public function isEnabled() {
return PhabricatorEnv::getEnvConfig('phabricator.show-prototypes');
}
public function shouldShowIfEmpty() {
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/stepgroup/HarbormasterControlBuildStepGroup.php | src/applications/harbormaster/stepgroup/HarbormasterControlBuildStepGroup.php | <?php
final class HarbormasterControlBuildStepGroup
extends HarbormasterBuildStepGroup {
const GROUPKEY = 'harbormaster.control';
public function getGroupName() {
return pht('Flow Control');
}
public function getGroupOrder() {
return 5000;
}
public function shouldShowIfEmpty() {
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/stepgroup/HarbormasterBuildStepGroup.php | src/applications/harbormaster/stepgroup/HarbormasterBuildStepGroup.php | <?php
abstract class HarbormasterBuildStepGroup extends Phobject {
abstract public function getGroupName();
abstract public function getGroupOrder();
public function isEnabled() {
return true;
}
public function shouldShowIfEmpty() {
return true;
}
final public function getGroupKey() {
return $this->getPhobjectClassConstant('GROUPKEY');
}
final public static function getAllGroups() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getGroupKey')
->setSortMethod('getGroupOrder')
->execute();
}
final public static function getAllEnabledGroups() {
$groups = self::getAllGroups();
foreach ($groups as $key => $group) {
if (!$group->isEnabled()) {
unset($groups[$key]);
}
}
return $groups;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/stepgroup/HarbormasterDrydockBuildStepGroup.php | src/applications/harbormaster/stepgroup/HarbormasterDrydockBuildStepGroup.php | <?php
final class HarbormasterDrydockBuildStepGroup
extends HarbormasterBuildStepGroup {
const GROUPKEY = 'harbormaster.drydock';
public function getGroupName() {
return pht('Drydock');
}
public function getGroupOrder() {
return 3000;
}
public function isEnabled() {
$drydock_class = 'PhabricatorDrydockApplication';
return PhabricatorApplication::isClassInstalled($drydock_class);
}
public function shouldShowIfEmpty() {
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/stepgroup/HarbormasterBuiltinBuildStepGroup.php | src/applications/harbormaster/stepgroup/HarbormasterBuiltinBuildStepGroup.php | <?php
final class HarbormasterBuiltinBuildStepGroup
extends HarbormasterBuildStepGroup {
const GROUPKEY = 'harbormaster.builtin';
public function getGroupName() {
return pht('Builtins');
}
public function getGroupOrder() {
return 0;
}
public function shouldShowIfEmpty() {
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/stepgroup/HarbormasterExternalBuildStepGroup.php | src/applications/harbormaster/stepgroup/HarbormasterExternalBuildStepGroup.php | <?php
final class HarbormasterExternalBuildStepGroup
extends HarbormasterBuildStepGroup {
const GROUPKEY = 'harbormaster.external';
public function getGroupName() {
return pht('Interacting with External Build Systems');
}
public function getGroupOrder() {
return 4000;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/stepgroup/HarbormasterTestBuildStepGroup.php | src/applications/harbormaster/stepgroup/HarbormasterTestBuildStepGroup.php | <?php
final class HarbormasterTestBuildStepGroup
extends HarbormasterBuildStepGroup {
const GROUPKEY = 'harbormaster.test';
public function getGroupName() {
return pht('Testing Utilities');
}
public function getGroupOrder() {
return 7000;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/event/HarbormasterUIEventListener.php | src/applications/harbormaster/event/HarbormasterUIEventListener.php | <?php
final class HarbormasterUIEventListener
extends PhabricatorEventListener {
public function register() {
$this->listen(PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES);
}
public function handleEvent(PhutilEvent $event) {
switch ($event->getType()) {
case PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES:
$this->handlePropertyEvent($event);
break;
}
}
private function handlePropertyEvent($ui_event) {
$viewer = $ui_event->getUser();
$object = $ui_event->getValue('object');
if (!$object || !$object->getPHID()) {
// No object, or the object has no PHID yet..
return;
}
if ($object instanceof HarbormasterBuildable) {
// Although HarbormasterBuildable implements the correct interface, it
// does not make sense to show a build's build status. In the best case
// it is meaningless, and in the worst case it's confusing.
return;
}
if ($object instanceof DifferentialRevision) {
// TODO: This is a bit hacky and we could probably find a cleaner fix
// eventually, but we show build status on each diff, immediately below
// this property list, so it's redundant to show it on the revision view.
return;
}
if (!($object instanceof HarbormasterBuildableInterface)) {
return;
}
$buildable_phid = $object->getHarbormasterBuildablePHID();
if (!$buildable_phid) {
return;
}
if (!$this->canUseApplication($ui_event->getUser())) {
return;
}
try {
$buildable = id(new HarbormasterBuildableQuery())
->setViewer($viewer)
->withManualBuildables(false)
->withBuildablePHIDs(array($buildable_phid))
->needBuilds(true)
->needTargets(true)
->executeOne();
} catch (PhabricatorPolicyException $ex) {
// TODO: See PHI430. When this query raises a policy exception, it
// fatals the whole page because it happens very late in execution,
// during final page rendering. If the viewer can't see the buildable or
// some of the builds, just hide this element for now.
return;
}
if (!$buildable) {
return;
}
$builds = $buildable->getBuilds();
$targets = array();
foreach ($builds as $build) {
foreach ($build->getBuildTargets() as $target) {
$targets[] = $target;
}
}
if ($targets) {
$artifacts = id(new HarbormasterBuildArtifactQuery())
->setViewer($viewer)
->withBuildTargetPHIDs(mpull($targets, 'getPHID'))
->withArtifactTypes(
array(
HarbormasterURIArtifact::ARTIFACTCONST,
))
->execute();
$artifacts = mgroup($artifacts, 'getBuildTargetPHID');
} else {
$artifacts = array();
}
$status_view = new PHUIStatusListView();
$buildable_icon = $buildable->getStatusIcon();
$buildable_color = $buildable->getStatusColor();
$buildable_name = $buildable->getStatusDisplayName();
$target = phutil_tag(
'a',
array(
'href' => '/'.$buildable->getMonogram(),
),
pht('Buildable %d', $buildable->getID()));
$target = phutil_tag('strong', array(), $target);
$status_view
->addItem(
id(new PHUIStatusItemView())
->setIcon($buildable_icon, $buildable_color, $buildable_name)
->setTarget($target));
foreach ($builds as $build) {
$item = new PHUIStatusItemView();
$item->setTarget($viewer->renderHandle($build->getPHID()));
$links = array();
foreach ($build->getBuildTargets() as $build_target) {
$uris = idx($artifacts, $build_target->getPHID(), array());
foreach ($uris as $uri) {
$impl = $uri->getArtifactImplementation();
if ($impl->isExternalLink()) {
$links[] = $impl->renderLink();
}
}
}
if ($links) {
$links = phutil_implode_html(" \xC2\xB7 ", $links);
$item->setNote($links);
}
$status = $build->getBuildStatus();
$status_name = HarbormasterBuildStatus::getBuildStatusName($status);
$icon = HarbormasterBuildStatus::getBuildStatusIcon($status);
$color = HarbormasterBuildStatus::getBuildStatusColor($status);
$item->setIcon($icon, $color, $status_name);
$status_view->addItem($item);
}
$view = $ui_event->getValue('view');
$view->addProperty(pht('Build Status'), $status_view);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/phid/HarbormasterBuildArtifactPHIDType.php | src/applications/harbormaster/phid/HarbormasterBuildArtifactPHIDType.php | <?php
final class HarbormasterBuildArtifactPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'HMBA';
public function getTypeName() {
return pht('Build Artifact');
}
public function newObject() {
return new HarbormasterBuildArtifact();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new HarbormasterBuildArtifactQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$artifact = $objects[$phid];
$artifact_id = $artifact->getID();
$handle->setName(pht('Build Artifact %d', $artifact_id));
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/phid/HarbormasterBuildTargetPHIDType.php | src/applications/harbormaster/phid/HarbormasterBuildTargetPHIDType.php | <?php
final class HarbormasterBuildTargetPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'HMBT';
public function getTypeName() {
return pht('Build Target');
}
public function newObject() {
return new HarbormasterBuildTarget();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new HarbormasterBuildTargetQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$target = $objects[$phid];
$target_id = $target->getID();
// Build target don't currently have their own page, so just point
// the user at the build until we have one.
$build = $target->getBuild();
$build_id = $build->getID();
$uri = "/harbormaster/build/{$build_id}/";
$handle->setName(pht('Build Target %d', $target_id));
$handle->setURI($uri);
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php | src/applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php | <?php
final class HarbormasterBuildLogPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'HMCL';
public function getTypeName() {
return pht('Build Log');
}
public function newObject() {
return new HarbormasterBuildLog();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new HarbormasterBuildLogQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$build_log = $objects[$phid];
$handle
->setName(pht('Build Log %d', $build_log->getID()))
->setURI($build_log->getURI());
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/phid/HarbormasterBuildPlanPHIDType.php | src/applications/harbormaster/phid/HarbormasterBuildPlanPHIDType.php | <?php
final class HarbormasterBuildPlanPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'HMCP';
public function getTypeName() {
return pht('Build Plan');
}
public function getTypeIcon() {
return 'fa-cubes';
}
public function newObject() {
return new HarbormasterBuildPlan();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new HarbormasterBuildPlanQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$build_plan = $objects[$phid];
$id = $build_plan->getID();
$handles[$phid]->setName(pht('Plan %d %s', $id, $build_plan->getName()));
$handles[$phid]->setURI('/harbormaster/plan/'.$id.'/');
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/phid/HarbormasterBuildStepPHIDType.php | src/applications/harbormaster/phid/HarbormasterBuildStepPHIDType.php | <?php
final class HarbormasterBuildStepPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'HMCS';
public function getTypeName() {
return pht('Build Step');
}
public function newObject() {
return new HarbormasterBuildStep();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new HarbormasterBuildStepQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$build_step = $objects[$phid];
$id = $build_step->getID();
$name = $build_step->getName();
$handle
->setName($name)
->setFullName(pht('Build Step %d: %s', $id, $name))
->setURI("/harbormaster/step/view/{$id}/");
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/phid/HarbormasterBuildablePHIDType.php | src/applications/harbormaster/phid/HarbormasterBuildablePHIDType.php | <?php
final class HarbormasterBuildablePHIDType extends PhabricatorPHIDType {
const TYPECONST = 'HMBB';
public function getTypeName() {
return pht('Buildable');
}
public function newObject() {
return new HarbormasterBuildable();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new HarbormasterBuildableQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
$viewer = $query->getViewer();
$target_phids = array();
foreach ($objects as $phid => $object) {
$target_phids[] = $object->getBuildablePHID();
}
$target_handles = $viewer->loadHandles($target_phids);
foreach ($handles as $phid => $handle) {
$buildable = $objects[$phid];
$id = $buildable->getID();
$buildable_phid = $buildable->getBuildablePHID();
$target = $target_handles[$buildable_phid];
$target_name = $target->getFullName();
$uri = $buildable->getURI();
$monogram = $buildable->getMonogram();
$handle
->setURI($uri)
->setName($monogram)
->setFullName("{$monogram}: {$target_name}");
}
}
public function canLoadNamedObject($name) {
return preg_match('/^B\d*[1-9]\d*$/i', $name);
}
public function loadNamedObjects(
PhabricatorObjectQuery $query,
array $names) {
$id_map = array();
foreach ($names as $name) {
$id = (int)substr($name, 1);
$id_map[$id][] = $name;
}
$objects = id(new HarbormasterBuildableQuery())
->setViewer($query->getViewer())
->withIDs(array_keys($id_map))
->execute();
$results = array();
foreach ($objects as $id => $object) {
foreach (idx($id_map, $id, array()) as $name) {
$results[$name] = $object;
}
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/phid/HarbormasterBuildPHIDType.php | src/applications/harbormaster/phid/HarbormasterBuildPHIDType.php | <?php
final class HarbormasterBuildPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'HMBD';
public function getTypeName() {
return pht('Build');
}
public function newObject() {
return new HarbormasterBuild();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new HarbormasterBuildQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$build = $objects[$phid];
$build_id = $build->getID();
$name = $build->getName();
$handle->setName(pht('Build %d: %s', $build_id, $name));
$handle->setURI("/harbormaster/build/{$build_id}/");
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php | src/applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php | <?php
final class HarbormasterRunBuildPlansHeraldAction
extends HeraldAction {
const DO_BUILD = 'do.build';
const ACTIONCONST = 'harbormaster.build';
public function getRequiredAdapterStates() {
return array(
HeraldBuildableState::STATECONST,
);
}
public function getActionGroupKey() {
return HeraldSupportActionGroup::ACTIONGROUPKEY;
}
public function supportsObject($object) {
$adapter = $this->getAdapter();
return ($adapter instanceof HarbormasterBuildableAdapterInterface);
}
protected function applyBuilds(array $phids, HeraldRule $rule) {
$adapter = $this->getAdapter();
$allowed_types = array(
HarbormasterBuildPlanPHIDType::TYPECONST,
);
$targets = $this->loadStandardTargets($phids, $allowed_types, array());
if (!$targets) {
return;
}
$phids = array_fuse(array_keys($targets));
foreach ($phids as $phid) {
$request = id(new HarbormasterBuildRequest())
->setBuildPlanPHID($phid)
->setInitiatorPHID($rule->getPHID());
$adapter->queueHarbormasterBuildRequest($request);
}
$this->logEffect(self::DO_BUILD, $phids);
}
protected function getActionEffectMap() {
return array(
self::DO_BUILD => array(
'icon' => 'fa-play',
'color' => 'green',
'name' => pht('Building'),
),
);
}
protected function renderActionEffectDescription($type, $data) {
switch ($type) {
case self::DO_BUILD:
return pht(
'Started %s build(s): %s.',
phutil_count($data),
$this->renderHandleList($data));
}
}
public function getHeraldActionName() {
return pht('Run build plans');
}
public function supportsRuleType($rule_type) {
return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
}
public function applyEffect($object, HeraldEffect $effect) {
return $this->applyBuilds($effect->getTarget(), $effect->getRule());
}
public function getHeraldActionStandardType() {
return self::STANDARD_PHID_LIST;
}
protected function getDatasource() {
return new HarbormasterBuildPlanDatasource();
}
public function renderActionDescription($value) {
return pht(
'Run build plans: %s.',
$this->renderHandleList($value));
}
public function getPHIDsAffectedByAction(HeraldActionRecord $record) {
return $record->getTarget();
}
public function isActionAvailable() {
return id(new PhabricatorHarbormasterApplication())->isInstalled();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/herald/HarbormasterBuildableAdapterInterface.php | src/applications/harbormaster/herald/HarbormasterBuildableAdapterInterface.php | <?php
interface HarbormasterBuildableAdapterInterface {
public function getHarbormasterBuildablePHID();
public function getHarbormasterContainerPHID();
public function getQueuedHarbormasterBuildRequests();
public function queueHarbormasterBuildRequest(
HarbormasterBuildRequest $request);
}
// TEMPLATE IMPLEMENTATION /////////////////////////////////////////////////////
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */
/*
public function getHarbormasterBuildablePHID() {
return $this->getObject()->getPHID();
}
public function getHarbormasterContainerPHID() {
return null;
}
public function getQueuedHarbormasterBuildPlanPHIDs() {
return $this->buildPlanPHIDs;
}
public function queueHarbormasterBuildPlanPHID($phid) {
$this->buildPlanPHIDs[] = $phid;
}
*/
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterBuildableSearchAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterBuildableSearchAPIMethod.php | <?php
final class HarbormasterBuildableSearchAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.buildable.search';
}
public function newSearchEngine() {
return new HarbormasterBuildableSearchEngine();
}
public function getMethodSummary() {
return pht('Find out information about buildables.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterSendMessageConduitAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterSendMessageConduitAPIMethod.php | <?php
final class HarbormasterSendMessageConduitAPIMethod
extends HarbormasterConduitAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.sendmessage';
}
public function getMethodSummary() {
return pht(
'Modify running builds, and report build results.');
}
public function getMethodDescription() {
return pht(<<<EOREMARKUP
Pause, abort, restart, and report results for builds.
EOREMARKUP
);
}
protected function newDocumentationPages(PhabricatorUser $viewer) {
$pages = array();
$pages[] = $this->newSendingDocumentationBoxPage($viewer);
$pages[] = $this->newBuildsDocumentationBoxPage($viewer);
$pages[] = $this->newCommandsDocumentationBoxPage($viewer);
$pages[] = $this->newTargetsDocumentationBoxPage($viewer);
$pages[] = $this->newUnitDocumentationBoxPage($viewer);
$pages[] = $this->newLintDocumentationBoxPage($viewer);
return $pages;
}
private function newSendingDocumentationBoxPage(PhabricatorUser $viewer) {
$title = pht('Sending Messages');
$content = pht(<<<EOREMARKUP
Harbormaster build objects work somewhat differently from objects in many other
applications. Most application objects can be edited directly using synchronous
APIs (like `maniphest.edit`, `differential.revision.edit`, and so on).
However, builds require long-running background processing and Habormaster
objects have a more complex lifecycle than most other application objects and
may spend significant periods of time locked by daemon processes during build
execition. A synchronous edit might need to wait an arbitrarily long amount of
time for this lock to become available so the edit could be applied.
Additionally, some edits may also require an arbitrarily long amount of time to
//complete//. For example, aborting a build may execute cleanup steps which
take minutes (or even hours) to complete.
Since a synchronous API could not guarantee it could return results to the
caller in a reasonable amount of time, the edit API for Harbormaster build
objects is asynchronous: to update a Harbormaster build or build target, use
this API (`harbormaster.sendmessage`) to send it a message describing an edit
you would like to effect or additional information you want to provide.
The message will be processed by the daemons once the build or target reaches
a suitable state to receive messages.
Select an object to send a message to using the `receiver` parameter. This
API method can send messages to multiple types of objects:
<table>
<tr>
<th>Object Type</th>
<th>PHID Example</th>
<th>Description</th>
</tr>
<tr>
<td>Harbormaster Buildable</td>
<td>`PHID-HMBB-...`</td>
<td>%s</td>
</tr>
<tr>
<td>Harbormaster Build</td>
<td>`PHID-HMBD-...`</td>
<td>%s</td>
</tr>
<tr>
<td>Harbormaster Build Target</td>
<td>`PHID-HMBT-...`</td>
<td>%s</td>
</tr>
</table>
See below for specifics on sending messages to different object types.
EOREMARKUP
,
pht(
'Buildables may receive control commands like "abort" and "restart". '.
'Sending a control command to a Buildable is the same as sending it '.
'to each Build for the Buildable.'),
pht(
'Builds may receive control commands like "pause", "resume", "abort", '.
'and "restart".'),
pht(
'Build Targets may receive build status and result messages, like '.
'"pass" or "fail".'));
$content = $this->newRemarkupDocumentationView($content);
return $this->newDocumentationBoxPage($viewer, $title, $content)
->setAnchor('sending')
->setIconIcon('fa-envelope-o');
}
private function newBuildsDocumentationBoxPage(PhabricatorUser $viewer) {
$title = pht('Updating Builds');
$content = pht(<<<EOREMARKUP
You can use this method (`harbormaster.sendmessage`) to send control commands
to Buildables and Builds.
Specify the Build or Buildable to receive the control command by providing its
PHID in the `receiver` parameter.
Sending a control command to a Buildable has the same effect as sending it to
each Build for the Buildable. For example, sending a "Pause" message to a
Buildable will pause all builds for the Buildable (or at least attempt to).
When sending control commands, the `unit` and `lint` parameters of this API
method must be omitted. You can not report lint or unit results directly to
a Build or Buildable, and can not report them alongside a control command.
More broadly, you can not report build results directly to a Build or
Buildable. Instead, report results to a Build Target.
See below for a list of control commands.
EOREMARKUP
);
$content = $this->newRemarkupDocumentationView($content);
return $this->newDocumentationBoxPage($viewer, $title, $content)
->setAnchor('builds')
->setIconIcon('fa-cubes');
}
private function newCommandsDocumentationBoxPage(PhabricatorUser $viewer) {
$messages = HarbormasterBuildMessageTransaction::getAllMessages();
$rows = array();
$rows[] = '<tr>';
$rows[] = '<th>'.pht('Message Type').'</th>';
$rows[] = '<th>'.pht('Description').'</th>';
$rows[] = '</tr>';
foreach ($messages as $message) {
$row = array();
$row[] = sprintf(
'<td>`%s`</td>',
$message->getHarbormasterBuildMessageType());
$row[] = sprintf(
'<td>%s</td>',
$message->getHarbormasterBuildMessageDescription());
$rows[] = sprintf(
'<tr>%s</tr>',
implode("\n", $row));
}
$message_table = sprintf(
'<table>%s</table>',
implode("\n", $rows));
$title = pht('Control Commands');
$content = pht(<<<EOREMARKUP
You can use this method to send control commands to Buildables and Builds.
This table summarizes which object types may receive control commands:
<table>
<tr>
<th>Object Type</th>
<th>PHID Example</th>
<th />
<th>Description</th>
</tr>
<tr>
<td>Harbormaster Buildable</td>
<td>`PHID-HMBB-...`</td>
<td>{icon check color=green}</td>
<td>Buildables may receive control commands.</td>
</tr>
<tr>
<td>Harbormaster Build</td>
<td>`PHID-HMBD-...`</td>
<td>{icon check color=green}</td>
<td>Builds may receive control commands.</td>
</tr>
<tr>
<td>Harbormaster Build Target</td>
<td>`PHID-HMBT-...`</td>
<td>{icon times color=red}</td>
<td>You may **NOT** send control commands to build targets.</td>
</tr>
</table>
You can send these commands:
%s
To send a command message, specify the PHID of the object you would like to
receive the message using the `receiver` parameter, and specify the message
type using the `type` parameter.
EOREMARKUP
,
$message_table);
$content = $this->newRemarkupDocumentationView($content);
return $this->newDocumentationBoxPage($viewer, $title, $content)
->setAnchor('commands')
->setIconIcon('fa-exclamation-triangle');
}
private function newTargetsDocumentationBoxPage(PhabricatorUser $viewer) {
$messages = HarbormasterMessageType::getAllMessages();
$head_type = pht('Type');
$head_desc = pht('Description');
$rows = array();
$rows[] = "| {$head_type} | {$head_desc} |";
$rows[] = '|--------------|--------------|';
foreach ($messages as $message) {
$description = HarbormasterMessageType::getMessageDescription($message);
$rows[] = "| `{$message}` | {$description} |";
}
$message_table = implode("\n", $rows);
$content = pht(<<<EOREMARKUP
If you run external builds, you can use this method to publish build results
back into Harbormaster after the external system finishes work (or as it makes
progress).
To report build status or results, you must send a message to the appropriate
Build Target. This table summarizes which object types may receive build status
and result messages:
<table>
<tr>
<th>Object Type</th>
<th>PHID Example</th>
<th />
<th>Description</th>
</tr>
<tr>
<td>Harbormaster Buildable</td>
<td>`PHID-HMBB-...`</td>
<td>{icon times color=red}</td>
<td>Buildables may **NOT** receive status or result messages.</td>
</tr>
<tr>
<td>Harbormaster Build</td>
<td>`PHID-HMBD-...`</td>
<td>{icon times color=red}</td>
<td>Builds may **NOT** receive status or result messages.</td>
</tr>
<tr>
<td>Harbormaster Build Target</td>
<td>`PHID-HMBT-...`</td>
<td>{icon check color=green}</td>
<td>Report build status and results to Build Targets.</td>
</tr>
</table>
The simplest way to use this method to report build results is to call it once
after the build finishes with a `pass` or `fail` message. This will record the
build result, and continue the next step in the build if the build was waiting
for a result.
When you send a status message about a build target, you can optionally include
detailed `lint` or `unit` results alongside the message. See below for details.
If you want to report intermediate results but a build hasn't completed yet,
you can use the `work` message. This message doesn't have any direct effects,
but allows you to send additional data to update the progress of the build
target. The target will continue waiting for a completion message, but the UI
will update to show the progress which has been made.
When sending a message to a build target to report the status or results of
a build, your message must include a `type` which describes the overall state
of the build. For example, use `pass` to tell Harbormaster that a build target
completed successfully.
Supported message types are:
%s
EOREMARKUP
,
$message_table);
$title = pht('Updating Build Targets');
$content = $this->newRemarkupDocumentationView($content);
return $this->newDocumentationBoxPage($viewer, $title, $content)
->setAnchor('targets')
->setIconIcon('fa-bullseye');
}
private function newUnitDocumentationBoxPage(PhabricatorUser $viewer) {
$head_key = pht('Key');
$head_desc = pht('Description');
$head_name = pht('Name');
$head_type = pht('Type');
$rows = array();
$rows[] = "| {$head_key} | {$head_type} | {$head_desc} |";
$rows[] = '|-------------|--------------|--------------|';
$unit_spec = HarbormasterBuildUnitMessage::getParameterSpec();
foreach ($unit_spec as $key => $parameter) {
$type = idx($parameter, 'type');
$type = str_replace('|', ' '.pht('or').' ', $type);
$description = idx($parameter, 'description');
$rows[] = "| `{$key}` | //{$type}// | {$description} |";
}
$unit_table = implode("\n", $rows);
$rows = array();
$rows[] = "| {$head_key} | {$head_name} | {$head_desc} |";
$rows[] = '|-------------|--------------|--------------|';
$results = ArcanistUnitTestResult::getAllResultCodes();
foreach ($results as $result_code) {
$name = ArcanistUnitTestResult::getResultCodeName($result_code);
$description = ArcanistUnitTestResult::getResultCodeDescription(
$result_code);
$rows[] = "| `{$result_code}` | **{$name}** | {$description} |";
}
$result_table = implode("\n", $rows);
$valid_unit = array(
array(
'name' => 'PassingTest',
'result' => ArcanistUnitTestResult::RESULT_PASS,
),
array(
'name' => 'FailingTest',
'result' => ArcanistUnitTestResult::RESULT_FAIL,
),
);
$json = new PhutilJSON();
$valid_unit = $json->encodeAsList($valid_unit);
$title = pht('Reporting Unit Results');
$content = pht(<<<EOREMARKUP
You can report test results when updating the state of a build target. The
simplest way to do this is to report all the results alongside a `pass` or
`fail` message, but you can also send a `work` message to report intermediate
results.
To provide unit test results, pass a list of results in the `unit`
parameter. Each result should be a dictionary with these keys:
%s
The `result` parameter recognizes these test results:
%s
This is a simple, valid value for the `unit` parameter. It reports one passing
test and one failing test:
```lang=json
%s
```
EOREMARKUP
,
$unit_table,
$result_table,
$valid_unit);
$content = $this->newRemarkupDocumentationView($content);
return $this->newDocumentationBoxPage($viewer, $title, $content)
->setAnchor('unit');
}
private function newLintDocumentationBoxPage(PhabricatorUser $viewer) {
$head_key = pht('Key');
$head_desc = pht('Description');
$head_name = pht('Name');
$head_type = pht('Type');
$rows = array();
$rows[] = "| {$head_key} | {$head_type} | {$head_desc} |";
$rows[] = '|-------------|--------------|--------------|';
$lint_spec = HarbormasterBuildLintMessage::getParameterSpec();
foreach ($lint_spec as $key => $parameter) {
$type = idx($parameter, 'type');
$type = str_replace('|', ' '.pht('or').' ', $type);
$description = idx($parameter, 'description');
$rows[] = "| `{$key}` | //{$type}// | {$description} |";
}
$lint_table = implode("\n", $rows);
$rows = array();
$rows[] = "| {$head_key} | {$head_name} |";
$rows[] = '|-------------|--------------|';
$severities = ArcanistLintSeverity::getLintSeverities();
foreach ($severities as $key => $name) {
$rows[] = "| `{$key}` | **{$name}** |";
}
$severity_table = implode("\n", $rows);
$valid_lint = array(
array(
'name' => pht('Syntax Error'),
'code' => 'EXAMPLE1',
'severity' => ArcanistLintSeverity::SEVERITY_ERROR,
'path' => 'path/to/example.c',
'line' => 17,
'char' => 3,
),
array(
'name' => pht('Not A Haiku'),
'code' => 'EXAMPLE2',
'severity' => ArcanistLintSeverity::SEVERITY_ERROR,
'path' => 'path/to/source.cpp',
'line' => 23,
'char' => 1,
'description' => pht(
'This function definition is not a haiku.'),
),
);
$json = new PhutilJSON();
$valid_lint = $json->encodeAsList($valid_lint);
$title = pht('Reporting Lint Results');
$content = pht(<<<EOREMARKUP
Like unit test results, you can report lint results when updating the state
of a build target. The `lint` parameter should contain results as a list of
dictionaries with these keys:
%s
The `severity` parameter recognizes these severity levels:
%s
This is a simple, valid value for the `lint` parameter. It reports one error
and one warning:
```lang=json
%s
```
EOREMARKUP
,
$lint_table,
$severity_table,
$valid_lint);
$content = $this->newRemarkupDocumentationView($content);
return $this->newDocumentationBoxPage($viewer, $title, $content)
->setAnchor('lint');
}
protected function defineParamTypes() {
$messages = HarbormasterMessageType::getAllMessages();
$more_messages = HarbormasterBuildMessageTransaction::getAllMessages();
$more_messages = mpull($more_messages, 'getHarbormasterBuildMessageType');
$messages = array_merge($messages, $more_messages);
$messages = array_unique($messages);
sort($messages);
$type_const = $this->formatStringConstants($messages);
return array(
'receiver' => 'required string|phid',
'type' => 'required '.$type_const,
'unit' => 'optional list<wild>',
'lint' => 'optional list<wild>',
'buildTargetPHID' => 'deprecated optional phid',
);
}
protected function defineReturnType() {
return 'void';
}
protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getViewer();
$receiver_name = $request->getValue('receiver');
$build_target_phid = $request->getValue('buildTargetPHID');
if ($build_target_phid !== null) {
if ($receiver_name === null) {
$receiver_name = $build_target_phid;
} else {
throw new Exception(
pht(
'Call specifies both "receiver" and "buildTargetPHID". '.
'When using the modern "receiver" parameter, omit the '.
'deprecated "buildTargetPHID" parameter.'));
}
}
if ($receiver_name === null || !strlen($receiver_name)) {
throw new Exception(
pht(
'Call omits required "receiver" parameter. Specify the PHID '.
'of the object you want to send a message to.'));
}
$message_type = $request->getValue('type');
if ($message_type === null || !strlen($message_type)) {
throw new Exception(
pht(
'Call omits required "type" parameter. Specify the type of '.
'message you want to send.'));
}
$receiver_object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withNames(array($receiver_name))
->executeOne();
if (!$receiver_object) {
throw new Exception(
pht(
'Unable to load object "%s" to receive message.',
$receiver_name));
}
$is_target = ($receiver_object instanceof HarbormasterBuildTarget);
if ($is_target) {
return $this->sendToTarget($request, $message_type, $receiver_object);
}
if ($request->getValue('unit') !== null) {
throw new Exception(
pht(
'Call includes "unit" parameter. This parameter must be omitted '.
'when the receiver is not a Build Target.'));
}
if ($request->getValue('lint') !== null) {
throw new Exception(
pht(
'Call includes "lint" parameter. This parameter must be omitted '.
'when the receiver is not a Build Target.'));
}
$is_build = ($receiver_object instanceof HarbormasterBuild);
if ($is_build) {
return $this->sendToBuild($request, $message_type, $receiver_object);
}
$is_buildable = ($receiver_object instanceof HarbormasterBuildable);
if ($is_buildable) {
return $this->sendToBuildable($request, $message_type, $receiver_object);
}
throw new Exception(
pht(
'Receiver object (of class "%s") is not a valid receiver.',
get_class($receiver_object)));
}
private function sendToTarget(
ConduitAPIRequest $request,
$message_type,
HarbormasterBuildTarget $build_target) {
$viewer = $request->getViewer();
$save = array();
$lint_messages = $request->getValue('lint', array());
foreach ($lint_messages as $lint) {
$save[] = HarbormasterBuildLintMessage::newFromDictionary(
$build_target,
$lint);
}
$unit_messages = $request->getValue('unit', array());
foreach ($unit_messages as $unit) {
$save[] = HarbormasterBuildUnitMessage::newFromDictionary(
$build_target,
$unit);
}
$save[] = HarbormasterBuildMessage::initializeNewMessage($viewer)
->setReceiverPHID($build_target->getPHID())
->setType($message_type);
$build_target->openTransaction();
foreach ($save as $object) {
$object->save();
}
$build_target->saveTransaction();
// If the build has completely paused because all steps are blocked on
// waiting targets, this will resume it.
$build = $build_target->getBuild();
PhabricatorWorker::scheduleTask(
'HarbormasterBuildWorker',
array(
'buildID' => $build->getID(),
),
array(
'objectPHID' => $build->getPHID(),
));
return null;
}
private function sendToBuild(
ConduitAPIRequest $request,
$message_type,
HarbormasterBuild $build) {
$viewer = $request->getViewer();
$xaction =
HarbormasterBuildMessageTransaction::getTransactionObjectForMessageType(
$message_type);
if (!$xaction) {
throw new Exception(
pht(
'Message type "%s" is not supported.',
$message_type));
}
// NOTE: This is a slightly weaker check than we perform in the web UI.
// We allow API callers to send a "pause" message to a pausing build,
// for example, even though the message will have no effect.
$xaction->assertCanApplyMessage($viewer, $build);
$build->sendMessage($viewer, $xaction->getHarbormasterBuildMessageType());
}
private function sendToBuildable(
ConduitAPIRequest $request,
$message_type,
HarbormasterBuildable $buildable) {
$viewer = $request->getViewer();
$xaction =
HarbormasterBuildMessageTransaction::getTransactionObjectForMessageType(
$message_type);
if (!$xaction) {
throw new Exception(
pht(
'Message type "%s" is not supported.',
$message_type));
}
// Reload the Buildable to load Builds.
$buildable = id(new HarbormasterBuildableQuery())
->setViewer($viewer)
->withIDs(array($buildable->getID()))
->needBuilds(true)
->executeOne();
$can_send = array();
foreach ($buildable->getBuilds() as $build) {
if ($xaction->canApplyMessage($viewer, $build)) {
$can_send[] = $build;
}
}
// NOTE: This doesn't actually apply a transaction to the Buildable,
// but that transaction is purely informational and should probably be
// implemented as a Message.
foreach ($can_send as $build) {
$build->sendMessage($viewer, $xaction->getHarbormasterBuildMessageType());
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterConduitAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterConduitAPIMethod.php | <?php
abstract class HarbormasterConduitAPIMethod extends ConduitAPIMethod {
final public function getApplication() {
return PhabricatorApplication::getByClass(
'PhabricatorHarbormasterApplication');
}
protected function returnArtifactList(array $artifacts) {
$list = array();
foreach ($artifacts as $artifact) {
$list[] = array(
'phid' => $artifact->getPHID(),
);
}
return $list;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterQueryBuildablesConduitAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterQueryBuildablesConduitAPIMethod.php | <?php
final class HarbormasterQueryBuildablesConduitAPIMethod
extends HarbormasterConduitAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.querybuildables';
}
public function getMethodDescription() {
return pht('Query Harbormaster buildables.');
}
protected function defineParamTypes() {
return array(
'ids' => 'optional list<id>',
'phids' => 'optional list<phid>',
'buildablePHIDs' => 'optional list<phid>',
'containerPHIDs' => 'optional list<phid>',
'manualBuildables' => 'optional bool',
) + self::getPagerParamTypes();
}
protected function defineReturnType() {
return 'wild';
}
protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getUser();
$query = id(new HarbormasterBuildableQuery())
->setViewer($viewer);
$ids = $request->getValue('ids');
if ($ids !== null) {
$query->withIDs($ids);
}
$phids = $request->getValue('phids');
if ($phids !== null) {
$query->withPHIDs($phids);
}
$buildable_phids = $request->getValue('buildablePHIDs');
if ($buildable_phids !== null) {
$query->withBuildablePHIDs($buildable_phids);
}
$container_phids = $request->getValue('containerPHIDs');
if ($container_phids !== null) {
$query->withContainerPHIDs($container_phids);
}
$manual = $request->getValue('manualBuildables');
if ($manual !== null) {
$query->withManualBuildables($manual);
}
$pager = $this->newPager($request);
$buildables = $query->executeWithCursorPager($pager);
$data = array();
foreach ($buildables as $buildable) {
$monogram = $buildable->getMonogram();
$status = $buildable->getBuildableStatus();
$status_name = $buildable->getStatusDisplayName();
$data[] = array(
'id' => $buildable->getID(),
'phid' => $buildable->getPHID(),
'monogram' => $monogram,
'uri' => PhabricatorEnv::getProductionURI('/'.$monogram),
'buildableStatus' => $status,
'buildableStatusName' => $status_name,
'buildablePHID' => $buildable->getBuildablePHID(),
'containerPHID' => $buildable->getContainerPHID(),
'isManualBuildable' => (bool)$buildable->getIsManualBuildable(),
);
}
$results = array(
'data' => $data,
);
$results = $this->addPagerResults($results, $pager);
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterArtifactSearchConduitAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterArtifactSearchConduitAPIMethod.php | <?php
final class HarbormasterArtifactSearchConduitAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.artifact.search';
}
public function newSearchEngine() {
return new HarbormasterArtifactSearchEngine();
}
public function getMethodSummary() {
return pht('Query information about build artifacts.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterBuildPlanEditAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterBuildPlanEditAPIMethod.php | <?php
final class HarbormasterBuildPlanEditAPIMethod
extends PhabricatorEditEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.buildplan.edit';
}
public function newEditEngine() {
return new HarbormasterBuildPlanEditEngine();
}
public function getMethodSummary() {
return pht(
'Apply transactions to create a new build plan or edit an existing '.
'one.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterBuildStepSearchAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterBuildStepSearchAPIMethod.php | <?php
final class HarbormasterBuildStepSearchAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.step.search';
}
public function newSearchEngine() {
return new HarbormasterBuildStepSearchEngine();
}
public function getMethodSummary() {
return pht('Retrieve information about Harbormaster build steps.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterBuildPlanSearchAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterBuildPlanSearchAPIMethod.php | <?php
final class HarbormasterBuildPlanSearchAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.buildplan.search';
}
public function newSearchEngine() {
return new HarbormasterBuildPlanSearchEngine();
}
public function getMethodSummary() {
return pht('Retrieve information about Harbormaster build plans.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterBuildEditAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterBuildEditAPIMethod.php | <?php
final class HarbormasterBuildEditAPIMethod
extends PhabricatorEditEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.build.edit';
}
public function newEditEngine() {
return new HarbormasterBuildEditEngine();
}
public function getMethodSummary() {
return pht(
'Apply transactions to create a new build or edit an existing '.
'one.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterBuildLogSearchConduitAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterBuildLogSearchConduitAPIMethod.php | <?php
final class HarbormasterBuildLogSearchConduitAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.log.search';
}
public function newSearchEngine() {
return new HarbormasterBuildLogSearchEngine();
}
public function getMethodSummary() {
return pht('Find out information about build logs.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterCreateArtifactConduitAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterCreateArtifactConduitAPIMethod.php | <?php
final class HarbormasterCreateArtifactConduitAPIMethod
extends HarbormasterConduitAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.createartifact';
}
public function getMethodSummary() {
return pht('Create a build artifact.');
}
public function getMethodDescription() {
$types = HarbormasterArtifact::getAllArtifactTypes();
$types = msort($types, 'getArtifactTypeName');
$head_key = pht('Key');
$head_type = pht('Type');
$head_desc = pht('Description');
$head_atype = pht('Artifact Type');
$head_name = pht('Name');
$head_summary = pht('Summary');
$out = array();
$out[] = pht(
'Use this method to attach artifacts to build targets while running '.
'builds. Artifacts can be used to carry data through a complex build '.
'workflow, provide extra information to users, or store build results.');
$out[] = null;
$out[] = pht(
'When creating an artifact, you will choose an `artifactType` from '.
'this table. These types of artifacts are supported:');
$out[] = "| {$head_atype} | {$head_name} | {$head_summary} |";
$out[] = '|-------------|--------------|--------------|';
foreach ($types as $type) {
$type_name = $type->getArtifactTypeName();
$type_const = $type->getArtifactConstant();
$type_summary = $type->getArtifactTypeSummary();
$out[] = "| `{$type_const}` | **{$type_name}** | {$type_summary} |";
}
$out[] = null;
$out[] = pht(
'Each artifact also needs an `artifactKey`, which names the artifact. '.
'Finally, you will provide some `artifactData` to fill in the content '.
'of the artifact. The data you provide depends on what type of artifact '.
'you are creating.');
foreach ($types as $type) {
$type_name = $type->getArtifactTypeName();
$type_const = $type->getArtifactConstant();
$out[] = $type_name;
$out[] = '--------------------------';
$out[] = null;
$out[] = $type->getArtifactTypeDescription();
$out[] = null;
$out[] = pht(
'Create an artifact of this type by passing `%s` as the '.
'`artifactType`. When creating an artifact of this type, provide '.
'these parameters as a dictionary to `artifactData`:',
$type_const);
$spec = $type->getArtifactParameterSpecification();
$desc = $type->getArtifactParameterDescriptions();
$out[] = "| {$head_key} | {$head_type} | {$head_desc} |";
$out[] = '|-------------|--------------|--------------|';
foreach ($spec as $key => $key_type) {
$key_desc = idx($desc, $key);
$out[] = "| `{$key}` | //{$key_type}// | {$key_desc} |";
}
$example = $type->getArtifactDataExample();
if ($example !== null) {
$json = new PhutilJSON();
$rendered = $json->encodeFormatted($example);
$out[] = pht('For example:');
$out[] = '```lang=json';
$out[] = $rendered;
$out[] = '```';
}
}
return implode("\n", $out);
}
protected function defineParamTypes() {
return array(
'buildTargetPHID' => 'phid',
'artifactKey' => 'string',
'artifactType' => 'string',
'artifactData' => 'map<string, wild>',
);
}
protected function defineReturnType() {
return 'wild';
}
protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getUser();
$build_target_phid = $request->getValue('buildTargetPHID');
$build_target = id(new HarbormasterBuildTargetQuery())
->setViewer($viewer)
->withPHIDs(array($build_target_phid))
->executeOne();
if (!$build_target) {
throw new Exception(
pht(
'No such build target "%s"!',
$build_target_phid));
}
$artifact_type = $request->getValue('artifactType');
// Cast "artifactData" parameters to acceptable types if this request
// is submitting raw HTTP parameters. This is not ideal. See T11887 for
// discussion.
$artifact_data = $request->getValue('artifactData');
if (!$request->getIsStrictlyTyped()) {
$impl = HarbormasterArtifact::getArtifactType($artifact_type);
if ($impl) {
foreach ($artifact_data as $key => $value) {
$artifact_data[$key] = $impl->readArtifactHTTPParameter(
$key,
$value);
}
}
}
$artifact = $build_target->createArtifact(
$viewer,
$request->getValue('artifactKey'),
$artifact_type,
$artifact_data);
return array(
'data' => $this->returnArtifactList(array($artifact)),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterBuildSearchConduitAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterBuildSearchConduitAPIMethod.php | <?php
final class HarbormasterBuildSearchConduitAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.build.search';
}
public function newSearchEngine() {
return new HarbormasterBuildSearchEngine();
}
public function getMethodSummary() {
return pht('Find out information about builds.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterQueryAutotargetsConduitAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterQueryAutotargetsConduitAPIMethod.php | <?php
final class HarbormasterQueryAutotargetsConduitAPIMethod
extends HarbormasterConduitAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.queryautotargets';
}
public function getMethodDescription() {
return pht('Load or create build autotargets.');
}
protected function defineParamTypes() {
return array(
'objectPHID' => 'phid',
'targetKeys' => 'list<string>',
);
}
protected function defineReturnType() {
return 'map<string, phid>';
}
protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getUser();
$phid = $request->getValue('objectPHID');
// NOTE: We use withNames() to let monograms like "D123" work, which makes
// this a little easier to test. Real PHIDs will still work as expected.
$object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withNames(array($phid))
->executeOne();
if (!$object) {
throw new Exception(
pht(
'No such object "%s" exists.',
$phid));
}
if (!($object instanceof HarbormasterBuildableInterface)) {
throw new Exception(
pht(
'Object "%s" does not implement interface "%s". Autotargets may '.
'only be queried for buildable objects.',
$phid,
'HarbormasterBuildableInterface'));
}
$autotargets = $request->getValue('targetKeys', array());
if ($autotargets) {
$targets = id(new HarbormasterTargetEngine())
->setViewer($viewer)
->setObject($object)
->setAutoTargetKeys($autotargets)
->buildTargets();
} else {
$targets = array();
}
// Reorder the results according to the request order so we can make test
// assertions that subsequent calls return the same results.
$map = mpull($targets, 'getPHID');
$map = array_select_keys($map, $autotargets);
return array(
'targetMap' => $map,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterBuildStepEditAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterBuildStepEditAPIMethod.php | <?php
final class HarbormasterBuildStepEditAPIMethod
extends PhabricatorEditEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.step.edit';
}
public function newEditEngine() {
return new HarbormasterBuildStepEditEngine();
}
public function getMethodSummary() {
return pht(
'Apply transactions to create a new build step or edit an existing '.
'one.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterBuildableEditAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterBuildableEditAPIMethod.php | <?php
final class HarbormasterBuildableEditAPIMethod
extends PhabricatorEditEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.buildable.edit';
}
public function newEditEngine() {
return new HarbormasterBuildableEditEngine();
}
public function getMethodSummary() {
return pht(
'Apply transactions to create a new buildable or edit an existing '.
'one.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterTargetSearchAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterTargetSearchAPIMethod.php | <?php
final class HarbormasterTargetSearchAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.target.search';
}
public function newSearchEngine() {
return new HarbormasterBuildTargetSearchEngine();
}
public function getMethodSummary() {
return pht('Retrieve information about Harbormaster build targets.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/conduit/HarbormasterQueryBuildsConduitAPIMethod.php | src/applications/harbormaster/conduit/HarbormasterQueryBuildsConduitAPIMethod.php | <?php
final class HarbormasterQueryBuildsConduitAPIMethod
extends HarbormasterConduitAPIMethod {
public function getAPIMethodName() {
return 'harbormaster.querybuilds';
}
public function getMethodDescription() {
return pht('Query Harbormaster builds.');
}
public function getMethodStatus() {
return self::METHOD_STATUS_DEPRECATED;
}
public function getMethodStatusDescription() {
return pht('Use %s instead.', 'harbormaster.build.search');
}
protected function defineParamTypes() {
return array(
'ids' => 'optional list<id>',
'phids' => 'optional list<phid>',
'buildStatuses' => 'optional list<string>',
'buildablePHIDs' => 'optional list<phid>',
'buildPlanPHIDs' => 'optional list<phid>',
) + self::getPagerParamTypes();
}
protected function defineReturnType() {
return 'wild';
}
protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getUser();
$call = new ConduitCall(
'harbormaster.build.search',
array_filter(array(
'constraints' => array_filter(array(
'ids' => $request->getValue('ids'),
'phids' => $request->getValue('phids'),
'statuses' => $request->getValue('buildStatuses'),
'buildables' => $request->getValue('buildablePHIDs'),
'plans' => $request->getValue('buildPlanPHIDs'),
)),
'attachments' => array(
'querybuilds' => true,
),
'limit' => $request->getValue('limit'),
'before' => $request->getValue('before'),
'after' => $request->getValue('after'),
)));
$subsumption = $call->setUser($viewer)
->execute();
$data = array();
foreach ($subsumption['data'] as $build_data) {
$querybuilds = idxv(
$build_data,
array('attachments', 'querybuilds'),
array());
$fields = idx($build_data, 'fields', array());
unset($build_data['fields']);
unset($build_data['attachments']);
// To retain backward compatibility, remove newer keys from the
// result array.
$fields['buildStatus'] = array_select_keys(
$fields['buildStatus'],
array(
'value',
'name',
));
$data[] = array_mergev(array($build_data, $querybuilds, $fields));
}
$subsumption['data'] = $data;
return $subsumption;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/engine/HarbormasterBuildGraph.php | src/applications/harbormaster/engine/HarbormasterBuildGraph.php | <?php
/**
* Directed graph representing a build plan
*/
final class HarbormasterBuildGraph extends AbstractDirectedGraph {
private $stepMap;
public static function determineDependencyExecution(
HarbormasterBuildPlan $plan) {
$steps = id(new HarbormasterBuildStepQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withBuildPlanPHIDs(array($plan->getPHID()))
->execute();
$steps_by_phid = mpull($steps, null, 'getPHID');
$step_phids = mpull($steps, 'getPHID');
if (count($steps) === 0) {
return array();
}
$graph = id(new HarbormasterBuildGraph($steps_by_phid))
->addNodes($step_phids);
$raw_results = $graph->getNodesInRoughTopologicalOrder();
$results = array();
foreach ($raw_results as $node) {
$results[] = array(
'node' => $steps_by_phid[$node['node']],
'depth' => $node['depth'],
'cycle' => $node['cycle'],
);
}
return $results;
}
public function __construct($step_map) {
$this->stepMap = $step_map;
}
protected function loadEdges(array $nodes) {
$map = array();
foreach ($nodes as $node) {
$step = $this->stepMap[$node];
try {
$deps = $step->getStepImplementation()->getDependencies($step);
} catch (Exception $ex) {
$deps = array();
}
$map[$node] = array();
foreach ($deps as $dep) {
$map[$node][] = $dep;
}
}
return $map;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/engine/HarbormasterBuildableEngine.php | src/applications/harbormaster/engine/HarbormasterBuildableEngine.php | <?php
abstract class HarbormasterBuildableEngine
extends Phobject {
private $viewer;
private $actingAsPHID;
private $contentSource;
private $object;
final public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
final public function getViewer() {
return $this->viewer;
}
final public function setActingAsPHID($acting_as_phid) {
$this->actingAsPHID = $acting_as_phid;
return $this;
}
final public function getActingAsPHID() {
return $this->actingAsPHID;
}
final public function setContentSource(
PhabricatorContentSource $content_source) {
$this->contentSource = $content_source;
return $this;
}
final public function getContentSource() {
return $this->contentSource;
}
final public function setObject(HarbormasterBuildableInterface $object) {
$this->object = $object;
return $this;
}
final public function getObject() {
return $this->object;
}
protected function getPublishableObject() {
return $this->getObject();
}
public function publishBuildable(
HarbormasterBuildable $old,
HarbormasterBuildable $new) {
return;
}
final public static function newForObject(
HarbormasterBuildableInterface $object,
PhabricatorUser $viewer) {
return $object->newBuildableEngine()
->setViewer($viewer)
->setObject($object);
}
final protected function newEditor() {
$publishable = $this->getPublishableObject();
$viewer = $this->getViewer();
$editor = $publishable->getApplicationTransactionEditor()
->setActor($viewer)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
$acting_as_phid = $this->getActingAsPHID();
if ($acting_as_phid !== null) {
$editor->setActingAsPHID($acting_as_phid);
}
$content_source = $this->getContentSource();
if ($content_source !== null) {
$editor->setContentSource($content_source);
}
return $editor;
}
final protected function newTransaction() {
$publishable = $this->getPublishableObject();
return $publishable->getApplicationTransactionTemplate();
}
final protected function applyTransactions(array $xactions) {
$publishable = $this->getPublishableObject();
$editor = $this->newEditor();
$editor->applyTransactions($publishable, $xactions);
}
public function getAuthorIdentity() {
return null;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/engine/HarbormasterBuildEngine.php | src/applications/harbormaster/engine/HarbormasterBuildEngine.php | <?php
/**
* Moves a build forward by queuing build tasks, canceling or restarting the
* build, or failing it in response to task failures.
*/
final class HarbormasterBuildEngine extends Phobject {
private $build;
private $viewer;
private $newBuildTargets = array();
private $artifactReleaseQueue = array();
private $forceBuildableUpdate;
public function setForceBuildableUpdate($force_buildable_update) {
$this->forceBuildableUpdate = $force_buildable_update;
return $this;
}
public function shouldForceBuildableUpdate() {
return $this->forceBuildableUpdate;
}
public function queueNewBuildTarget(HarbormasterBuildTarget $target) {
$this->newBuildTargets[] = $target;
return $this;
}
public function getNewBuildTargets() {
return $this->newBuildTargets;
}
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function setBuild(HarbormasterBuild $build) {
$this->build = $build;
return $this;
}
public function getBuild() {
return $this->build;
}
public function continueBuild() {
$viewer = $this->getViewer();
$build = $this->getBuild();
$lock_key = 'harbormaster.build:'.$build->getID();
$lock = PhabricatorGlobalLock::newLock($lock_key)->lock(15);
$build->reload();
$old_status = $build->getBuildStatus();
try {
$this->updateBuild($build);
} catch (Exception $ex) {
// If any exception is raised, the build is marked as a failure and the
// exception is re-thrown (this ensures we don't leave builds in an
// inconsistent state).
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_ERROR);
$build->save();
$lock->unlock();
$build->releaseAllArtifacts($viewer);
throw $ex;
}
$lock->unlock();
// NOTE: We queue new targets after releasing the lock so that in-process
// execution via `bin/harbormaster` does not reenter the locked region.
foreach ($this->getNewBuildTargets() as $target) {
$task = PhabricatorWorker::scheduleTask(
'HarbormasterTargetWorker',
array(
'targetID' => $target->getID(),
),
array(
'objectPHID' => $target->getPHID(),
));
}
// If the build changed status, we might need to update the overall status
// on the buildable.
$new_status = $build->getBuildStatus();
if ($new_status != $old_status || $this->shouldForceBuildableUpdate()) {
$this->updateBuildable($build->getBuildable());
}
$this->releaseQueuedArtifacts();
// If we are no longer building for any reason, release all artifacts.
if (!$build->isBuilding()) {
$build->releaseAllArtifacts($viewer);
}
}
private function updateBuild(HarbormasterBuild $build) {
$viewer = $this->getViewer();
$content_source = PhabricatorContentSource::newForSource(
PhabricatorDaemonContentSource::SOURCECONST);
$acting_phid = $viewer->getPHID();
if (!$acting_phid) {
$acting_phid = id(new PhabricatorHarbormasterApplication())->getPHID();
}
$editor = $build->getApplicationTransactionEditor()
->setActor($viewer)
->setActingAsPHID($acting_phid)
->setContentSource($content_source)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
$xactions = array();
$messages = $build->getUnprocessedMessagesForApply();
foreach ($messages as $message) {
$message_type = $message->getType();
$message_xaction =
HarbormasterBuildMessageTransaction::getTransactionTypeForMessageType(
$message_type);
if (!$message_xaction) {
continue;
}
$xactions[] = $build->getApplicationTransactionTemplate()
->setAuthorPHID($message->getAuthorPHID())
->setTransactionType($message_xaction)
->setNewValue($message_type);
}
if (!$xactions) {
if ($build->isPending()) {
// TODO: This should be a transaction.
$build->restartBuild($viewer);
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING);
$build->save();
}
}
if ($xactions) {
$editor->applyTransactions($build, $xactions);
$build->markUnprocessedMessagesAsProcessed();
}
if ($build->getBuildStatus() == HarbormasterBuildStatus::STATUS_BUILDING) {
$this->updateBuildSteps($build);
}
}
private function updateBuildSteps(HarbormasterBuild $build) {
$all_targets = id(new HarbormasterBuildTargetQuery())
->setViewer($this->getViewer())
->withBuildPHIDs(array($build->getPHID()))
->withBuildGenerations(array($build->getBuildGeneration()))
->execute();
$this->updateWaitingTargets($all_targets);
$targets = mgroup($all_targets, 'getBuildStepPHID');
$steps = id(new HarbormasterBuildStepQuery())
->setViewer($this->getViewer())
->withBuildPlanPHIDs(array($build->getBuildPlan()->getPHID()))
->execute();
$steps = mpull($steps, null, 'getPHID');
// Identify steps which are in various states.
$queued = array();
$underway = array();
$waiting = array();
$complete = array();
$failed = array();
foreach ($steps as $step) {
$step_targets = idx($targets, $step->getPHID(), array());
if ($step_targets) {
$is_queued = false;
$is_underway = false;
foreach ($step_targets as $target) {
if ($target->isUnderway()) {
$is_underway = true;
break;
}
}
$is_waiting = false;
foreach ($step_targets as $target) {
if ($target->isWaiting()) {
$is_waiting = true;
break;
}
}
$is_complete = true;
foreach ($step_targets as $target) {
if (!$target->isComplete()) {
$is_complete = false;
break;
}
}
$is_failed = false;
foreach ($step_targets as $target) {
if ($target->isFailed()) {
$is_failed = true;
break;
}
}
} else {
$is_queued = true;
$is_underway = false;
$is_waiting = false;
$is_complete = false;
$is_failed = false;
}
if ($is_queued) {
$queued[$step->getPHID()] = true;
}
if ($is_underway) {
$underway[$step->getPHID()] = true;
}
if ($is_waiting) {
$waiting[$step->getPHID()] = true;
}
if ($is_complete) {
$complete[$step->getPHID()] = true;
}
if ($is_failed) {
$failed[$step->getPHID()] = true;
}
}
// If any step failed, fail the whole build, then bail.
if (count($failed)) {
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_FAILED);
$build->save();
return;
}
// If every step is complete, we're done with this build. Mark it passed
// and bail.
if (count($complete) == count($steps)) {
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_PASSED);
$build->save();
return;
}
// Release any artifacts which are not inputs to any remaining build
// step. We're done with these, so something else is free to use them.
$ongoing_phids = array_keys($queued + $waiting + $underway);
$ongoing_steps = array_select_keys($steps, $ongoing_phids);
$this->releaseUnusedArtifacts($all_targets, $ongoing_steps);
// Identify all the steps which are ready to run (because all their
// dependencies are complete).
$runnable = array();
foreach ($steps as $step) {
$dependencies = $step->getStepImplementation()->getDependencies($step);
if (isset($queued[$step->getPHID()])) {
$can_run = true;
foreach ($dependencies as $dependency) {
if (empty($complete[$dependency])) {
$can_run = false;
break;
}
}
if ($can_run) {
$runnable[] = $step;
}
}
}
if (!$runnable && !$waiting && !$underway) {
// This means the build is deadlocked, and the user has configured
// circular dependencies.
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_DEADLOCKED);
$build->save();
return;
}
foreach ($runnable as $runnable_step) {
$target = HarbormasterBuildTarget::initializeNewBuildTarget(
$build,
$runnable_step,
$build->retrieveVariablesFromBuild());
$target->save();
$this->queueNewBuildTarget($target);
}
}
/**
* Release any artifacts which aren't used by any running or waiting steps.
*
* This releases artifacts as soon as they're no longer used. This can be
* particularly relevant when a build uses multiple hosts since it returns
* hosts to the pool more quickly.
*
* @param list<HarbormasterBuildTarget> Targets in the build.
* @param list<HarbormasterBuildStep> List of running and waiting steps.
* @return void
*/
private function releaseUnusedArtifacts(array $targets, array $steps) {
assert_instances_of($targets, 'HarbormasterBuildTarget');
assert_instances_of($steps, 'HarbormasterBuildStep');
if (!$targets || !$steps) {
return;
}
$target_phids = mpull($targets, 'getPHID');
$artifacts = id(new HarbormasterBuildArtifactQuery())
->setViewer($this->getViewer())
->withBuildTargetPHIDs($target_phids)
->withIsReleased(false)
->execute();
if (!$artifacts) {
return;
}
// Collect all the artifacts that remaining build steps accept as inputs.
$must_keep = array();
foreach ($steps as $step) {
$inputs = $step->getStepImplementation()->getArtifactInputs();
foreach ($inputs as $input) {
$artifact_key = $input['key'];
$must_keep[$artifact_key] = true;
}
}
// Queue unreleased artifacts which no remaining step uses for immediate
// release.
foreach ($artifacts as $artifact) {
$key = $artifact->getArtifactKey();
if (isset($must_keep[$key])) {
continue;
}
$this->artifactReleaseQueue[] = $artifact;
}
}
/**
* Process messages which were sent to these targets, kicking applicable
* targets out of "Waiting" and into either "Passed" or "Failed".
*
* @param list<HarbormasterBuildTarget> List of targets to process.
* @return void
*/
private function updateWaitingTargets(array $targets) {
assert_instances_of($targets, 'HarbormasterBuildTarget');
// We only care about messages for targets which are actually in a waiting
// state.
$waiting_targets = array();
foreach ($targets as $target) {
if ($target->isWaiting()) {
$waiting_targets[$target->getPHID()] = $target;
}
}
if (!$waiting_targets) {
return;
}
$messages = id(new HarbormasterBuildMessageQuery())
->setViewer($this->getViewer())
->withReceiverPHIDs(array_keys($waiting_targets))
->withConsumed(false)
->execute();
foreach ($messages as $message) {
$target = $waiting_targets[$message->getReceiverPHID()];
switch ($message->getType()) {
case HarbormasterMessageType::MESSAGE_PASS:
$new_status = HarbormasterBuildTarget::STATUS_PASSED;
break;
case HarbormasterMessageType::MESSAGE_FAIL:
$new_status = HarbormasterBuildTarget::STATUS_FAILED;
break;
case HarbormasterMessageType::MESSAGE_WORK:
default:
$new_status = null;
break;
}
if ($new_status !== null) {
$message->setIsConsumed(true);
$message->save();
$target->setTargetStatus($new_status);
if ($target->isComplete()) {
$target->setDateCompleted(PhabricatorTime::getNow());
}
$target->save();
}
}
}
/**
* Update the overall status of the buildable this build is attached to.
*
* After a build changes state (for example, passes or fails) it may affect
* the overall state of the associated buildable. Compute the new aggregate
* state and save it on the buildable.
*
* @param HarbormasterBuild The buildable to update.
* @return void
*/
public function updateBuildable(HarbormasterBuildable $buildable) {
$viewer = $this->getViewer();
$lock_key = 'harbormaster.buildable:'.$buildable->getID();
$lock = PhabricatorGlobalLock::newLock($lock_key)->lock(15);
$buildable = id(new HarbormasterBuildableQuery())
->setViewer($viewer)
->withIDs(array($buildable->getID()))
->needBuilds(true)
->executeOne();
$messages = id(new HarbormasterBuildMessageQuery())
->setViewer($viewer)
->withReceiverPHIDs(array($buildable->getPHID()))
->withConsumed(false)
->execute();
$done_preparing = false;
$update_container = false;
foreach ($messages as $message) {
switch ($message->getType()) {
case HarbormasterMessageType::BUILDABLE_BUILD:
$done_preparing = true;
break;
case HarbormasterMessageType::BUILDABLE_CONTAINER:
$update_container = true;
break;
default:
break;
}
$message
->setIsConsumed(true)
->save();
}
// If we received a "build" command, all builds are scheduled and we can
// move out of "preparing" into "building".
if ($done_preparing) {
if ($buildable->isPreparing()) {
$buildable
->setBuildableStatus(HarbormasterBuildableStatus::STATUS_BUILDING)
->save();
}
}
// If we've been informed that the container for the buildable has
// changed, update it.
if ($update_container) {
$object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($buildable->getBuildablePHID()))
->executeOne();
if ($object) {
$buildable
->setContainerPHID($object->getHarbormasterContainerPHID())
->save();
}
}
$old = clone $buildable;
// Don't update the buildable status if we're still preparing builds: more
// builds may still be scheduled shortly, so even if every build we know
// about so far has passed, that doesn't mean the buildable has actually
// passed everything it needs to.
if (!$buildable->isPreparing()) {
$behavior_key = HarbormasterBuildPlanBehavior::BEHAVIOR_BUILDABLE;
$behavior = HarbormasterBuildPlanBehavior::getBehavior($behavior_key);
$key_never = HarbormasterBuildPlanBehavior::BUILDABLE_NEVER;
$key_building = HarbormasterBuildPlanBehavior::BUILDABLE_IF_BUILDING;
$all_pass = true;
$any_fail = false;
foreach ($buildable->getBuilds() as $build) {
$plan = $build->getBuildPlan();
$option = $behavior->getPlanOption($plan);
$option_key = $option->getKey();
$is_never = ($option_key === $key_never);
$is_building = ($option_key === $key_building);
// If this build "Never" affects the buildable, ignore it.
if ($is_never) {
continue;
}
// If this build affects the buildable "If Building", but is already
// complete, ignore it.
if ($is_building && $build->isComplete()) {
continue;
}
if (!$build->isPassed()) {
$all_pass = false;
}
if ($build->isComplete() && !$build->isPassed()) {
$any_fail = true;
}
}
if ($any_fail) {
$new_status = HarbormasterBuildableStatus::STATUS_FAILED;
} else if ($all_pass) {
$new_status = HarbormasterBuildableStatus::STATUS_PASSED;
} else {
$new_status = HarbormasterBuildableStatus::STATUS_BUILDING;
}
$did_update = ($old->getBuildableStatus() !== $new_status);
if ($did_update) {
$buildable->setBuildableStatus($new_status);
$buildable->save();
}
}
$lock->unlock();
// Don't publish anything if we're still preparing builds.
if ($buildable->isPreparing()) {
return;
}
$this->publishBuildable($old, $buildable);
}
public function publishBuildable(
HarbormasterBuildable $old,
HarbormasterBuildable $new) {
$viewer = $this->getViewer();
// Publish the buildable. We publish buildables even if they haven't
// changed status in Harbormaster because applications may care about
// different things than Harbormaster does. For example, Differential
// does not care about local lint and unit tests when deciding whether
// a revision should move out of draft or not.
// NOTE: We're publishing both automatic and manual buildables. Buildable
// objects should generally ignore manual buildables, but it's up to them
// to decide.
$object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($new->getBuildablePHID()))
->executeOne();
if (!$object) {
return;
}
$engine = HarbormasterBuildableEngine::newForObject($object, $viewer);
$daemon_source = PhabricatorContentSource::newForSource(
PhabricatorDaemonContentSource::SOURCECONST);
$harbormaster_phid = id(new PhabricatorHarbormasterApplication())
->getPHID();
$engine
->setActingAsPHID($harbormaster_phid)
->setContentSource($daemon_source)
->publishBuildable($old, $new);
}
private function releaseQueuedArtifacts() {
foreach ($this->artifactReleaseQueue as $key => $artifact) {
$artifact->releaseArtifact();
unset($this->artifactReleaseQueue[$key]);
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/engine/HarbormasterBuildRequest.php | src/applications/harbormaster/engine/HarbormasterBuildRequest.php | <?php
/**
* Structure used to ask Harbormaster to start a build.
*
* Requests to start builds sometimes originate several layers away from where
* they are processed. For example, Herald rules which start builds pass the
* requests through the adapter and then through the editor before they reach
* Harbormaster.
*
* This class is just a thin wrapper around these requests so we can make them
* more complex later without needing to rewrite any APIs.
*/
final class HarbormasterBuildRequest extends Phobject {
private $buildPlanPHID;
private $initiatorPHID;
private $buildParameters = array();
public function setBuildPlanPHID($build_plan_phid) {
$this->buildPlanPHID = $build_plan_phid;
return $this;
}
public function getBuildPlanPHID() {
return $this->buildPlanPHID;
}
public function setBuildParameters(array $build_parameters) {
$this->buildParameters = $build_parameters;
return $this;
}
public function getBuildParameters() {
return $this->buildParameters;
}
public function setInitiatorPHID($phid) {
$this->initiatorPHID = $phid;
return $this;
}
public function getInitiatorPHID() {
return $this->initiatorPHID;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/engine/HarbormasterMessageType.php | src/applications/harbormaster/engine/HarbormasterMessageType.php | <?php
final class HarbormasterMessageType extends Phobject {
const MESSAGE_PASS = 'pass';
const MESSAGE_FAIL = 'fail';
const MESSAGE_WORK = 'work';
const BUILDABLE_BUILD = 'build';
const BUILDABLE_CONTAINER = 'container';
public static function getAllMessages() {
return array_keys(self::getMessageSpecifications());
}
public static function getMessageDescription($message) {
$spec = self::getMessageSpecification($message);
if (!$spec) {
return null;
}
return idx($spec, 'description');
}
private static function getMessageSpecification($message) {
$specs = self::getMessageSpecifications();
return idx($specs, $message);
}
private static function getMessageSpecifications() {
return array(
self::MESSAGE_PASS => array(
'description' => pht(
'Report that the target is complete, and the target has passed.'),
),
self::MESSAGE_FAIL => array(
'description' => pht(
'Report that the target is complete, and the target has failed.'),
),
self::MESSAGE_WORK => array(
'description' => pht(
'Report that work on the target is ongoing. This message can be '.
'used to report partial results during a build.'),
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/engine/HarbormasterTargetEngine.php | src/applications/harbormaster/engine/HarbormasterTargetEngine.php | <?php
final class HarbormasterTargetEngine extends Phobject {
private $viewer;
private $object;
private $autoTargetKeys;
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function setObject(HarbormasterBuildableInterface $object) {
$this->object = $object;
return $this;
}
public function getObject() {
return $this->object;
}
public function setAutoTargetKeys(array $auto_keys) {
$this->autoTargetKeys = $auto_keys;
return $this;
}
public function getAutoTargetKeys() {
return $this->autoTargetKeys;
}
public function buildTargets() {
$object = $this->getObject();
$viewer = $this->getViewer();
$step_map = $this->generateBuildStepMap($this->getAutoTargetKeys());
$buildable = HarbormasterBuildable::createOrLoadExisting(
$viewer,
$object->getHarbormasterBuildablePHID(),
$object->getHarbormasterContainerPHID());
$target_map = $this->generateBuildTargetMap($buildable, $step_map);
return $target_map;
}
/**
* Get a map of the @{class:HarbormasterBuildStep} objects for a list of
* autotarget keys.
*
* This method creates the steps if they do not yet exist.
*
* @param list<string> Autotarget keys, like `"core.arc.lint"`.
* @return map<string, object> Map of keys to step objects.
*/
private function generateBuildStepMap(array $autotargets) {
$viewer = $this->getViewer();
$autosteps = $this->getAutosteps($autotargets);
$autosteps = mgroup($autosteps, 'getBuildStepAutotargetPlanKey');
$plans = id(new HarbormasterBuildPlanQuery())
->setViewer($viewer)
->withPlanAutoKeys(array_keys($autosteps))
->needBuildSteps(true)
->execute();
$plans = mpull($plans, null, 'getPlanAutoKey');
// NOTE: When creating the plan and steps, we save the autokeys as the
// names. These won't actually be shown in the UI, but make the data more
// consistent for secondary consumers like typeaheads.
$step_map = array();
foreach ($autosteps as $plan_key => $steps) {
$plan = idx($plans, $plan_key);
if (!$plan) {
$plan = HarbormasterBuildPlan::initializeNewBuildPlan($viewer)
->setName($plan_key)
->setPlanAutoKey($plan_key);
}
$current = $plan->getBuildSteps();
$current = mpull($current, null, 'getStepAutoKey');
$new_steps = array();
foreach ($steps as $step_key => $step) {
if (isset($current[$step_key])) {
$step_map[$step_key] = $current[$step_key];
continue;
}
$new_step = HarbormasterBuildStep::initializeNewStep($viewer)
->setName($step_key)
->setClassName(get_class($step))
->setStepAutoKey($step_key);
$new_steps[$step_key] = $new_step;
}
if ($new_steps) {
$plan->openTransaction();
if (!$plan->getPHID()) {
$plan->save();
}
foreach ($new_steps as $step_key => $step) {
$step->setBuildPlanPHID($plan->getPHID());
$step->save();
$step->attachBuildPlan($plan);
$step_map[$step_key] = $step;
}
$plan->saveTransaction();
}
}
return $step_map;
}
/**
* Get all of the @{class:HarbormasterBuildStepImplementation} objects for
* a list of autotarget keys.
*
* @param list<string> Autotarget keys, like `"core.arc.lint"`.
* @return map<string, object> Map of keys to implementations.
*/
private function getAutosteps(array $autotargets) {
$all_steps = HarbormasterBuildStepImplementation::getImplementations();
$all_steps = mpull($all_steps, null, 'getBuildStepAutotargetStepKey');
// Make sure all the targets really exist.
foreach ($autotargets as $autotarget) {
if (empty($all_steps[$autotarget])) {
throw new Exception(
pht(
'No build step provides autotarget "%s"!',
$autotarget));
}
}
return array_select_keys($all_steps, $autotargets);
}
/**
* Get a list of @{class:HarbormasterBuildTarget} objects for a list of
* autotarget keys.
*
* If some targets or builds do not exist, they are created.
*
* @param HarbormasterBuildable A buildable.
* @param map<string, object> Map of keys to steps.
* @return map<string, object> Map of keys to targets.
*/
private function generateBuildTargetMap(
HarbormasterBuildable $buildable,
array $step_map) {
$viewer = $this->getViewer();
$initiator_phid = null;
if (!$viewer->isOmnipotent()) {
$initiator_phid = $viewer->getPHID();
}
$plan_map = mgroup($step_map, 'getBuildPlanPHID');
$builds = id(new HarbormasterBuildQuery())
->setViewer($viewer)
->withBuildablePHIDs(array($buildable->getPHID()))
->withBuildPlanPHIDs(array_keys($plan_map))
->needBuildTargets(true)
->execute();
$autobuilds = array();
foreach ($builds as $build) {
$plan_key = $build->getBuildPlan()->getPlanAutoKey();
$autobuilds[$plan_key] = $build;
}
$new_builds = array();
foreach ($plan_map as $plan_phid => $steps) {
$plan = head($steps)->getBuildPlan();
$plan_key = $plan->getPlanAutoKey();
$build = idx($autobuilds, $plan_key);
if ($build) {
// We already have a build for this set of targets, so we don't need
// to do any work. (It's possible the build is an older build that
// doesn't have all of the right targets if new autotargets were
// recently introduced, but we don't currently try to construct them.)
continue;
}
// NOTE: Normally, `applyPlan()` does not actually generate targets.
// We need to apply the plan in-process to perform target generation.
// This is fine as long as autotargets are empty containers that don't
// do any work, which they always should be.
PhabricatorWorker::setRunAllTasksInProcess(true);
try {
// NOTE: We might race another process here to create the same build
// with the same `planAutoKey`. The database will prevent this and
// using autotargets only currently makes sense if you just created the
// resource and "own" it, so we don't try to handle this, but may need
// to be more careful here if use of autotargets expands.
$build = $buildable->applyPlan($plan, array(), $initiator_phid);
PhabricatorWorker::setRunAllTasksInProcess(false);
} catch (Exception $ex) {
PhabricatorWorker::setRunAllTasksInProcess(false);
throw $ex;
}
$new_builds[] = $build;
}
if ($new_builds) {
$all_targets = id(new HarbormasterBuildTargetQuery())
->setViewer($viewer)
->withBuildPHIDs(mpull($new_builds, 'getPHID'))
->execute();
} else {
$all_targets = array();
}
foreach ($builds as $build) {
foreach ($build->getBuildTargets() as $target) {
$all_targets[] = $target;
}
}
$target_map = array();
foreach ($all_targets as $target) {
$target_key = $target
->getImplementation()
->getBuildStepAutotargetStepKey();
if (!$target_key) {
continue;
}
$target_map[$target_key] = $target;
}
$target_map = array_select_keys($target_map, array_keys($step_map));
return $target_map;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/typeahead/HarbormasterBuildInitiatorDatasource.php | src/applications/harbormaster/typeahead/HarbormasterBuildInitiatorDatasource.php | <?php
final class HarbormasterBuildInitiatorDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getBrowseTitle() {
return pht('Browse Build Initiators');
}
public function getPlaceholderText() {
return pht('Type the name of a user, application or Herald rule...');
}
public function getComponentDatasources() {
return array(
new PhabricatorApplicationDatasource(),
new PhabricatorPeopleUserFunctionDatasource(),
new HeraldRuleDatasource(),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/typeahead/HarbormasterBuildStatusDatasource.php | src/applications/harbormaster/typeahead/HarbormasterBuildStatusDatasource.php | <?php
final class HarbormasterBuildStatusDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Choose Build Statuses');
}
public function getPlaceholderText() {
return pht('Type a build status name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
public function loadResults() {
$results = $this->buildResults();
return $this->filterResultsAgainstTokens($results);
}
public function renderTokens(array $values) {
return $this->renderTokensFromResults($this->buildResults(), $values);
}
private function buildResults() {
$results = array();
$status_map = HarbormasterBuildStatus::getBuildStatusMap();
foreach ($status_map as $value => $name) {
$result = id(new PhabricatorTypeaheadResult())
->setIcon(HarbormasterBuildStatus::getBuildStatusIcon($value))
->setColor(HarbormasterBuildStatus::getBuildStatusColor($value))
->setPHID($value)
->setName($name)
->addAttribute(pht('Status'));
$results[$value] = $result;
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/typeahead/HarbormasterBuildPlanDatasource.php | src/applications/harbormaster/typeahead/HarbormasterBuildPlanDatasource.php | <?php
final class HarbormasterBuildPlanDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Build Plans');
}
public function getPlaceholderText() {
return pht('Type a build plan name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
public function loadResults() {
$viewer = $this->getViewer();
$raw_query = $this->getRawQuery();
$results = array();
$query = id(new HarbormasterBuildPlanQuery())
->setOrder('name')
->withDatasourceQuery($raw_query);
$plans = $this->executeQuery($query);
foreach ($plans as $plan) {
$closed = null;
if ($plan->isDisabled()) {
$closed = pht('Disabled');
}
$results[] = id(new PhabricatorTypeaheadResult())
->setName($plan->getName())
->setClosed($closed)
->setPHID($plan->getPHID());
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/typeahead/HarbormasterBuildDependencyDatasource.php | src/applications/harbormaster/typeahead/HarbormasterBuildDependencyDatasource.php | <?php
final class HarbormasterBuildDependencyDatasource
extends PhabricatorTypeaheadDatasource {
public function isBrowsable() {
// TODO: This should be browsable, but fixing it is involved.
return false;
}
public function getBrowseTitle() {
return pht('Browse Dependencies');
}
public function getPlaceholderText() {
return pht('Type another build step name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
public function loadResults() {
$viewer = $this->getViewer();
$plan_phid = $this->getParameter('planPHID');
$step_phid = $this->getParameter('stepPHID');
$steps = id(new HarbormasterBuildStepQuery())
->setViewer($viewer)
->withBuildPlanPHIDs(array($plan_phid))
->execute();
$steps = mpull($steps, null, 'getPHID');
if (count($steps) === 0) {
return array();
}
$results = array();
foreach ($steps as $phid => $step) {
if ($step->getPHID() === $step_phid) {
continue;
}
$results[] = id(new PhabricatorTypeaheadResult())
->setName($step->getName())
->setURI('/')
->setPHID($phid);
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/harbormaster/codex/HarbormasterBuildPlanPolicyCodex.php | src/applications/harbormaster/codex/HarbormasterBuildPlanPolicyCodex.php | <?php
final class HarbormasterBuildPlanPolicyCodex
extends PhabricatorPolicyCodex {
public function getPolicySpecialRuleDescriptions() {
$object = $this->getObject();
$run_with_view = $object->canRunWithoutEditCapability();
$rules = array();
$rules[] = $this->newRule()
->setCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT,
))
->setIsActive(!$run_with_view)
->setDescription(
pht(
'You must have edit permission on this build plan to pause, '.
'abort, resume, or restart it.'));
$rules[] = $this->newRule()
->setCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT,
))
->setIsActive(!$run_with_view)
->setDescription(
pht(
'You must have edit permission on this build plan to run it '.
'manually.'));
return $rules;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.