From e3a5ab1f8cecdce851710f096ed53fb2d10bbf23 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 6 Nov 2013 11:26:24 -0800 Subject: [PATCH] Add an administrative `bin/repository mark-imported` command Summary: Ref T4068. In some cases like that one, I anticipate a repository not fully importing when a handful of random commits are broken. In the long run we should just deal with that properly, but in the meantime provide an administrative escape hatch so you can mark the repository as imported and get it running normally. The major reason to do this is that Herald, Feed, Harbormaster, etc., won't activate until a repository is "imported". Test Plan: - Tried to mark an imported repository as imported, got an "already imported" message. - Same for not-imported. - Marked a repository not-imported. - Marked a repository imported. - Marked a repository not-imported, then waited for the daemons to mark it imported again automatically. Reviewers: btrahan Reviewed By: btrahan CC: aran, kbrownlees Maniphest Tasks: T4068 Differential Revision: https://secure.phabricator.com/D7514 --- scripts/repository/manage_repositories.php | 1 + src/__phutil_library_map__.php | 2 + ...positoryManagementMarkImportedWorkflow.php | 67 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 src/applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php diff --git a/scripts/repository/manage_repositories.php b/scripts/repository/manage_repositories.php index 694910a83d..e41bac6ab9 100755 --- a/scripts/repository/manage_repositories.php +++ b/scripts/repository/manage_repositories.php @@ -20,6 +20,7 @@ $workflows = array( new PhabricatorRepositoryManagementDiscoverWorkflow(), new PhabricatorRepositoryManagementListWorkflow(), new PhabricatorRepositoryManagementDeleteWorkflow(), + new PhabricatorRepositoryManagementMarkImportedWorkflow(), new PhutilHelpArgumentWorkflow(), ); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 87463605d9..7063139b22 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1661,6 +1661,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryManagementDeleteWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php', 'PhabricatorRepositoryManagementDiscoverWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php', 'PhabricatorRepositoryManagementListWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementListWorkflow.php', + 'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php', 'PhabricatorRepositoryManagementPullWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php', 'PhabricatorRepositoryManagementWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementWorkflow.php', 'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php', @@ -4013,6 +4014,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryManagementDeleteWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 'PhabricatorRepositoryManagementDiscoverWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 'PhabricatorRepositoryManagementListWorkflow' => 'PhabricatorRepositoryManagementWorkflow', + 'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 'PhabricatorRepositoryManagementPullWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 'PhabricatorRepositoryManagementWorkflow' => 'PhutilArgumentWorkflow', 'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker', diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php new file mode 100644 index 0000000000..7c8d5fb825 --- /dev/null +++ b/src/applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php @@ -0,0 +1,67 @@ +setName('mark-imported') + ->setExamples('**mark-imported** __repository__ ...') + ->setSynopsis('Mark __repository__, named by callsign, as imported.') + ->setArguments( + array( + array( + 'name' => 'mark-not-imported', + 'help' => 'Instead, mark repositories as NOT imported.', + ), + array( + 'name' => 'repos', + 'wildcard' => true, + ), + )); + } + + public function execute(PhutilArgumentParser $args) { + $repos = $this->loadRepositories($args, 'repos'); + + if (!$repos) { + throw new PhutilArgumentUsageException( + "Specify one or more repositories to mark imported, by callsign."); + } + + $new_importing_value = (bool)$args->getArg('mark-not-imported'); + + $console = PhutilConsole::getConsole(); + foreach ($repos as $repo) { + $callsign = $repo->getCallsign(); + + if ($repo->isImporting() && $new_importing_value) { + $console->writeOut( + "%s\n", + pht("Repository '%s' is already importing.", $callsign)); + } else if (!$repo->isImporting() && !$new_importing_value) { + $console->writeOut( + "%s\n", + pht("Repository '%s' is already imported.", $callsign)); + } else { + if ($new_importing_value) { + $console->writeOut( + "%s\n", + pht("Marking repository '%s' as importing.", $callsign)); + } else { + $console->writeOut( + "%s\n", + pht("Marking repository '%s' as imported.", $callsign)); + } + + $repo->setDetail('importing', $new_importing_value); + $repo->save(); + } + } + + $console->writeOut("Done.\n"); + + return 0; + } + +}