1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 22:40:55 +01:00

Allow "bin/repository thaw" to accept "--all-repositories" instead of a list of repositories

Summary:
Ref T13222. See PHI992. If you've lost an entire cluster (or have lost a device and are willing to make broad assumptions about the state the device was in) you currently have to `xargs` to thaw everything or do something else creative.

Since this workflow is broadly reasonable, provide an easier way to accomplish the goal.

Test Plan:
  - Ran with `--all-repositories`, a list of repositories, both (error) and neither (error).
  - Saw a helpful new list of affected repositories.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13222

Differential Revision: https://secure.phabricator.com/D19849
This commit is contained in:
epriestley 2018-12-05 11:51:15 -08:00
parent 1e4bdc39a1
commit bba4186005

View file

@ -32,6 +32,12 @@ final class PhabricatorRepositoryManagementThawWorkflow
'name' => 'force', 'name' => 'force',
'help' => pht('Run operations without asking for confirmation.'), 'help' => pht('Run operations without asking for confirmation.'),
), ),
array(
'name' => 'all-repositories',
'help' => pht(
'Apply the promotion or demotion to all repositories hosted '.
'on the device.'),
),
array( array(
'name' => 'repositories', 'name' => 'repositories',
'wildcard' => true, 'wildcard' => true,
@ -42,12 +48,6 @@ final class PhabricatorRepositoryManagementThawWorkflow
public function execute(PhutilArgumentParser $args) { public function execute(PhutilArgumentParser $args) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$repositories = $this->loadRepositories($args, 'repositories');
if (!$repositories) {
throw new PhutilArgumentUsageException(
pht('Specify one or more repositories to thaw.'));
}
$promote = $args->getArg('promote'); $promote = $args->getArg('promote');
$demote = $args->getArg('demote'); $demote = $args->getArg('demote');
@ -72,6 +72,60 @@ final class PhabricatorRepositoryManagementThawWorkflow
pht('No device "%s" exists.', $device_name)); pht('No device "%s" exists.', $device_name));
} }
$repository_names = $args->getArg('repositories');
$all_repositories = $args->getArg('all-repositories');
if ($repository_names && $all_repositories) {
throw new PhutilArgumentUsageException(
pht(
'Specify a list of repositories or "--all-repositories", '.
'but not both.'));
} else if (!$repository_names && !$all_repositories) {
throw new PhutilArgumentUsageException(
pht(
'Select repositories to affect by providing a list of repositories '.
'or using the "--all-repositories" flag.'));
}
if ($repository_names) {
$repositories = $this->loadRepositories($args, 'repositories');
if (!$repositories) {
throw new PhutilArgumentUsageException(
pht('Specify one or more repositories to thaw.'));
}
} else {
$repositories = array();
$services = id(new AlmanacServiceQuery())
->setViewer($viewer)
->withDevicePHIDs(array($device->getPHID()))
->execute();
if ($services) {
$repositories = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withAlmanacServicePHIDs(mpull($services, 'getPHID'))
->execute();
}
if (!$repositories) {
throw new PhutilArgumentUsageException(
pht('There are no repositories on the selected device.'));
}
}
$display_list = new PhutilConsoleList();
foreach ($repositories as $repository) {
$display_list->addItem(
pht(
'%s %s',
$repository->getMonogram(),
$repository->getName()));
}
echo tsprintf(
"%s\n\n%B\n",
pht('These repositories will be thawed:'),
$display_list->drawConsoleString());
if ($promote) { if ($promote) {
$risk_message = pht( $risk_message = pht(
'Promoting a device can cause the loss of any repository data which '. 'Promoting a device can cause the loss of any repository data which '.