Making WordPress.org


Ignore:
Timestamp:
04/08/2018 11:43:27 AM (8 years ago)
Author:
ocean90
Message:

Slack/Trac: Add support for attachment notification mails.

See #3526.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/common/includes/slack/trac/comment-handler.php

    r7041 r7064  
    3737                        $line = array_shift( $lines );
    3838                        if ( 0 === strpos( $line, 'X-Trac-Ticket-URL:' ) ) {
    39                                 // X-Trac-Ticket-URL: https://core.trac.wordpress.org/ticket/12345#comment:1
     39                                $comment_id = 0;
    4040                                list( , $comment_url ) = explode( ': ', $line );
    41                                 list( $ticket_url, $comment_id ) = explode( '#comment:', $comment_url );
     41
     42                                // Get ticket URL, attachment notifcations have no specific URL.
     43                                if ( false !== strpos( $line, '#comment:' ) ) {
     44                                        // X-Trac-Ticket-URL: https://core.trac.wordpress.org/ticket/12345#comment:1
     45                                        list( $ticket_url, $comment_id ) = explode( '#comment:', $comment_url );
     46                                } else {
     47                                        // X-Trac-Ticket-URL: https://core.trac.wordpress.org/ticket/12345
     48                                        $ticket_url = $comment_url;
     49                                }
     50
    4251                                list( $trac_url, $ticket_id ) = explode( '/ticket/', $ticket_url );
    4352
     
    167176                if ( $has_changes ) {
    168177                        while ( $lines && '' !== current( $lines ) ) {
    169                                 $changes[] = preg_replace( '~^ \* (.*?):  ~', '_*$1:*_ ', array_shift( $lines ) );
     178                                $line = array_shift( $lines );
     179
     180                                if ( preg_match( '~Attachment "([^"]+)" (added|removed)\.$~', $line, $matches ) ) { // * Attachment "test.txt" added/removed.
     181                                        $changes[] = "_*attachment:*_ `{$matches[1]}` {$matches[2]}";
     182                                } else { // * status:  assigned => closed
     183                                        $changes[] = preg_replace( '~^ \* (.*?):  ~', '_*$1:*_ ', $line );
     184                                }
    170185                        }
    171186                }
Note: See TracChangeset for help on using the changeset viewer.