1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Use PhutilBugtraqParser in Phabricator

Summary: Fixes T3840. Depends on D7021. See task for discussion. Also improved some config/help stuff.

Test Plan: See screenshot.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3840

Differential Revision: https://secure.phabricator.com/D7022
This commit is contained in:
epriestley 2013-09-18 10:13:00 -07:00
parent 3b9037fa2a
commit 7d26252a3f
4 changed files with 25 additions and 54 deletions

View file

@ -486,7 +486,6 @@ final class PhabricatorConfigEditController
if (is_array($value)) {
$value = implode("\n", $value);
}
$value = phutil_escape_html_newlines($value);
}
$table[] = hsprintf(

View file

@ -79,6 +79,7 @@ final class PhabricatorDiffusionConfigOptions
array('/[Ii]ssues?:?(\s*,?\s*#\d+)+/', '/(\d+)/'),
pht('Issue #123, #456'))
->addExample(array('/(?<!#)\b(T[1-9]\d*)\b/'), pht('Task T123'))
->addExample('/[A-Z]{2,}-\d+/', pht('JIRA-1234'))
->setDescription(pht(
'Regular expression to link external bug tracker. See '.
'http://tortoisesvn.net/docs/release/TortoiseSVN_en/'.

View file

@ -106,7 +106,7 @@ final class DiffusionCommitController extends DiffusionController {
$message = $commit_data->getCommitMessage();
$revision = $commit->getCommitIdentifier();
$message = $repository->linkBugtraq($message, $revision);
$message = $this->linkBugtraq($message);
$message = $engine->markupText($message);
@ -999,4 +999,27 @@ final class DiffusionCommitController extends DiffusionController {
return $view;
}
private function linkBugtraq($corpus) {
$url = PhabricatorEnv::getEnvConfig('bugtraq.url');
if (!strlen($url)) {
return $corpus;
}
$regexes = PhabricatorEnv::getEnvConfig('bugtraq.logregex');
if (!$regexes) {
return $corpus;
}
$parser = id(new PhutilBugtraqParser())
->setBugtraqPattern("[[ {$url} | %BUGID% ]]")
->setBugtraqCaptureExpression(array_shift($regexes));
$select = array_shift($regexes);
if ($select) {
$parser->setBugtraqSelectExpression($select);
}
return $parser->processCorpus($corpus);
}
}

View file

@ -692,58 +692,6 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
}
/**
* Link external bug tracking system if defined.
*
* @param string Plain text.
* @param string Commit identifier.
* @return string Remarkup
*/
public function linkBugtraq($message, $revision = null) {
$bugtraq_url = PhabricatorEnv::getEnvConfig('bugtraq.url');
list($bugtraq_re, $id_re) =
PhabricatorEnv::getEnvConfig('bugtraq.logregex') +
array('', '');
switch ($this->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
// TODO: Get bugtraq:logregex and bugtraq:url from SVN properties.
break;
}
if (!$bugtraq_url || $bugtraq_re == '') {
return $message;
}
$matches = null;
$flags = PREG_SET_ORDER | PREG_OFFSET_CAPTURE;
preg_match_all($bugtraq_re, $message, $matches, $flags);
foreach ($matches as $match) {
list($all, $all_offset) = array_shift($match);
if ($id_re != '') {
// Match substrings with bug IDs
preg_match_all($id_re, $all, $match, PREG_OFFSET_CAPTURE);
list(, $match) = $match;
} else {
$all_offset = 0;
}
$match = array_reverse($match);
foreach ($match as $val) {
list($s, $offset) = $val;
$message = substr_replace(
$message,
'[[ '.str_replace('%BUGID%', $s, $bugtraq_url).' | '.$s.' ]]',
$offset + $all_offset,
strlen($s));
}
}
return $message;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */