Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15427191
D8263.id19652.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D8263.id19652.diff
View Options
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
@@ -885,6 +885,8 @@
'ManiphestCreateMailReceiver' => 'applications/maniphest/mail/ManiphestCreateMailReceiver.php',
'ManiphestCustomField' => 'applications/maniphest/field/ManiphestCustomField.php',
'ManiphestCustomFieldNumericIndex' => 'applications/maniphest/storage/ManiphestCustomFieldNumericIndex.php',
+ 'ManiphestCustomFieldStatusParser' => 'applications/maniphest/field/parser/ManiphestCustomFieldStatusParser.php',
+ 'ManiphestCustomFieldStatusParserTestCase' => 'applications/maniphest/field/parser/__tests__/ManiphestCustomFieldStatusParserTestCase.php',
'ManiphestCustomFieldStorage' => 'applications/maniphest/storage/ManiphestCustomFieldStorage.php',
'ManiphestCustomFieldStringIndex' => 'applications/maniphest/storage/ManiphestCustomFieldStringIndex.php',
'ManiphestDAO' => 'applications/maniphest/storage/ManiphestDAO.php',
@@ -3498,6 +3500,8 @@
'ManiphestCreateMailReceiver' => 'PhabricatorMailReceiver',
'ManiphestCustomField' => 'PhabricatorCustomField',
'ManiphestCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage',
+ 'ManiphestCustomFieldStatusParser' => 'PhabricatorCustomFieldMonogramParser',
+ 'ManiphestCustomFieldStatusParserTestCase' => 'PhabricatorTestCase',
'ManiphestCustomFieldStorage' => 'PhabricatorCustomFieldStorage',
'ManiphestCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage',
'ManiphestDAO' => 'PhabricatorLiskDAO',
diff --git a/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php b/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
--- a/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
+++ b/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
@@ -44,53 +44,36 @@
'' => null,
);
- $prefix_regex = array();
- foreach ($prefixes as $prefix => $resolution) {
- $prefix_regex[] = preg_quote($prefix, '/');
- }
- $prefix_regex = implode('|', $prefix_regex);
-
- $suffix_regex = array();
- foreach ($suffixes as $suffix => $resolution) {
- $suffix_regex[] = preg_quote($suffix, '/');
- }
- $suffix_regex = implode('|', $suffix_regex);
-
- $matches = null;
- preg_match_all(
- "/({$prefix_regex})\s+T(\d+)\s*({$suffix_regex})/i",
- $message,
- $matches,
- PREG_SET_ORDER);
+ $matches = id(new ManiphestCustomFieldStatusParser())
+ ->parseCorpus($message);
- $tasks_statuses = array();
- foreach ($matches as $set) {
- $prefix = strtolower($set[1]);
- $task_id = (int)$set[2];
- $suffix = strtolower($set[3]);
+ $task_statuses = array();
+ foreach ($matches as $match) {
+ $prefix = phutil_utf8_strtolower($match['prefix']);
+ $suffix = phutil_utf8_strtolower($match['suffix']);
$status = idx($suffixes, $suffix);
if (!$status) {
$status = idx($prefixes, $prefix);
}
- $tasks_statuses[$task_id] = $status;
+ foreach ($match['monograms'] as $task_monogram) {
+ $task_id = (int)trim($task_monogram, 'tT');
+ $task_statuses[$task_id] = $status;
+ }
}
- return $tasks_statuses;
+ return $task_statuses;
}
private function findDependentRevisions($message) {
- $dependents = array();
+ $matches = id(new DifferentialCustomFieldDependsOnParser())
+ ->parseCorpus($message);
- $matches = null;
- preg_match_all(
- '/\b(?i:depends\s+on):?\s+D(\d+(,\s+D\d++)*)\b/',
- $message,
- $matches);
-
- foreach ($matches[1] as $revisions) {
- foreach (preg_split('/,\s+D/', $revisions) as $id) {
+ $dependents = array();
+ foreach ($matches as $match) {
+ foreach ($match['monograms'] as $monogram) {
+ $id = (int)trim($monogram, 'dD');
$dependents[$id] = $id;
}
}
@@ -99,46 +82,13 @@
}
public static function findRevertedCommits($message) {
- $reverts = array();
- $matches = null;
-
- // NOTE: Git language is "This reverts commit X."
- // NOTE: Mercurial language is "Backed out changeset Y".
-
- $prefixes = array(
- 'revert' => true,
- 'reverts' => true,
- 'back\s*out' => true,
- 'backs\s*out' => true,
- 'backed\s*out' => true,
- 'undo' => true,
- 'undoes' => true,
- );
-
- $optional = array(
- 'commit' => true,
- 'changeset' => true,
- 'rev' => true,
- 'revision' => true,
- 'change' => true,
- 'diff' => true,
- );
-
- $pre_re = implode('|', array_keys($prefixes));
- $opt_re = implode('|', array_keys($optional));
-
- $matches = null;
- preg_match_all(
- '/\b(?i:'.$pre_re.')(?:\s+(?i:'.$opt_re.'))?([rA-Z0-9a-f,\s]+)\b/',
- $message,
- $matches);
+ $matches = id(new DifferentialCustomFieldRevertsParser())
+ ->parseCorpus($message);
$result = array();
- foreach ($matches[1] as $commits) {
- $commits = preg_split('/[,\s]+/', $commits);
- $commits = array_filter($commits);
- foreach ($commits as $commit) {
- $result[$commit] = $commit;
+ foreach ($matches as $match) {
+ foreach ($match['monograms'] as $monogram) {
+ $result[$monogram] = $monogram;
}
}
diff --git a/src/applications/maniphest/field/parser/ManiphestCustomFieldStatusParser.php b/src/applications/maniphest/field/parser/ManiphestCustomFieldStatusParser.php
new file mode 100644
--- /dev/null
+++ b/src/applications/maniphest/field/parser/ManiphestCustomFieldStatusParser.php
@@ -0,0 +1,59 @@
+<?php
+
+final class ManiphestCustomFieldStatusParser
+ extends PhabricatorCustomFieldMonogramParser {
+
+ protected function getPrefixes() {
+ return array(
+ 'resolve',
+ 'resolves',
+ 'resolved',
+ 'fix',
+ 'fixes',
+ 'fixed',
+ 'wontfix',
+ 'wontfixes',
+ 'wontfixed',
+ 'spite',
+ 'spites',
+ 'spited',
+ 'invalidate',
+ 'invalidates',
+ 'invalidated',
+ 'close',
+ 'closes',
+ 'closed',
+ 'ref',
+ 'refs',
+ 'references',
+ 'cf.',
+ );
+ }
+
+ protected function getInfixes() {
+ return array(
+ 'task',
+ 'tasks',
+ 'issue',
+ 'issues',
+ 'bug',
+ 'bugs',
+ );
+ }
+
+ protected function getSuffixes() {
+ return array(
+ 'as resolved',
+ 'as fixed',
+ 'as wontfix',
+ 'as spite',
+ 'out of spite',
+ 'as invalid',
+ );
+ }
+
+ protected function getMonogramPattern() {
+ return '[tT]\d+';
+ }
+
+}
diff --git a/src/applications/maniphest/field/parser/__tests__/ManiphestCustomFieldStatusParserTestCase.php b/src/applications/maniphest/field/parser/__tests__/ManiphestCustomFieldStatusParserTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/applications/maniphest/field/parser/__tests__/ManiphestCustomFieldStatusParserTestCase.php
@@ -0,0 +1,92 @@
+<?php
+
+final class ManiphestCustomFieldStatusParserTestCase
+ extends PhabricatorTestCase {
+
+ public function testParser() {
+ $map = array(
+ 'quack quack quack' => array(),
+
+ // Git default message.
+ 'This reverts commit 1234abcd.' => array(
+ array(
+ 'match' => 'reverts commit 1234abcd',
+ 'prefix' => 'reverts',
+ 'infix' => 'commit',
+ 'monograms' => array('1234abcd'),
+ 'suffix' => '',
+ 'offset' => 5,
+ ),
+ ),
+
+ // Mercurial default message.
+ 'Backed out changeset 1234abcd.' => array(
+ array(
+ 'match' => 'Backed out changeset 1234abcd',
+ 'prefix' => 'Backed out',
+ 'infix' => 'changeset',
+ 'monograms' => array('1234abcd'),
+ 'suffix' => '',
+ 'offset' => 0,
+ ),
+ ),
+
+ 'this undoes 1234abcd, 5678efab. they were bad' => array(
+ array(
+ 'match' => 'undoes 1234abcd, 5678efab',
+ 'prefix' => 'undoes',
+ 'infix' => '',
+ 'monograms' => array('1234abcd', '5678efab'),
+ 'suffix' => '',
+ 'offset' => 5,
+ ),
+ ),
+
+ "Reverts 123" => array(
+ array(
+ 'match' => 'Reverts 123',
+ 'prefix' => 'Reverts',
+ 'infix' => '',
+ 'monograms' => array('123'),
+ 'suffix' => '',
+ 'offset' => 0,
+ ),
+ ),
+
+
+ "Reverts r123" => array(
+ array(
+ 'match' => 'Reverts r123',
+ 'prefix' => 'Reverts',
+ 'infix' => '',
+ 'monograms' => array('r123'),
+ 'suffix' => '',
+ 'offset' => 0,
+ ),
+ ),
+
+ "Backs out commit\n99\n100" => array(
+ array(
+ 'match' => "Backs out commit\n99\n100",
+ 'prefix' => 'Backs out',
+ 'infix' => 'commit',
+ 'monograms' => array('99', '100'),
+ 'suffix' => '',
+ 'offset' => 0,
+ ),
+ ),
+
+ "This doesn't revert anything" => array(),
+ 'nonrevert of r11' => array(),
+ "fixed a bug" => array(),
+ );
+
+ foreach ($map as $input => $expect) {
+ $parser = new DifferentialCustomFieldRevertsParser();
+ $output = $parser->parseCorpus($input);
+
+ $this->assertEqual($expect, $output, $input);
+ }
+ }
+
+}
diff --git a/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php b/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php
--- a/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php
+++ b/src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php
@@ -47,7 +47,7 @@
'prefix' => $set[1][0],
'infix' => $set[2][0],
'monograms' => array_filter(preg_split('/[,\s]+/', $set[3][0])),
- 'suffix' => $set[4][0],
+ 'suffix' => idx(idx($set, 4, array()), 0, ''),
'offset' => $set[0][1],
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 24, 1:16 PM (2 w, 17 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7720273
Default Alt Text
D8263.id19652.diff (10 KB)
Attached To
Mode
D8263: Bring "fixes x as y" parser forward and use new parsers instead of old ones
Attached
Detach File
Event Timeline
Log In to Comment