Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15268721
D17248.id41490.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D17248.id41490.diff
View Options
diff --git a/src/applications/differential/customfield/DifferentialCoreCustomField.php b/src/applications/differential/customfield/DifferentialCoreCustomField.php
--- a/src/applications/differential/customfield/DifferentialCoreCustomField.php
+++ b/src/applications/differential/customfield/DifferentialCoreCustomField.php
@@ -64,52 +64,11 @@
continue;
}
}
-
- if (is_string($value)) {
- $parser = $this->getFieldParser();
- $result = $parser->parseCorpus($value);
-
- unset($result['__title__']);
- unset($result['__summary__']);
-
- if ($result) {
- $error = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Invalid'),
- pht(
- 'The value you have entered in "%s" can not be parsed '.
- 'unambiguously when rendered in a commit message. Edit the '.
- 'message so that keywords like "Summary:" and "Test Plan:" do '.
- 'not appear at the beginning of lines. Parsed keys: %s.',
- $this->getFieldName(),
- implode(', ', array_keys($result))),
- $xaction);
- $errors[] = $error;
- $this->setFieldError(pht('Invalid'));
- continue;
- }
- }
}
return $errors;
}
- private function getFieldParser() {
- if (!$this->fieldParser) {
- $viewer = $this->getViewer();
- $parser = DifferentialCommitMessageParser::newStandardParser($viewer);
-
- // Set custom title and summary keys so we can detect the presence of
- // "Summary:" in, e.g., a test plan.
- $parser->setTitleKey('__title__');
- $parser->setSummaryKey('__summary__');
-
- $this->fieldParser = $parser;
- }
-
- return $this->fieldParser;
- }
-
public function canDisableField() {
return false;
}
diff --git a/src/applications/differential/field/DifferentialTestPlanCommitMessageField.php b/src/applications/differential/field/DifferentialTestPlanCommitMessageField.php
--- a/src/applications/differential/field/DifferentialTestPlanCommitMessageField.php
+++ b/src/applications/differential/field/DifferentialTestPlanCommitMessageField.php
@@ -50,4 +50,11 @@
);
}
+ public function validateTransactions($object, array $xactions) {
+ return $this->validateCommitMessageCorpusTransactions(
+ $object,
+ $xactions,
+ pht('Test Plan'));
+ }
+
}
diff --git a/src/applications/differential/xaction/DifferentialRevisionSummaryTransaction.php b/src/applications/differential/xaction/DifferentialRevisionSummaryTransaction.php
--- a/src/applications/differential/xaction/DifferentialRevisionSummaryTransaction.php
+++ b/src/applications/differential/xaction/DifferentialRevisionSummaryTransaction.php
@@ -54,4 +54,11 @@
return $changes;
}
+ public function validateTransactions($object, array $xactions) {
+ return $this->validateCommitMessageCorpusTransactions(
+ $object,
+ $xactions,
+ pht('Summary'));
+ }
+
}
diff --git a/src/applications/differential/xaction/DifferentialRevisionTransactionType.php b/src/applications/differential/xaction/DifferentialRevisionTransactionType.php
--- a/src/applications/differential/xaction/DifferentialRevisionTransactionType.php
+++ b/src/applications/differential/xaction/DifferentialRevisionTransactionType.php
@@ -1,4 +1,60 @@
<?php
abstract class DifferentialRevisionTransactionType
- extends PhabricatorModularTransactionType {}
+ extends PhabricatorModularTransactionType {
+
+ protected function validateCommitMessageCorpusTransactions(
+ $object,
+ array $xactions,
+ $field_name) {
+
+ $errors = array();
+ foreach ($xactions as $xaction) {
+ $error = $this->validateMessageCorpus($xaction, $field_name);
+ if ($error) {
+ $errors[] = $error;
+ }
+ }
+
+ return $errors;
+ }
+
+ private function validateMessageCorpus($xaction, $field_name) {
+ $value = $xaction->getNewValue();
+ if (!strlen($value)) {
+ return null;
+ }
+
+ // Put a placeholder title on the message, because the first line of a
+ // message is now always parsed as a title.
+ $value = "<placeholder>\n".$value;
+
+ $viewer = $this->getActor();
+ $parser = DifferentialCommitMessageParser::newStandardParser($viewer);
+
+ // Set custom title and summary keys so we can detect the presence of
+ // "Summary:" in, e.g., a test plan.
+ $parser->setTitleKey('__title__');
+ $parser->setSummaryKey('__summary__');
+
+ $result = $parser->parseCorpus($value);
+
+ unset($result['__title__']);
+ unset($result['__summary__']);
+
+ if (!$result) {
+ return null;
+ }
+
+ return $this->newInvalidError(
+ pht(
+ 'The value you have entered in "%s" can not be parsed '.
+ 'unambiguously when rendered in a commit message. Edit the '.
+ 'message so that keywords like "Summary:" and "Test Plan:" do '.
+ 'not appear at the beginning of lines. Parsed keys: %s.',
+ $field_name,
+ implode(', ', array_keys($result))),
+ $xaction);
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Feb 27, 4:42 PM (16 h, 49 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7212345
Default Alt Text
D17248.id41490.diff (5 KB)
Attached To
Mode
D17248: Fix two issues with embedding other fields inside "Summary" or "Test Plan" in Differential with the web UI
Attached
Detach File
Event Timeline
Log In to Comment