Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistReleaseWorkflow.php
- This file was added.
<?php | |||||
final class ArcanistReleaseWorkflow extends ArcanistWorkflow { | |||||
public function getWorkflowName() { | |||||
return 'release'; | |||||
} | |||||
public function getCommandSynopses() { | |||||
return phutil_console_format(<<<EOTEXT | |||||
**release** [__id__] | |||||
EOTEXT | |||||
); | |||||
} | |||||
public function getCommandHelp() { | |||||
return phutil_console_format(<<<EOTEXT | |||||
Release Drydock leases when you are done with them. | |||||
EOTEXT | |||||
); | |||||
} | |||||
public function getArguments() { | |||||
return array( | |||||
'*' => 'lease', | |||||
); | |||||
} | |||||
public function requiresAuthentication() { | |||||
return true; | |||||
} | |||||
public function run() { | |||||
if (!$this->getPassedArguments()) { | |||||
$this->listLeases(); | |||||
return 0; | |||||
} | |||||
$lease_id = (int)head($this->getArgument('lease')); | |||||
if (!$lease_id) { | |||||
throw new ArcanistUsageException('You must provide a lease ID.'); | |||||
} | |||||
$lease = $this->getConduit()->callMethodSynchronous( | |||||
'drydock.lease.search', | |||||
array( | |||||
'constraints' => array( | |||||
'ids' => array($lease_id), | |||||
), | |||||
)); | |||||
$lease = $lease['data'][0]; | |||||
$this->getConduit()->callMethodSynchronous('drydock.destroylease', array( | |||||
'leasePHID' => $lease['phid'], | |||||
)); | |||||
echo phutil_console_format( | |||||
"%s\n **%s** __%s__\n\n", | |||||
pht('Lease scheduled for release.'), | |||||
pht('Lease URI:'), | |||||
rtrim($this->getConfigFromAnySource('phabricator.uri'), '/').'/'. | |||||
'drydock/lease/'.$lease['id'].'/'); | |||||
return 0; | |||||
} | |||||
protected function listLeases() { | |||||
$console = PhutilConsole::getConsole(); | |||||
$console->writeOut("<bg:blue> %s </bg>\n", pht('LIVE LEASES')); | |||||
$conduit = $this->getConduit(); | |||||
$leases = $conduit->callMethodSynchronous('drydock.lease.search', array( | |||||
'constraints' => array( | |||||
'statuses' => array( | |||||
'pending', | |||||
'acquired', | |||||
'active', | |||||
), | |||||
'ownerPHIDs' => array( | |||||
$this->getUserPHID(), | |||||
), | |||||
), | |||||
)); | |||||
$leases = idx($leases, 'data', array()); | |||||
if (!$leases) { | |||||
$console->writeOut("\t%s\n", pht('No leases found.')); | |||||
return; | |||||
} | |||||
$table = (new PhutilConsoleTable()) | |||||
->addColumn('id', array('title' => 'ID')) | |||||
->addColumn('status', array('title' => 'Status')) | |||||
->addColumn('type', array('title' => 'Type')) | |||||
->setBorders(true); | |||||
chad: do these need pht()? | |||||
Not Done Inline ActionsI don't see why they wouldn't, but also I am really lazy today. I will do this tomorrow / or whenever I'm pretty sure you guys don't want me to actually just delete all of this code. yelirekim: I don't see why they wouldn't, but also I am //really// lazy today. I will do this tomorrow /… | |||||
foreach ($leases as $lease) { | |||||
$table->addRow(array( | |||||
'id' => idx($lease, 'id'), | |||||
'status' => idxv($lease, array('fields', 'status', 'name')), | |||||
'type' => idxv($lease, array('fields', 'resourceType')), | |||||
)); | |||||
} | |||||
$table->draw(); | |||||
} | |||||
} |
do these need pht()?