Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion common/includes/slack/trac/comment-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 ) ) {
Expand All @@ -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 );
}
}
Expand Down
8 changes: 8 additions & 0 deletions common/includes/slack/trac/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
9 changes: 9 additions & 0 deletions common/includes/slack/trac/trac.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:';
Expand Down Expand Up @@ -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;
Expand Down