]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Remove client-side commit message validation from Arcanist
authorepriestley <git@epriestley.com>
Thu, 1 Dec 2011 23:50:44 +0000 (15:50 -0800)
committerepriestley <git@epriestley.com>
Fri, 2 Dec 2011 15:29:31 +0000 (07:29 -0800)
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

src/differential/commitmessage/ArcanistDifferentialCommitMessage.php
src/differential/commitmessage/ArcanistDifferentialCommitMessageParserException.php
src/differential/commitmessage/__init__.php
src/workflow/diff/ArcanistDiffWorkflow.php

index 04a188cb24af475100c45eb16116cb49385d6c21..baf0d667db4113df5283146a3b7a6b7e7c720126 100644 (file)
@@ -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'];
   }
index 41ea5cd2ba91531e6665c561fe8f4713321403ec..e4faf5aa61100fd7dd9c15deb72cd418ebbb4c76 100644 (file)
  */
 class ArcanistDifferentialCommitMessageParserException extends Exception {
 
+  private $parserErrors;
+
+  public function __construct(array $errors) {
+    $this->parserErrors = $errors;
+    parent::__construct(head($errors));
+  }
+
+  public function getParserErrors() {
+    return $this->parserErrors;
+  }
+
 }
index 2bb56d500a75d4e629ed30d3ac8122bd4f80b170..49f0e53a9ef0c4904026153ced0cd985f2514e58 100644 (file)
@@ -6,6 +6,8 @@
 
 
 
+phutil_require_module('phutil', 'utils');
+
 
 phutil_require_source('ArcanistDifferentialCommitMessage.php');
 phutil_require_source('ArcanistDifferentialCommitMessageParserException.php');
index a64c661a56cff578c2fe2f57ec5a8d4ac89095fe..4d2a831404665cbad13df26c1628e1533f78ca30 100644 (file)
@@ -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 ".