mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Bring "Reverts X" to more general infrastructure and port unit tests
Summary: Ref T3886. See D8261. This brings the "reverts x" phrase to modern infrastructure. It isn't actually called by the real parser yet, I'm going to do that in one go at the end so I can test everything more easily. This had unit tests; port most of them forward. Test Plan: Added and executed unit tests. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3886 Differential Revision: https://secure.phabricator.com/D8262
This commit is contained in:
parent
e4d60bbc15
commit
5afddb6703
7 changed files with 153 additions and 39 deletions
|
@ -358,6 +358,8 @@ phutil_register_library_map(array(
|
|||
'DifferentialCustomFieldDependsOnParser' => 'applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php',
|
||||
'DifferentialCustomFieldDependsOnParserTestCase' => 'applications/differential/field/parser/__tests__/DifferentialCustomFieldDependsOnParserTestCase.php',
|
||||
'DifferentialCustomFieldNumericIndex' => 'applications/differential/storage/DifferentialCustomFieldNumericIndex.php',
|
||||
'DifferentialCustomFieldRevertsParser' => 'applications/differential/field/parser/DifferentialCustomFieldRevertsParser.php',
|
||||
'DifferentialCustomFieldRevertsParserTestCase' => 'applications/differential/field/parser/__tests__/DifferentialCustomFieldRevertsParserTestCase.php',
|
||||
'DifferentialCustomFieldStorage' => 'applications/differential/storage/DifferentialCustomFieldStorage.php',
|
||||
'DifferentialCustomFieldStringIndex' => 'applications/differential/storage/DifferentialCustomFieldStringIndex.php',
|
||||
'DifferentialDAO' => 'applications/differential/storage/DifferentialDAO.php',
|
||||
|
@ -387,7 +389,6 @@ phutil_register_library_map(array(
|
|||
'DifferentialFieldSpecificationIncompleteException' => 'applications/differential/field/exception/DifferentialFieldSpecificationIncompleteException.php',
|
||||
'DifferentialFieldValidationException' => 'applications/differential/field/exception/DifferentialFieldValidationException.php',
|
||||
'DifferentialFreeformFieldSpecification' => 'applications/differential/field/specification/DifferentialFreeformFieldSpecification.php',
|
||||
'DifferentialFreeformFieldTestCase' => 'applications/differential/field/specification/__tests__/DifferentialFreeformFieldTestCase.php',
|
||||
'DifferentialGetWorkingCopy' => 'applications/differential/DifferentialGetWorkingCopy.php',
|
||||
'DifferentialGitSVNIDFieldSpecification' => 'applications/differential/field/specification/DifferentialGitSVNIDFieldSpecification.php',
|
||||
'DifferentialHostFieldSpecification' => 'applications/differential/field/specification/DifferentialHostFieldSpecification.php',
|
||||
|
@ -2876,6 +2877,8 @@ phutil_register_library_map(array(
|
|||
'DifferentialCustomFieldDependsOnParser' => 'PhabricatorCustomFieldMonogramParser',
|
||||
'DifferentialCustomFieldDependsOnParserTestCase' => 'PhabricatorTestCase',
|
||||
'DifferentialCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage',
|
||||
'DifferentialCustomFieldRevertsParser' => 'PhabricatorCustomFieldMonogramParser',
|
||||
'DifferentialCustomFieldRevertsParserTestCase' => 'PhabricatorTestCase',
|
||||
'DifferentialCustomFieldStorage' => 'PhabricatorCustomFieldStorage',
|
||||
'DifferentialCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage',
|
||||
'DifferentialDAO' => 'PhabricatorLiskDAO',
|
||||
|
@ -2908,7 +2911,6 @@ phutil_register_library_map(array(
|
|||
'DifferentialFieldSpecificationIncompleteException' => 'Exception',
|
||||
'DifferentialFieldValidationException' => 'Exception',
|
||||
'DifferentialFreeformFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialFreeformFieldTestCase' => 'PhabricatorTestCase',
|
||||
'DifferentialGitSVNIDFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialHostFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialHovercardEventListener' => 'PhabricatorEventListener',
|
||||
|
|
|
@ -26,7 +26,7 @@ final class DifferentialCustomFieldDependsOnParser
|
|||
}
|
||||
|
||||
protected function getMonogramPattern() {
|
||||
return 'D\d+';
|
||||
return '[Dd]\d+';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialCustomFieldRevertsParser
|
||||
extends PhabricatorCustomFieldMonogramParser {
|
||||
|
||||
protected function getPrefixes() {
|
||||
|
||||
// NOTE: Git language is "This reverts commit X."
|
||||
// NOTE: Mercurial language is "Backed out changeset Y".
|
||||
|
||||
return array(
|
||||
'revert',
|
||||
'reverts',
|
||||
'reverted',
|
||||
'backout',
|
||||
'backsout',
|
||||
'backedout',
|
||||
'back out',
|
||||
'backs out',
|
||||
'backed out',
|
||||
'undo',
|
||||
'undoes',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getInfixes() {
|
||||
return array(
|
||||
'commit',
|
||||
'commits',
|
||||
'change',
|
||||
'changes',
|
||||
'changeset',
|
||||
'changesets',
|
||||
'rev',
|
||||
'revs',
|
||||
'revision',
|
||||
'revisions',
|
||||
'diff',
|
||||
'diffs',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getSuffixes() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function getMonogramPattern() {
|
||||
return '[rA-Z0-9a-f]+';
|
||||
}
|
||||
|
||||
}
|
|
@ -27,12 +27,12 @@ final class DifferentialCustomFieldDependsOnParserTestCase
|
|||
'offset' => 0,
|
||||
),
|
||||
),
|
||||
'depends on D123, D124' => array(
|
||||
'depends on D123, d124' => array(
|
||||
array(
|
||||
'match' => 'depends on D123, D124',
|
||||
'match' => 'depends on D123, d124',
|
||||
'prefix' => 'depends on',
|
||||
'infix' => '',
|
||||
'monograms' => array('D123', 'D124'),
|
||||
'monograms' => array('D123', 'd124'),
|
||||
'suffix' => '',
|
||||
'offset' => 0,
|
||||
),
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialCustomFieldRevertsParserTestCase
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialFreeformFieldTestCase extends PhabricatorTestCase {
|
||||
|
||||
public function testRevertedCommitParser() {
|
||||
$map = array(
|
||||
"Reverts 123" => array('123'),
|
||||
"Reverts r123" => array('r123'),
|
||||
"Reverts ac382f2" => array('ac382f2'),
|
||||
"Reverts r22, r23" => array('r22', 'r23'),
|
||||
"Reverts D99" => array('D99'),
|
||||
"Backs out commit\n99\n100" => array('99', '100'),
|
||||
"undo change f9f9f8f8" => array('f9f9f8f8'),
|
||||
"Backedout Changeset rX1234" => array('rX1234'),
|
||||
"This doesn't revert anything" => array(),
|
||||
'nonrevert of r11' => array(),
|
||||
"fixed a bug" => array(),
|
||||
);
|
||||
|
||||
foreach ($map as $input => $expect) {
|
||||
$actual = array_values(
|
||||
DifferentialFreeformFieldSpecification::findRevertedCommits($input));
|
||||
|
||||
$this->assertEqual(
|
||||
$expect,
|
||||
$actual,
|
||||
"Reverted commits in: {$input}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -27,7 +27,7 @@ abstract class PhabricatorCustomFieldMonogramParser
|
|||
'((?:'.$monogram_pattern.'[,\s]*)+)'.
|
||||
$suffix_regex.
|
||||
'(?:$|\b)'.
|
||||
'/i';
|
||||
'/';
|
||||
|
||||
$matches = null;
|
||||
$ok = preg_match_all(
|
||||
|
@ -65,7 +65,7 @@ abstract class PhabricatorCustomFieldMonogramParser
|
|||
$maybe_tail = $final ? '' : '\s+';
|
||||
$maybe_optional = $optional ? '?' : '';
|
||||
|
||||
return '(?:('.$parts.')'.$maybe_tail.')'.$maybe_optional;
|
||||
return '(?i:('.$parts.')'.$maybe_tail.')'.$maybe_optional;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue