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',
|
'ManiphestCreateMailReceiver' => 'applications/maniphest/mail/ManiphestCreateMailReceiver.php',
|
||||||
'ManiphestCustomField' => 'applications/maniphest/field/ManiphestCustomField.php',
|
'ManiphestCustomField' => 'applications/maniphest/field/ManiphestCustomField.php',
|
||||||
'ManiphestCustomFieldNumericIndex' => 'applications/maniphest/storage/ManiphestCustomFieldNumericIndex.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',
|
'ManiphestCustomFieldStorage' => 'applications/maniphest/storage/ManiphestCustomFieldStorage.php',
|
||||||
'ManiphestCustomFieldStringIndex' => 'applications/maniphest/storage/ManiphestCustomFieldStringIndex.php',
|
'ManiphestCustomFieldStringIndex' => 'applications/maniphest/storage/ManiphestCustomFieldStringIndex.php',
|
||||||
'ManiphestDAO' => 'applications/maniphest/storage/ManiphestDAO.php',
|
'ManiphestDAO' => 'applications/maniphest/storage/ManiphestDAO.php',
|
||||||
|
@ -3498,6 +3500,8 @@ phutil_register_library_map(array(
|
||||||
'ManiphestCreateMailReceiver' => 'PhabricatorMailReceiver',
|
'ManiphestCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||||
'ManiphestCustomField' => 'PhabricatorCustomField',
|
'ManiphestCustomField' => 'PhabricatorCustomField',
|
||||||
'ManiphestCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage',
|
'ManiphestCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage',
|
||||||
|
'ManiphestCustomFieldStatusParser' => 'PhabricatorCustomFieldMonogramParser',
|
||||||
|
'ManiphestCustomFieldStatusParserTestCase' => 'PhabricatorTestCase',
|
||||||
'ManiphestCustomFieldStorage' => 'PhabricatorCustomFieldStorage',
|
'ManiphestCustomFieldStorage' => 'PhabricatorCustomFieldStorage',
|
||||||
'ManiphestCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage',
|
'ManiphestCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage',
|
||||||
'ManiphestDAO' => 'PhabricatorLiskDAO',
|
'ManiphestDAO' => 'PhabricatorLiskDAO',
|
||||||
|
|
|
@ -44,53 +44,36 @@ abstract class DifferentialFreeformFieldSpecification
|
||||||
'' => null,
|
'' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
$prefix_regex = array();
|
$matches = id(new ManiphestCustomFieldStatusParser())
|
||||||
foreach ($prefixes as $prefix => $resolution) {
|
->parseCorpus($message);
|
||||||
$prefix_regex[] = preg_quote($prefix, '/');
|
|
||||||
}
|
|
||||||
$prefix_regex = implode('|', $prefix_regex);
|
|
||||||
|
|
||||||
$suffix_regex = array();
|
$task_statuses = array();
|
||||||
foreach ($suffixes as $suffix => $resolution) {
|
foreach ($matches as $match) {
|
||||||
$suffix_regex[] = preg_quote($suffix, '/');
|
$prefix = phutil_utf8_strtolower($match['prefix']);
|
||||||
}
|
$suffix = phutil_utf8_strtolower($match['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]);
|
|
||||||
|
|
||||||
$status = idx($suffixes, $suffix);
|
$status = idx($suffixes, $suffix);
|
||||||
if (!$status) {
|
if (!$status) {
|
||||||
$status = idx($prefixes, $prefix);
|
$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) {
|
private function findDependentRevisions($message) {
|
||||||
|
$matches = id(new DifferentialCustomFieldDependsOnParser())
|
||||||
|
->parseCorpus($message);
|
||||||
|
|
||||||
$dependents = array();
|
$dependents = array();
|
||||||
|
foreach ($matches as $match) {
|
||||||
$matches = null;
|
foreach ($match['monograms'] as $monogram) {
|
||||||
preg_match_all(
|
$id = (int)trim($monogram, 'dD');
|
||||||
'/\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[$id] = $id;
|
$dependents[$id] = $id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,46 +82,13 @@ abstract class DifferentialFreeformFieldSpecification
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function findRevertedCommits($message) {
|
public static function findRevertedCommits($message) {
|
||||||
$reverts = array();
|
$matches = id(new DifferentialCustomFieldRevertsParser())
|
||||||
$matches = null;
|
->parseCorpus($message);
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($matches[1] as $commits) {
|
foreach ($matches as $match) {
|
||||||
$commits = preg_split('/[,\s]+/', $commits);
|
foreach ($match['monograms'] as $monogram) {
|
||||||
$commits = array_filter($commits);
|
$result[$monogram] = $monogram;
|
||||||
foreach ($commits as $commit) {
|
|
||||||
$result[$commit] = $commit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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],
|
'prefix' => $set[1][0],
|
||||||
'infix' => $set[2][0],
|
'infix' => $set[2][0],
|
||||||
'monograms' => array_filter(preg_split('/[,\s]+/', $set[3][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],
|
'offset' => $set[0][1],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue