summary refs log tree commit diff
path: root/MantisSmalltech.php
diff options
context:
space:
mode:
Diffstat (limited to 'MantisSmalltech.php')
-rw-r--r--MantisSmalltech.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/MantisSmalltech.php b/MantisSmalltech.php
index fcdb162..df6a984 100644
--- a/MantisSmalltech.php
+++ b/MantisSmalltech.php
@@ -41,6 +41,7 @@ class MantisSmalltechPlugin extends MantisPlugin  {
   function hooks() {
     $t_hooks = array(
       'EVENT_DISPLAY_BUG_ID' => 'display_bug_id',
+      'EVENT_DISPLAY_FORMATTED' => 'display_formatted',
     );
 
     return $t_hooks;
@@ -49,4 +50,26 @@ class MantisSmalltechPlugin extends MantisPlugin  {
   function display_bug_id( $p_event_name, $p_string, $p_number ) {
     return sprintf( 'b/%u', $p_number );
   }
+
+
+  function display_formatted( $p_event, $p_string, $p_multiline = true ):
+      string
+  {
+    /* This is better documented in the Gerrit config. If you read that one
+     * first, there's just two things to keep in mind about this one.
+     *
+     * 1. Gerrit applies HTML-escaping to the input prior to letting us see
+     *    it, Mantis gives us raw input.
+     *
+     * 2. Gerrit expects HTML output; Mantis expects Markdown.
+     */
+    $p_string = preg_replace(
+      '/(?<=(?:^|(?<=\\s)))((?:[\\(\\[\\{\'"])*)'
+      . 'cl\\/(\\d+)'
+      . '(?=(?:[\\.,;?!\\)\\]\\}\'"])*(?:$|(?=\\s)))/',
+      '\\1[cl/\\2](https://gerrit.internetsafetylabs.org/c/\\2)',
+      $p_string);
+
+    return $p_string;
+  }
 }