diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1887,6 +1887,7 @@ 'PhabricatorAuditManagementWorkflow' => 'applications/audit/management/PhabricatorAuditManagementWorkflow.php', 'PhabricatorAuditReplyHandler' => 'applications/audit/mail/PhabricatorAuditReplyHandler.php', 'PhabricatorAuditStatusConstants' => 'applications/audit/constants/PhabricatorAuditStatusConstants.php', + 'PhabricatorAuditSynchronizeManagementWorkflow' => 'applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php', 'PhabricatorAuditTransaction' => 'applications/audit/storage/PhabricatorAuditTransaction.php', 'PhabricatorAuditTransactionComment' => 'applications/audit/storage/PhabricatorAuditTransactionComment.php', 'PhabricatorAuditTransactionQuery' => 'applications/audit/query/PhabricatorAuditTransactionQuery.php', @@ -6783,6 +6784,7 @@ 'PhabricatorAuditManagementWorkflow' => 'PhabricatorManagementWorkflow', 'PhabricatorAuditReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'PhabricatorAuditStatusConstants' => 'Phobject', + 'PhabricatorAuditSynchronizeManagementWorkflow' => 'PhabricatorAuditManagementWorkflow', 'PhabricatorAuditTransaction' => 'PhabricatorModularTransaction', 'PhabricatorAuditTransactionComment' => 'PhabricatorApplicationTransactionComment', 'PhabricatorAuditTransactionQuery' => 'PhabricatorApplicationTransactionQuery', diff --git a/src/applications/audit/management/PhabricatorAuditManagementWorkflow.php b/src/applications/audit/management/PhabricatorAuditManagementWorkflow.php --- a/src/applications/audit/management/PhabricatorAuditManagementWorkflow.php +++ b/src/applications/audit/management/PhabricatorAuditManagementWorkflow.php @@ -1,4 +1,90 @@ 'all', + 'help' => pht('Update all commits in all repositories.'), + ), + array( + 'name' => 'objects', + 'wildcard' => true, + 'help' => pht('Update named commits and repositories.'), + ), + ); + } + + protected function loadCommitsWithConstraints(PhutilArgumentParser $args) { + $viewer = $this->getViewer(); + + $all = $args->getArg('all'); + $names = $args->getArg('objects'); + + if (!$names && !$all) { + throw new PhutilArgumentUsageException( + pht( + 'Specify "--all" to affect everything, or a list of specific '. + 'commits or repositories to affect.')); + } else if ($names && $all) { + throw new PhutilArgumentUsageException( + pht( + 'Specify either a list of objects to affect or "--all", but not '. + 'both.')); + } + + if ($all) { + $objects = new LiskMigrationIterator(new PhabricatorRepository()); + } else { + $query = id(new PhabricatorObjectQuery()) + ->setViewer($viewer) + ->withNames($names); + + $query->execute(); + + $objects = array(); + + $results = $query->getNamedResults(); + foreach ($names as $name) { + if (!isset($results[$name])) { + throw new PhutilArgumentUsageException( + pht( + 'Object "%s" is not a valid object.', + $name)); + } + + $object = $results[$name]; + if (!($object instanceof PhabricatorRepository) && + !($object instanceof PhabricatorRepositoryCommit)) { + throw new PhutilArgumentUsageException( + pht( + 'Object "%s" is not a valid repository or commit.', + $name)); + } + + $objects[] = $object; + } + } + + return $objects; + } + + protected function loadCommitsForConstraintObject($object) { + $viewer = $this->getViewer(); + + if ($object instanceof PhabricatorRepository) { + $commits = id(new DiffusionCommitQuery()) + ->setViewer($viewer) + ->withRepository($object) + ->execute(); + } else { + $commits = array($object); + } + + return $commits; + } + +} diff --git a/src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php b/src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php new file mode 100644 --- /dev/null +++ b/src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php @@ -0,0 +1,58 @@ +setName('synchronize') + ->setExamples('**synchronize** ...') + ->setSynopsis(pht('Update audit status for commits.')) + ->setArguments( + array_merge( + $this->getCommitConstraintArguments(), + array())); + } + + public function execute(PhutilArgumentParser $args) { + $viewer = $this->getViewer(); + $objects = $this->loadCommitsWithConstraints($args); + + foreach ($objects as $object) { + $commits = $this->loadCommitsForConstraintObject($object); + foreach ($commits as $commit) { + $commit = id(new DiffusionCommitQuery()) + ->setViewer($viewer) + ->withPHIDs(array($commit->getPHID())) + ->needAuditRequests(true) + ->executeOne(); + if (!$commit) { + continue; + } + + $old_status = $commit->getAuditStatus(); + $commit->updateAuditStatus($commit->getAudits()); + $new_status = $commit->getAuditStatus(); + + if ($old_status == $new_status) { + echo tsprintf( + "%s\n", + pht( + 'No changes for "%s".', + $commit->getDisplayName())); + } else { + echo tsprintf( + "%s\n", + pht( + 'Updated "%s": "%s" -> "%s".', + $commit->getDisplayName(), + PhabricatorAuditCommitStatusConstants::getStatusName( + $old_status), + PhabricatorAuditCommitStatusConstants::getStatusName( + $new_status))); + } + } + } + } + +} diff --git a/src/applications/audit/management/PhabricatorAuditUpdateOwnersManagementWorkflow.php b/src/applications/audit/management/PhabricatorAuditUpdateOwnersManagementWorkflow.php --- a/src/applications/audit/management/PhabricatorAuditUpdateOwnersManagementWorkflow.php +++ b/src/applications/audit/management/PhabricatorAuditUpdateOwnersManagementWorkflow.php @@ -9,79 +9,17 @@ ->setExamples('**update-owners** ...') ->setSynopsis(pht('Update package relationships for commits.')) ->setArguments( - array( - array( - 'name' => 'all', - 'help' => pht('Update all commits in all repositories.'), - ), - array( - 'name' => 'objects', - 'wildcard' => true, - 'help' => pht('Update named commits and repositories.'), - ), - )); + array_merge( + $this->getCommitConstraintArguments(), + array())); } public function execute(PhutilArgumentParser $args) { $viewer = $this->getViewer(); - - $all = $args->getArg('all'); - $names = $args->getArg('objects'); - - if (!$names && !$all) { - throw new PhutilArgumentUsageException( - pht( - 'Specify "--all" to update everything, or a list of specific '. - 'commits or repositories to update.')); - } else if ($names && $all) { - throw new PhutilArgumentUsageException( - pht( - 'Specify either a list of objects to update or "--all", but not '. - 'both.')); - } - - if ($all) { - $objects = new LiskMigrationIterator(new PhabricatorRepository()); - } else { - $query = id(new PhabricatorObjectQuery()) - ->setViewer($viewer) - ->withNames($names); - - $query->execute(); - - $objects = array(); - - $results = $query->getNamedResults(); - foreach ($names as $name) { - if (!isset($results[$name])) { - throw new PhutilArgumentUsageException( - pht( - 'Object "%s" is not a valid object.', - $name)); - } - - $object = $results[$name]; - if (!($object instanceof PhabricatorRepository) && - !($object instanceof PhabricatorRepositoryCommit)) { - throw new PhutilArgumentUsageException( - pht( - 'Object "%s" is not a valid repository or commit.', - $name)); - } - - $objects[] = $object; - } - } + $objects = $this->loadCommitsWithConstraints($args); foreach ($objects as $object) { - if ($object instanceof PhabricatorRepository) { - $commits = id(new DiffusionCommitQuery()) - ->setViewer($viewer) - ->withRepository($object) - ->execute(); - } else { - $commits = array($object); - } + $commits = $this->loadCommitsForConstraintObject($object); foreach ($commits as $commit) { $repository = $commit->getRepository(); diff --git a/src/docs/user/userguide/audit.diviner b/src/docs/user/userguide/audit.diviner --- a/src/docs/user/userguide/audit.diviner +++ b/src/docs/user/userguide/audit.diviner @@ -156,6 +156,46 @@ - Press "?" to view keyboard shortcuts. +Audit Maintenance +================= + +The `bin/audit` command allows you to perform several maintenance operations. +Get more information about a command by running: + +``` +phabricator/ $ ./bin/audit help +``` + +Supported operations are: + +**Delete Audits**: Delete audits that match certain parameters with +`bin/audit delete`. + +You can use this command to forcibly delete requests which may have triggered +incorrectly (for example, because a package or Herald rule was configured in an +overbroad way). + +After deleting audits, you may want to run `bin/audit synchronize` to +synchronize audit state. + +**Synchronize Audit State**: Synchronize the audit state of commits to the +current open audit requests with `bin/audit synchronize`. + +Normally, overall audit state is automatically kept up to date as changes are +made to an audit. However, if you delete audits or manually update the database +to make changes to audit request state, the state of corresponding commits may +no longer be correct. + +This command will update commits so their overall audit state reflects the +cumulative state of their actual audit requests. + +**Update Owners Package Membership**: Update which Owners packages commits +belong to with `bin/audit update-owners`. + +Normally, commits are automatically associated with packages when they are +imported. You can use this command to manually rebuild this association if +you run into problems with it. + Next Steps ==========