From b8d14f4c5025e0c793434f45570a336ac6a1e9f0 Mon Sep 17 00:00:00 2001 From: SirLouen Date: Sun, 25 Jan 2026 00:24:54 +0100 Subject: [PATCH] Slack: Add support for Workflow Keyword notifications in Slack integration --- .../includes/slack/trac/comment-handler.php | 26 ++++++++++++++++++- common/includes/slack/trac/config.php | 8 ++++++ common/includes/slack/trac/trac.php | 9 +++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/common/includes/slack/trac/comment-handler.php b/common/includes/slack/trac/comment-handler.php index 20af37140e..212ec45f3e 100644 --- a/common/includes/slack/trac/comment-handler.php +++ b/common/includes/slack/trac/comment-handler.php @@ -25,6 +25,22 @@ function run() { if ( $firehose ) { $this->send->send( $firehose ); } + + // Send notifications for Workflow Keyword additions + $this->send_keyword_notifications(); + } + + function send_keyword_notifications() { + if ( empty( $this->keywords_added ) ) { + return; + } + + foreach ( $this->keywords_added as $keyword ) { + $channels = $this->trac->get_keyword_channels( $keyword ); + foreach ( $channels as $channel ) { + $this->send->send( $channel ); + } + } } function process_message() { @@ -168,6 +184,7 @@ function process_message() { array_shift( $lines ); $changes = $comment = array(); + $this->keywords_added = array(); // Check if the summary of a ticket was changed. if ( preg_match( '/ \(was: (.*)\)$/', $subject, $matches ) ) { @@ -180,7 +197,14 @@ function process_message() { if ( preg_match( '~Attachment "([^"]+)" (added|removed)\.$~', $line, $matches ) ) { // * Attachment "test.txt" added/removed. $changes[] = "_*attachment:*_ `{$matches[1]}` {$matches[2]}"; - } else { // * status: assigned => closed + } else { + // Track keywords added for Workflow Keyword notifications. + if ( preg_match( '~^ \* keywords: (.*) => (.*)$~', $line, $kw_matches ) ) { + $old_keywords = array_filter( array_map( 'trim', explode( ' ', $kw_matches[1] ) ) ); + $new_keywords = array_filter( array_map( 'trim', explode( ' ', $kw_matches[2] ) ) ); + $this->keywords_added = array_diff( $new_keywords, $old_keywords ); + } + // Applies Slack formatting for other changes. $changes[] = preg_replace( '~^ \* (.*?): ~', '_*$1:*_ ', $line ); } } diff --git a/common/includes/slack/trac/config.php b/common/includes/slack/trac/config.php index 9576b286c8..bb7d2740a2 100644 --- a/common/includes/slack/trac/config.php +++ b/common/includes/slack/trac/config.php @@ -59,6 +59,14 @@ class Core extends Trac { '#^php[a-z]+\.xml\.dist$#' => '#core-build-test-tools', ); + /** + * Workflow keywords that cause ticket updates to be piped to particular channels. + * These trigger when the keyword is added to a ticket. + */ + protected $ticket_keyword_filters = array( + 'needs-testing' => '#core-test', + ); + /** * Components or focuses that cause new tickets to be piped to particular channels. */ diff --git a/common/includes/slack/trac/trac.php b/common/includes/slack/trac/trac.php index 874cf60058..248ca6ed1a 100644 --- a/common/includes/slack/trac/trac.php +++ b/common/includes/slack/trac/trac.php @@ -23,6 +23,7 @@ class Trac implements User { protected $commit_path_filters = array(); protected $ticket_component_filters = array(); + protected $ticket_keyword_filters = array(); protected $color = '#0073aa'; protected $icon = ':wordpress:'; @@ -284,6 +285,14 @@ function get_firehose_channel() { return $this->firehose_channel; } + function get_keyword_channels( $keyword ) { + if ( isset( $this->ticket_keyword_filters[ $keyword ] ) ) { + $channel = $this->ticket_keyword_filters[ $keyword ]; + return is_array( $channel ) ? array_keys( array_filter( $channel ) ) : array( $channel ); + } + return array(); + } + function get_ticket_format( $channel ) { if ( $channel === $this->primary_channel ) { return $this->primary_channel_ticket_format;