diff --git a/src/applications/diffusion/config/PhabricatorDiffusionConfigOptions.php b/src/applications/diffusion/config/PhabricatorDiffusionConfigOptions.php index d002498baa..8853a55425 100644 --- a/src/applications/diffusion/config/PhabricatorDiffusionConfigOptions.php +++ b/src/applications/diffusion/config/PhabricatorDiffusionConfigOptions.php @@ -65,6 +65,21 @@ final class PhabricatorDiffusionConfigOptions pht("Disable Closing 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', array()) + ->addExample(array('\B#([1-9]\d*)\b'), pht('Issue #123')) + ->addExample(array('(?setDescription(pht( + 'Regular expression to link external bug tracker. See '. + 'http://tortoisesvn.net/docs/release/TortoiseSVN_en/'. + 'tsvn-dug-bugtracker.html for further explanation.')), ); } diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php index f5872c04aa..16fe0d999a 100644 --- a/src/applications/diffusion/controller/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/DiffusionCommitController.php @@ -90,13 +90,20 @@ final class DiffusionCommitController extends DiffusionController { $property_list->addProperty($key, $value); } + $message = $commit_data->getCommitMessage(); + + $revision = $commit->getCommitIdentifier(); + $message = $repository->linkBugtraq($message, $revision); + + $message = $engine->markupText($message); + $property_list->addTextContent( phutil_tag( 'div', array( 'class' => 'diffusion-commit-message phabricator-remarkup', ), - $engine->markupText($commit_data->getCommitMessage()))); + $message)); $content[] = $top_anchor; $content[] = $headsup_view; diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index ebc97a3813..56c06b5456 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -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 )----------------------------------------- */