mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-09 22:31:03 +01:00
Link external bug trackers
Summary: Fixes T2971. Test Plan: /rG1. Set regexp to one line and URL, then /rG1. Set regexp to two lines, then /rG1. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2971 Differential Revision: https://secure.phabricator.com/D5676
This commit is contained in:
parent
e6720bd6d6
commit
6a5807eba4
3 changed files with 73 additions and 1 deletions
|
@ -65,6 +65,21 @@ final class PhabricatorDiffusionConfigOptions
|
||||||
pht("Disable Closing Audits"),
|
pht("Disable Closing Audits"),
|
||||||
))
|
))
|
||||||
->setDescription(pht('Controls whether Author can Close Audits.')),
|
->setDescription(pht('Controls whether Author can Close Audits.')),
|
||||||
|
|
||||||
|
$this->newOption('bugtraq.url', 'string', '')
|
||||||
|
->addExample('https://bugs.php.net/%BUGID%', pht('PHP bugs'))
|
||||||
|
->addExample('/%BUGID%', pht('Local Maniphest URL'))
|
||||||
|
->setDescription(pht(
|
||||||
|
'URL of external bug tracker used by Diffusion. %s will be '.
|
||||||
|
'substituted by the bug ID.',
|
||||||
|
'%BUGID%')),
|
||||||
|
$this->newOption('bugtraq.logregex', 'list<string>', array())
|
||||||
|
->addExample(array('\B#([1-9]\d*)\b'), pht('Issue #123'))
|
||||||
|
->addExample(array('(?<!#)\b(T[1-9]\d*)\b'), pht('Task T123'))
|
||||||
|
->setDescription(pht(
|
||||||
|
'Regular expression to link external bug tracker. See '.
|
||||||
|
'http://tortoisesvn.net/docs/release/TortoiseSVN_en/'.
|
||||||
|
'tsvn-dug-bugtracker.html for further explanation.')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,13 +90,20 @@ final class DiffusionCommitController extends DiffusionController {
|
||||||
$property_list->addProperty($key, $value);
|
$property_list->addProperty($key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$message = $commit_data->getCommitMessage();
|
||||||
|
|
||||||
|
$revision = $commit->getCommitIdentifier();
|
||||||
|
$message = $repository->linkBugtraq($message, $revision);
|
||||||
|
|
||||||
|
$message = $engine->markupText($message);
|
||||||
|
|
||||||
$property_list->addTextContent(
|
$property_list->addTextContent(
|
||||||
phutil_tag(
|
phutil_tag(
|
||||||
'div',
|
'div',
|
||||||
array(
|
array(
|
||||||
'class' => 'diffusion-commit-message phabricator-remarkup',
|
'class' => 'diffusion-commit-message phabricator-remarkup',
|
||||||
),
|
),
|
||||||
$engine->markupText($commit_data->getCommitMessage())));
|
$message));
|
||||||
|
|
||||||
$content[] = $top_anchor;
|
$content[] = $top_anchor;
|
||||||
$content[] = $headsup_view;
|
$content[] = $headsup_view;
|
||||||
|
|
|
@ -634,6 +634,56 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue