@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+153 -39
+4 -2
src/__phutil_library_map__.php
··· 358 358 'DifferentialCustomFieldDependsOnParser' => 'applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php', 359 359 'DifferentialCustomFieldDependsOnParserTestCase' => 'applications/differential/field/parser/__tests__/DifferentialCustomFieldDependsOnParserTestCase.php', 360 360 'DifferentialCustomFieldNumericIndex' => 'applications/differential/storage/DifferentialCustomFieldNumericIndex.php', 361 + 'DifferentialCustomFieldRevertsParser' => 'applications/differential/field/parser/DifferentialCustomFieldRevertsParser.php', 362 + 'DifferentialCustomFieldRevertsParserTestCase' => 'applications/differential/field/parser/__tests__/DifferentialCustomFieldRevertsParserTestCase.php', 361 363 'DifferentialCustomFieldStorage' => 'applications/differential/storage/DifferentialCustomFieldStorage.php', 362 364 'DifferentialCustomFieldStringIndex' => 'applications/differential/storage/DifferentialCustomFieldStringIndex.php', 363 365 'DifferentialDAO' => 'applications/differential/storage/DifferentialDAO.php', ··· 387 389 'DifferentialFieldSpecificationIncompleteException' => 'applications/differential/field/exception/DifferentialFieldSpecificationIncompleteException.php', 388 390 'DifferentialFieldValidationException' => 'applications/differential/field/exception/DifferentialFieldValidationException.php', 389 391 'DifferentialFreeformFieldSpecification' => 'applications/differential/field/specification/DifferentialFreeformFieldSpecification.php', 390 - 'DifferentialFreeformFieldTestCase' => 'applications/differential/field/specification/__tests__/DifferentialFreeformFieldTestCase.php', 391 392 'DifferentialGetWorkingCopy' => 'applications/differential/DifferentialGetWorkingCopy.php', 392 393 'DifferentialGitSVNIDFieldSpecification' => 'applications/differential/field/specification/DifferentialGitSVNIDFieldSpecification.php', 393 394 'DifferentialHostFieldSpecification' => 'applications/differential/field/specification/DifferentialHostFieldSpecification.php', ··· 2876 2877 'DifferentialCustomFieldDependsOnParser' => 'PhabricatorCustomFieldMonogramParser', 2877 2878 'DifferentialCustomFieldDependsOnParserTestCase' => 'PhabricatorTestCase', 2878 2879 'DifferentialCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage', 2880 + 'DifferentialCustomFieldRevertsParser' => 'PhabricatorCustomFieldMonogramParser', 2881 + 'DifferentialCustomFieldRevertsParserTestCase' => 'PhabricatorTestCase', 2879 2882 'DifferentialCustomFieldStorage' => 'PhabricatorCustomFieldStorage', 2880 2883 'DifferentialCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage', 2881 2884 'DifferentialDAO' => 'PhabricatorLiskDAO', ··· 2908 2911 'DifferentialFieldSpecificationIncompleteException' => 'Exception', 2909 2912 'DifferentialFieldValidationException' => 'Exception', 2910 2913 'DifferentialFreeformFieldSpecification' => 'DifferentialFieldSpecification', 2911 - 'DifferentialFreeformFieldTestCase' => 'PhabricatorTestCase', 2912 2914 'DifferentialGitSVNIDFieldSpecification' => 'DifferentialFieldSpecification', 2913 2915 'DifferentialHostFieldSpecification' => 'DifferentialFieldSpecification', 2914 2916 'DifferentialHovercardEventListener' => 'PhabricatorEventListener',
+1 -1
src/applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php
··· 26 26 } 27 27 28 28 protected function getMonogramPattern() { 29 - return 'D\d+'; 29 + return '[Dd]\d+'; 30 30 } 31 31 32 32 }
+51
src/applications/differential/field/parser/DifferentialCustomFieldRevertsParser.php
··· 1 + <?php 2 + 3 + final class DifferentialCustomFieldRevertsParser 4 + extends PhabricatorCustomFieldMonogramParser { 5 + 6 + protected function getPrefixes() { 7 + 8 + // NOTE: Git language is "This reverts commit X." 9 + // NOTE: Mercurial language is "Backed out changeset Y". 10 + 11 + return array( 12 + 'revert', 13 + 'reverts', 14 + 'reverted', 15 + 'backout', 16 + 'backsout', 17 + 'backedout', 18 + 'back out', 19 + 'backs out', 20 + 'backed out', 21 + 'undo', 22 + 'undoes', 23 + ); 24 + } 25 + 26 + protected function getInfixes() { 27 + return array( 28 + 'commit', 29 + 'commits', 30 + 'change', 31 + 'changes', 32 + 'changeset', 33 + 'changesets', 34 + 'rev', 35 + 'revs', 36 + 'revision', 37 + 'revisions', 38 + 'diff', 39 + 'diffs', 40 + ); 41 + } 42 + 43 + protected function getSuffixes() { 44 + return array(); 45 + } 46 + 47 + protected function getMonogramPattern() { 48 + return '[rA-Z0-9a-f]+'; 49 + } 50 + 51 + }
+3 -3
src/applications/differential/field/parser/__tests__/DifferentialCustomFieldDependsOnParserTestCase.php
··· 27 27 'offset' => 0, 28 28 ), 29 29 ), 30 - 'depends on D123, D124' => array( 30 + 'depends on D123, d124' => array( 31 31 array( 32 - 'match' => 'depends on D123, D124', 32 + 'match' => 'depends on D123, d124', 33 33 'prefix' => 'depends on', 34 34 'infix' => '', 35 - 'monograms' => array('D123', 'D124'), 35 + 'monograms' => array('D123', 'd124'), 36 36 'suffix' => '', 37 37 'offset' => 0, 38 38 ),
+92
src/applications/differential/field/parser/__tests__/DifferentialCustomFieldRevertsParserTestCase.php
··· 1 + <?php 2 + 3 + final class DifferentialCustomFieldRevertsParserTestCase 4 + extends PhabricatorTestCase { 5 + 6 + public function testParser() { 7 + $map = array( 8 + 'quack quack quack' => array(), 9 + 10 + // Git default message. 11 + 'This reverts commit 1234abcd.' => array( 12 + array( 13 + 'match' => 'reverts commit 1234abcd', 14 + 'prefix' => 'reverts', 15 + 'infix' => 'commit', 16 + 'monograms' => array('1234abcd'), 17 + 'suffix' => '', 18 + 'offset' => 5, 19 + ), 20 + ), 21 + 22 + // Mercurial default message. 23 + 'Backed out changeset 1234abcd.' => array( 24 + array( 25 + 'match' => 'Backed out changeset 1234abcd', 26 + 'prefix' => 'Backed out', 27 + 'infix' => 'changeset', 28 + 'monograms' => array('1234abcd'), 29 + 'suffix' => '', 30 + 'offset' => 0, 31 + ), 32 + ), 33 + 34 + 'this undoes 1234abcd, 5678efab. they were bad' => array( 35 + array( 36 + 'match' => 'undoes 1234abcd, 5678efab', 37 + 'prefix' => 'undoes', 38 + 'infix' => '', 39 + 'monograms' => array('1234abcd', '5678efab'), 40 + 'suffix' => '', 41 + 'offset' => 5, 42 + ), 43 + ), 44 + 45 + "Reverts 123" => array( 46 + array( 47 + 'match' => 'Reverts 123', 48 + 'prefix' => 'Reverts', 49 + 'infix' => '', 50 + 'monograms' => array('123'), 51 + 'suffix' => '', 52 + 'offset' => 0, 53 + ), 54 + ), 55 + 56 + 57 + "Reverts r123" => array( 58 + array( 59 + 'match' => 'Reverts r123', 60 + 'prefix' => 'Reverts', 61 + 'infix' => '', 62 + 'monograms' => array('r123'), 63 + 'suffix' => '', 64 + 'offset' => 0, 65 + ), 66 + ), 67 + 68 + "Backs out commit\n99\n100" => array( 69 + array( 70 + 'match' => "Backs out commit\n99\n100", 71 + 'prefix' => 'Backs out', 72 + 'infix' => 'commit', 73 + 'monograms' => array('99', '100'), 74 + 'suffix' => '', 75 + 'offset' => 0, 76 + ), 77 + ), 78 + 79 + "This doesn't revert anything" => array(), 80 + 'nonrevert of r11' => array(), 81 + "fixed a bug" => array(), 82 + ); 83 + 84 + foreach ($map as $input => $expect) { 85 + $parser = new DifferentialCustomFieldRevertsParser(); 86 + $output = $parser->parseCorpus($input); 87 + 88 + $this->assertEqual($expect, $output, $input); 89 + } 90 + } 91 + 92 + }
-31
src/applications/differential/field/specification/__tests__/DifferentialFreeformFieldTestCase.php
··· 1 - <?php 2 - 3 - final class DifferentialFreeformFieldTestCase extends PhabricatorTestCase { 4 - 5 - public function testRevertedCommitParser() { 6 - $map = array( 7 - "Reverts 123" => array('123'), 8 - "Reverts r123" => array('r123'), 9 - "Reverts ac382f2" => array('ac382f2'), 10 - "Reverts r22, r23" => array('r22', 'r23'), 11 - "Reverts D99" => array('D99'), 12 - "Backs out commit\n99\n100" => array('99', '100'), 13 - "undo change f9f9f8f8" => array('f9f9f8f8'), 14 - "Backedout Changeset rX1234" => array('rX1234'), 15 - "This doesn't revert anything" => array(), 16 - 'nonrevert of r11' => array(), 17 - "fixed a bug" => array(), 18 - ); 19 - 20 - foreach ($map as $input => $expect) { 21 - $actual = array_values( 22 - DifferentialFreeformFieldSpecification::findRevertedCommits($input)); 23 - 24 - $this->assertEqual( 25 - $expect, 26 - $actual, 27 - "Reverted commits in: {$input}"); 28 - } 29 - } 30 - 31 - }
+2 -2
src/infrastructure/customfield/parser/PhabricatorCustomFieldMonogramParser.php
··· 27 27 '((?:'.$monogram_pattern.'[,\s]*)+)'. 28 28 $suffix_regex. 29 29 '(?:$|\b)'. 30 - '/i'; 30 + '/'; 31 31 32 32 $matches = null; 33 33 $ok = preg_match_all( ··· 65 65 $maybe_tail = $final ? '' : '\s+'; 66 66 $maybe_optional = $optional ? '?' : ''; 67 67 68 - return '(?:('.$parts.')'.$maybe_tail.')'.$maybe_optional; 68 + return '(?i:('.$parts.')'.$maybe_tail.')'.$maybe_optional; 69 69 } 70 70 71 71 }