Making WordPress.org

Changeset 11020


Ignore:
Timestamp:
06/08/2021 06:06:51 AM (3 years ago)
Author:
dd32
Message:

API: Slack Trac Bot: Don't expand #1234 references within the #core-editor channel as being Core trac tickets, they're usually GitHub issues.

This still expands #core1234 and full core trac links.

See https://wordpress.slack.com/archives/C02QB2JS7/p1623129409360200?thread_ts=1623129305.358300&cid=C02QB2JS7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/common/includes/slack/trac/bot.php

    r10160 r11020  
    1313        '#meta'         => 'meta',
    1414        '#outreach'     => false,
     15    );
     16
     17    // Channels that are primarily GitHub issues, where digit-only tickets should not be expanded.
     18    static protected $github_channels = array(
     19        '#core-editor',
    1520    );
    1621
     
    4449
    4550    function parse_tickets( $text ) {
    46         $digits = Trac::get_digit_capture();
     51        $digits       = Trac::get_digit_capture();
    4752        $ticket_tracs = '?<trac>' . Trac::get_regex();
    48         preg_match_all( "/(?:\s|^|\()#(?<id>$digits)(?:\-($ticket_tracs))?\b/", $text, $tickets, PREG_SET_ORDER );
     53        $tickets      = array();
     54
     55        // If the channel is not GitHub centric, match #1234 as a Trac ticket
     56        if ( ! in_array( $this->get_channel(), $this->github_channels, true ) ) {
     57            preg_match_all( "/(?:\s|^|\()#(?<id>$digits)(?:\-($ticket_tracs))?\b/", $text, $tickets, PREG_SET_ORDER );
     58        }
     59
     60        // Always match trac-prefixed Tickets
    4961        preg_match_all( "/(?:\s|^|\()#($ticket_tracs)(?<id>$digits)\b/", $text, $tickets_alt, PREG_SET_ORDER );
     62
     63        // Always match full URI's
    5064        preg_match_all( "~https?://($ticket_tracs).trac.wordpress.org/ticket/(?<id>$digits)~", $text, $tickets_url, PREG_SET_ORDER );
     65
    5166        foreach ( $tickets_url as &$ticket ) {
    5267            $ticket['url'] = true;
Note: See TracChangeset for help on using the changeset viewer.