@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.

Be more lenient when accepting "Differential Revision" in the presence of custom ad-hoc commit message fields

Summary:
Fixes T8360. We will now parse revisions out of "Differential Revision: X" followed by other ad-hoc fields which we do not recognize. Previously, these fields would be treated as part of the value.

(In the general case, other fields may line wrap so we can't assume that fields are only one line long. However, we can make that assumption safely for this field.)

Also maybe fix whatever was going on in T9965 although that didn't really have a reproduction case.

Test Plan: Added unit tests.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T8360

Differential Revision: https://secure.phabricator.com/D17121

+54 -2
+2
src/__phutil_library_map__.php
··· 381 381 'DifferentialCloseConduitAPIMethod' => 'applications/differential/conduit/DifferentialCloseConduitAPIMethod.php', 382 382 'DifferentialCommitMessageCustomField' => 'applications/differential/field/DifferentialCommitMessageCustomField.php', 383 383 'DifferentialCommitMessageField' => 'applications/differential/field/DifferentialCommitMessageField.php', 384 + 'DifferentialCommitMessageFieldTestCase' => 'applications/differential/field/__tests__/DifferentialCommitMessageFieldTestCase.php', 384 385 'DifferentialCommitMessageParser' => 'applications/differential/parser/DifferentialCommitMessageParser.php', 385 386 'DifferentialCommitMessageParserTestCase' => 'applications/differential/parser/__tests__/DifferentialCommitMessageParserTestCase.php', 386 387 'DifferentialCommitsField' => 'applications/differential/customfield/DifferentialCommitsField.php', ··· 5030 5031 'DifferentialCloseConduitAPIMethod' => 'DifferentialConduitAPIMethod', 5031 5032 'DifferentialCommitMessageCustomField' => 'DifferentialCommitMessageField', 5032 5033 'DifferentialCommitMessageField' => 'Phobject', 5034 + 'DifferentialCommitMessageFieldTestCase' => 'PhabricatorTestCase', 5033 5035 'DifferentialCommitMessageParser' => 'Phobject', 5034 5036 'DifferentialCommitMessageParserTestCase' => 'PhabricatorTestCase', 5035 5037 'DifferentialCommitsField' => 'DifferentialCustomField',
+18 -1
src/applications/differential/field/DifferentialRevisionIDCommitMessageField.php
··· 18 18 } 19 19 20 20 public function parseFieldValue($value) { 21 - // If the value is just "D123" or similar, parse the ID from it directly. 21 + // If the complete commit message we are parsing has unrecognized custom 22 + // fields at the end, they can end up parsed into the field value for this 23 + // field. For example, if the message looks like this: 24 + 25 + // Differential Revision: xyz 26 + // Some-Other-Field: abc 27 + 28 + // ...we will receive "xyz\nSome-Other-Field: abc" as the field value for 29 + // this field. Ideally, the install would define these fields so they can 30 + // parse formally, but we can reasonably assume that only the first line 31 + // of any value we encounter actually contains a revision identifier, so 32 + // start by throwing away any other lines. 33 + 34 + $value = trim($value); 35 + $value = phutil_split_lines($value, false); 36 + $value = head($value); 22 37 $value = trim($value); 38 + 39 + // If the value is just "D123" or similar, parse the ID from it directly. 23 40 $matches = null; 24 41 if (preg_match('/^[dD]([1-9]\d*)\z/', $value, $matches)) { 25 42 return (int)$matches[1];
+30
src/applications/differential/field/__tests__/DifferentialCommitMessageFieldTestCase.php
··· 1 + <?php 2 + 3 + final class DifferentialCommitMessageFieldTestCase 4 + extends PhabricatorTestCase { 5 + 6 + public function testRevisionCommitMessageFieldParsing() { 7 + $base_uri = 'https://www.example.com/'; 8 + 9 + $tests = array( 10 + 'D123' => 123, 11 + 'd123' => 123, 12 + " \n d123 \n " => 123, 13 + "D123\nSome-Custom-Field: The End" => 123, 14 + "{$base_uri}D123" => 123, 15 + "{$base_uri}D123\nSome-Custom-Field: The End" => 123, 16 + ); 17 + 18 + $env = PhabricatorEnv::beginScopedEnv(); 19 + $env->overrideEnvConfig('phabricator.base-uri', $base_uri); 20 + 21 + foreach ($tests as $input => $expect) { 22 + $actual = id(new DifferentialRevisionIDCommitMessageField()) 23 + ->parseFieldValue($input); 24 + $this->assertEqual($expect, $actual, pht('Parse of: %s', $input)); 25 + } 26 + 27 + unset($env); 28 + } 29 + 30 + }
+4 -1
src/applications/differential/parser/DifferentialCommitMessageParser.php
··· 155 155 $field = $key_title; 156 156 157 157 $seen = array(); 158 - $lines = explode("\n", trim($corpus)); 158 + 159 + $lines = trim($corpus); 160 + $lines = phutil_split_lines($lines, false); 161 + 159 162 $field_map = array(); 160 163 foreach ($lines as $key => $line) { 161 164 $match = null;