mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Add a "--dry-run" flag to "bin/repository rebuild-identities"
Summary: Ref T13444. Allow the effects of performing an identity rebuild to be previewed without committing to any changes. Test Plan: Ran "bin/repository rebuild-identities --all-identities" with and without "--dry-run". Maniphest Tasks: T13444 Differential Revision: https://secure.phabricator.com/D20922
This commit is contained in:
parent
63d84e0b44
commit
374f8b10b3
2 changed files with 84 additions and 25 deletions
|
@ -5,6 +5,7 @@ final class DiffusionRepositoryIdentityEngine
|
||||||
|
|
||||||
private $viewer;
|
private $viewer;
|
||||||
private $sourcePHID;
|
private $sourcePHID;
|
||||||
|
private $dryRun;
|
||||||
|
|
||||||
public function setViewer(PhabricatorUser $viewer) {
|
public function setViewer(PhabricatorUser $viewer) {
|
||||||
$this->viewer = $viewer;
|
$this->viewer = $viewer;
|
||||||
|
@ -28,6 +29,15 @@ final class DiffusionRepositoryIdentityEngine
|
||||||
return $this->sourcePHID;
|
return $this->sourcePHID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setDryRun($dry_run) {
|
||||||
|
$this->dryRun = $dry_run;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDryRun() {
|
||||||
|
return $this->dryRun;
|
||||||
|
}
|
||||||
|
|
||||||
public function newResolvedIdentity($raw_identity) {
|
public function newResolvedIdentity($raw_identity) {
|
||||||
$identity = $this->loadRawIdentity($raw_identity);
|
$identity = $this->loadRawIdentity($raw_identity);
|
||||||
|
|
||||||
|
@ -88,9 +98,13 @@ final class DiffusionRepositoryIdentityEngine
|
||||||
|
|
||||||
$resolved_phid = $this->resolveIdentity($identity);
|
$resolved_phid = $this->resolveIdentity($identity);
|
||||||
|
|
||||||
$identity
|
$identity->setAutomaticGuessedUserPHID($resolved_phid);
|
||||||
->setAutomaticGuessedUserPHID($resolved_phid)
|
|
||||||
->save();
|
if ($this->getDryRun()) {
|
||||||
|
$identity->makeEphemeral();
|
||||||
|
} else {
|
||||||
|
$identity->save();
|
||||||
|
}
|
||||||
|
|
||||||
return $identity;
|
return $identity;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
|
||||||
extends PhabricatorRepositoryManagementWorkflow {
|
extends PhabricatorRepositoryManagementWorkflow {
|
||||||
|
|
||||||
private $identityCache = array();
|
private $identityCache = array();
|
||||||
|
private $phidCache = array();
|
||||||
|
private $dryRun;
|
||||||
|
|
||||||
protected function didConstruct() {
|
protected function didConstruct() {
|
||||||
$this
|
$this
|
||||||
|
@ -51,6 +53,10 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
|
||||||
'repeat' => true,
|
'repeat' => true,
|
||||||
'help' => pht('Rebuild identities for a raw commit string.'),
|
'help' => pht('Rebuild identities for a raw commit string.'),
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'dry-run',
|
||||||
|
'help' => pht('Show changes, but do not make any changes.'),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +65,6 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
|
||||||
|
|
||||||
$rebuilt_anything = false;
|
$rebuilt_anything = false;
|
||||||
|
|
||||||
|
|
||||||
$all_repositories = $args->getArg('all-repositories');
|
$all_repositories = $args->getArg('all-repositories');
|
||||||
$repositories = $args->getArg('repository');
|
$repositories = $args->getArg('repository');
|
||||||
|
|
||||||
|
@ -81,6 +86,15 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
|
||||||
'compatible.'));
|
'compatible.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dry_run = $args->getArg('dry-run');
|
||||||
|
$this->dryRun = $dry_run;
|
||||||
|
|
||||||
|
if ($this->dryRun) {
|
||||||
|
$this->logWarn(
|
||||||
|
pht('DRY RUN'),
|
||||||
|
pht('This is a dry run, so no changes will be written.'));
|
||||||
|
}
|
||||||
|
|
||||||
if ($all_repositories || $repositories) {
|
if ($all_repositories || $repositories) {
|
||||||
$rebuilt_anything = true;
|
$rebuilt_anything = true;
|
||||||
|
|
||||||
|
@ -245,10 +259,7 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
|
||||||
$raw_identity) {
|
$raw_identity) {
|
||||||
|
|
||||||
if (!isset($this->identityCache[$raw_identity])) {
|
if (!isset($this->identityCache[$raw_identity])) {
|
||||||
$viewer = $this->getViewer();
|
$identity = $this->newIdentityEngine()
|
||||||
|
|
||||||
$identity = id(new DiffusionRepositoryIdentityEngine())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->setSourcePHID($commit->getPHID())
|
->setSourcePHID($commit->getPHID())
|
||||||
->newResolvedIdentity($raw_identity);
|
->newResolvedIdentity($raw_identity);
|
||||||
|
|
||||||
|
@ -317,7 +328,7 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
private function rebuildIdentities($identities) {
|
private function rebuildIdentities($identities) {
|
||||||
$viewer = $this->getViewer();
|
$dry_run = $this->dryRun;
|
||||||
|
|
||||||
foreach ($identities as $identity) {
|
foreach ($identities as $identity) {
|
||||||
$raw_identity = $identity->getIdentityName();
|
$raw_identity = $identity->getIdentityName();
|
||||||
|
@ -340,8 +351,7 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
|
||||||
$old_auto = $identity->getAutomaticGuessedUserPHID();
|
$old_auto = $identity->getAutomaticGuessedUserPHID();
|
||||||
$old_assign = $identity->getManuallySetUserPHID();
|
$old_assign = $identity->getManuallySetUserPHID();
|
||||||
|
|
||||||
$identity = id(new DiffusionRepositoryIdentityEngine())
|
$identity = $this->newIdentityEngine()
|
||||||
->setViewer($viewer)
|
|
||||||
->newUpdatedIdentity($identity);
|
->newUpdatedIdentity($identity);
|
||||||
|
|
||||||
$this->identityCache[$raw_identity] = $identity;
|
$this->identityCache[$raw_identity] = $identity;
|
||||||
|
@ -358,20 +368,38 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
|
||||||
pht('No changes to identity.'));
|
pht('No changes to identity.'));
|
||||||
} else {
|
} else {
|
||||||
if (!$same_auto) {
|
if (!$same_auto) {
|
||||||
$this->logWarn(
|
if ($dry_run) {
|
||||||
pht('AUTOMATIC PHID'),
|
$this->logWarn(
|
||||||
pht(
|
pht('DETECTED PHID'),
|
||||||
'Automatic user updated from "%s" to "%s".',
|
pht(
|
||||||
$this->renderPHID($old_auto),
|
'(Dry Run) Would update detected user from "%s" to "%s".',
|
||||||
$this->renderPHID($new_auto)));
|
$this->renderPHID($old_auto),
|
||||||
|
$this->renderPHID($new_auto)));
|
||||||
|
} else {
|
||||||
|
$this->logWarn(
|
||||||
|
pht('DETECTED PHID'),
|
||||||
|
pht(
|
||||||
|
'Detected user updated from "%s" to "%s".',
|
||||||
|
$this->renderPHID($old_auto),
|
||||||
|
$this->renderPHID($new_auto)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!$same_assign) {
|
if (!$same_assign) {
|
||||||
$this->logWarn(
|
if ($dry_run) {
|
||||||
pht('ASSIGNED PHID'),
|
$this->logWarn(
|
||||||
pht(
|
pht('ASSIGNED PHID'),
|
||||||
'Assigned user updated from "%s" to "%s".',
|
pht(
|
||||||
$this->renderPHID($old_assign),
|
'(Dry Run) Would update assigned user from "%s" to "%s".',
|
||||||
$this->renderPHID($new_assign)));
|
$this->renderPHID($old_assign),
|
||||||
|
$this->renderPHID($new_assign)));
|
||||||
|
} else {
|
||||||
|
$this->logWarn(
|
||||||
|
pht('ASSIGNED PHID'),
|
||||||
|
pht(
|
||||||
|
'Assigned user updated from "%s" to "%s".',
|
||||||
|
$this->renderPHID($old_assign),
|
||||||
|
$this->renderPHID($new_assign)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -380,9 +408,26 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
|
||||||
private function renderPHID($phid) {
|
private function renderPHID($phid) {
|
||||||
if ($phid == null) {
|
if ($phid == null) {
|
||||||
return pht('NULL');
|
return pht('NULL');
|
||||||
} else {
|
|
||||||
return $phid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($this->phidCache[$phid])) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
$handles = $viewer->loadHandles(array($phid));
|
||||||
|
$this->phidCache[$phid] = pht(
|
||||||
|
'%s <%s>',
|
||||||
|
$handles[$phid]->getFullName(),
|
||||||
|
$phid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->phidCache[$phid];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function newIdentityEngine() {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
|
return id(new DiffusionRepositoryIdentityEngine())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->setDryRun($this->dryRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue