summary refs log tree commit diff
path: root/MantisSmalltech.php
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@internetsafetylabs.org>2025-10-08 06:59:43 -0700
committerIrene Knapp <ireneista@internetsafetylabs.org>2025-10-08 06:59:43 -0700
commitca9e5d974a7add7ab0e25e0076a7e77e2b7072e1 (patch)
treee7df32dccf4a0d593bea406fe76d861f86d37495 /MantisSmalltech.php
parent7dad24cb3d807d2aef23583aac2d48b70edb1903 (diff)
the cl/1637 syntax now works (yay!!!!)
Force-Push: initial development in a new repo
Change-Id: Ib9da847b711b7ce4e20fb27d660746ad4e47f6bf
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;
+  }
 }