Making WordPress.org

Changeset 7064


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

Slack/Trac: Add support for attachment notification mails.

See #3526.

Location:
sites/trunk
Files:
2 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        }
  • sites/trunk/svn.wordpress.org/bin/slack-trac-hook.php

    r3062 r7064  
    2424    $ticket_base_url = $matches[3];
    2525    $ticket = $matches[4];
    26     $type = isset( $matches[5] ) ? 'comment' : 'ticket';
     26    // Attachment notifcations use the ticket URL, check for attachment change line and process mail as comment on match.
     27    $is_attachment = (bool) preg_grep( '/^ \* Attachment "([^"]+)"/', $lines );
     28    $type = ( isset( $matches[5] ) || $is_attachment ) ? 'comment' : 'ticket';
    2729    preg_match( '~^https?://([^.]+)\.trac~i', $ticket_base_url, $matches );
    2830    $trac = $matches[1];
Note: See TracChangeset for help on using the changeset viewer.