mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +01:00
Bring "fixes x as y" parser forward and use new parsers instead of old ones
Summary: Fixes T3872. Ref T1812. Ref T3886. Modernize the "closes x as y" string parser, and use all the new parsers instead of the old ones. Test Plan: Made a commit full of a pile of these trigger strings, then used `scripts/repository/reparse.php --message` to reparse it. Verified that parses came back as expected using a bunch of `var_dump()`. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1812, T3872, T3886 Differential Revision: https://secure.phabricator.com/D8263
This commit is contained in:
parent
5afddb6703
commit
8a725ece0f
5 changed files with 149 additions and 73 deletions
|
@ -885,6 +885,8 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'ManiphestCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||
'ManiphestCustomField' => 'PhabricatorCustomField',
|
||||
'ManiphestCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage',
|
||||
'ManiphestCustomFieldStatusParser' => 'PhabricatorCustomFieldMonogramParser',
|
||||
'ManiphestCustomFieldStatusParserTestCase' => 'PhabricatorTestCase',
|
||||
'ManiphestCustomFieldStorage' => 'PhabricatorCustomFieldStorage',
|
||||
'ManiphestCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage',
|
||||
'ManiphestDAO' => 'PhabricatorLiskDAO',
|
||||
|
|
|
@ -44,53 +44,36 @@ abstract class DifferentialFreeformFieldSpecification
|
|||
'' => null,
|
||||
);
|
||||
|
||||
$prefix_regex = array();
|
||||
foreach ($prefixes as $prefix => $resolution) {
|
||||
$prefix_regex[] = preg_quote($prefix, '/');
|
||||
}
|
||||
$prefix_regex = implode('|', $prefix_regex);
|
||||
$matches = id(new ManiphestCustomFieldStatusParser())
|
||||
->parseCorpus($message);
|
||||
|
||||
$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);
|
||||
|
||||
$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) {
|
||||
$matches = id(new DifferentialCustomFieldDependsOnParser())
|
||||
->parseCorpus($message);
|
||||
|
||||
$dependents = array();
|
||||
|
||||
$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) {
|
||||
foreach ($matches as $match) {
|
||||
foreach ($match['monograms'] as $monogram) {
|
||||
$id = (int)trim($monogram, 'dD');
|
||||
$dependents[$id] = $id;
|
||||
}
|
||||
}
|
||||
|
@ -99,46 +82,13 @@ abstract class DifferentialFreeformFieldSpecification
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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+';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
final class ManiphestCustomFieldStatusParserTestCase
|
||||
extends PhabricatorTestCase {
|
||||
|
||||
public function testParser() {
|
||||
$map = array(
|
||||
'quack quack quack' => array(),
|
||||
'T123' => array(),
|
||||
'Fixes T123' => array(
|
||||
array(
|
||||
'match' => 'Fixes T123',
|
||||
'prefix' => 'Fixes',
|
||||
'infix' => '',
|
||||
'monograms' => array('T123'),
|
||||
'suffix' => '',
|
||||
'offset' => 0,
|
||||
),
|
||||
),
|
||||
'Fixes T123, T124, and also some other bugs.' => array(
|
||||
array(
|
||||
'match' => 'Fixes T123, T124, ',
|
||||
'prefix' => 'Fixes',
|
||||
'infix' => '',
|
||||
'monograms' => array('T123', 'T124'),
|
||||
'suffix' => '',
|
||||
'offset' => 0,
|
||||
),
|
||||
),
|
||||
'Closes T1 as wontfix' => array(
|
||||
array(
|
||||
'match' => 'Closes T1 as wontfix',
|
||||
'prefix' => 'Closes',
|
||||
'infix' => '',
|
||||
'monograms' => array('T1'),
|
||||
'suffix' => 'as wontfix',
|
||||
'offset' => 0,
|
||||
),
|
||||
),
|
||||
'Fixes task T9' => array(
|
||||
array(
|
||||
'match' => 'Fixes task T9',
|
||||
'prefix' => 'Fixes',
|
||||
'infix' => 'task',
|
||||
'monograms' => array('T9'),
|
||||
'suffix' => '',
|
||||
'offset' => 0,
|
||||
),
|
||||
),
|
||||
'Fixes t2apps' => array(),
|
||||
'fixes a bug' => array(),
|
||||
'Prefixes T2' => array(),
|
||||
);
|
||||
|
||||
foreach ($map as $input => $expect) {
|
||||
$parser = new ManiphestCustomFieldStatusParser();
|
||||
$output = $parser->parseCorpus($input);
|
||||
|
||||
$this->assertEqual($expect, $output, $input);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -47,7 +47,7 @@ abstract class PhabricatorCustomFieldMonogramParser
|
|||
'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],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue