From 79da3a6ff9a97bf077b47eeef9131f97a81904f3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 1 Dec 2011 15:50:44 -0800 Subject: [PATCH] Remove client-side commit message validation from Arcanist Summary: Commit templates are fully configurable on the server now, so we should be doing validation there, since an install can add or remove fields and change validation rules. Remove these outdated client validations, as per comment. Also update the API call to use the 'errors' field, which allows us to show the user all the parse errors at once. See: https://secure.phabricator.com/diffusion/P/browse/origin:master/src/applications/conduit/method/differential/parsecommitmessage/ConduitAPI_differential_parsecommitmessage_Method.php;cfaab709df37739b$75 Test Plan: Ran "arc diff" on a change with multiple errors: ```$ arc diff --conduit-uri=http://local.aphront.com/ Usage Exception: Commit message is not properly formatted: Error parsing field 'Reviewers': Commit message references nonexistent users: jjjderp. Error parsing field 'CC': Commit message references nonexistent users and mailing lists: jjjderp. You should use the standard git commit template to provide a commit message. If you only want to create a diff (not a revision), use --preview to ignore commit messages.``` Reviewers: btrahan, jungejason Reviewed By: btrahan CC: aran, btrahan Differential Revision: 1154 --- .../ArcanistDifferentialCommitMessage.php | 4 +-- ...fferentialCommitMessageParserException.php | 11 +++++++ src/differential/commitmessage/__init__.php | 2 ++ src/workflow/diff/ArcanistDiffWorkflow.php | 30 +++---------------- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/differential/commitmessage/ArcanistDifferentialCommitMessage.php b/src/differential/commitmessage/ArcanistDifferentialCommitMessage.php index 04a188cb..baf0d667 100644 --- a/src/differential/commitmessage/ArcanistDifferentialCommitMessage.php +++ b/src/differential/commitmessage/ArcanistDifferentialCommitMessage.php @@ -66,9 +66,9 @@ class ArcanistDifferentialCommitMessage { 'corpus' => $this->rawCorpus, )); $result = $result->resolve(); - if (!empty($result['error'])) { + if (!empty($result['errors'])) { throw new ArcanistDifferentialCommitMessageParserException( - $result['error']); + $result['errors']); } $this->fields = $result['fields']; } diff --git a/src/differential/commitmessage/ArcanistDifferentialCommitMessageParserException.php b/src/differential/commitmessage/ArcanistDifferentialCommitMessageParserException.php index 41ea5cd2..e4faf5aa 100644 --- a/src/differential/commitmessage/ArcanistDifferentialCommitMessageParserException.php +++ b/src/differential/commitmessage/ArcanistDifferentialCommitMessageParserException.php @@ -23,4 +23,15 @@ */ class ArcanistDifferentialCommitMessageParserException extends Exception { + private $parserErrors; + + public function __construct(array $errors) { + $this->parserErrors = $errors; + parent::__construct(head($errors)); + } + + public function getParserErrors() { + return $this->parserErrors; + } + } diff --git a/src/differential/commitmessage/__init__.php b/src/differential/commitmessage/__init__.php index 2bb56d50..49f0e53a 100644 --- a/src/differential/commitmessage/__init__.php +++ b/src/differential/commitmessage/__init__.php @@ -6,6 +6,8 @@ +phutil_require_module('phutil', 'utils'); + phutil_require_source('ArcanistDifferentialCommitMessage.php'); phutil_require_source('ArcanistDifferentialCommitMessageParserException.php'); diff --git a/src/workflow/diff/ArcanistDiffWorkflow.php b/src/workflow/diff/ArcanistDiffWorkflow.php index a64c661a..4d2a8314 100644 --- a/src/workflow/diff/ArcanistDiffWorkflow.php +++ b/src/workflow/diff/ArcanistDiffWorkflow.php @@ -972,31 +972,10 @@ EOTEXT $parsed[$key] = $message; } catch (ArcanistDifferentialCommitMessageParserException $ex) { - $problems[$key][] = $ex; - continue; - } - - // TODO: Move this all behind Conduit. - if (!$message->getRevisionID()) { - if ($message->getFieldValue('reviewedByPHIDs')) { - $problems[$key][] = new ArcanistUsageException( - "When creating or updating a revision, use the 'Reviewers:' ". - "field to specify reviewers, not 'Reviewed By:'. After the ". - "revision is accepted, run 'arc amend' to update the commit ". - "message."); - } - - if (!$message->getFieldValue('title')) { - $problems[$key][] = new ArcanistUsageException( - "Commit message has no title. You must provide a title for this ". - "revision."); - } - - if (!$message->getFieldValue('testPlan')) { - $problems[$key][] = new ArcanistUsageException( - "Commit message has no 'Test Plan:'. You must provide a test ". - "plan."); + foreach ($ex->getParserErrors() as $problem) { + $problems[$key][] = $problem; } + continue; } } @@ -1020,8 +999,7 @@ EOTEXT } if ($revision_id === -1) { - $all_problems = call_user_func_array('array_merge', $problems); - $desc = implode("\n", mpull($all_problems, 'getMessage')); + $desc = implode("\n", array_mergev($problems)); if (count($problems) > 1) { throw new ArcanistUsageException( "All changes between the specified commits have template parsing ". -- 2.43.0