Making WordPress.org


Ignore:
Timestamp:
05/05/2016 12:59:30 PM (8 years ago)
Author:
ocean90
Message:

Slack: Improve notifications for ticket summary changes.

  • Parse the subject of a Trac mail because it's the only place where summary changes are mentioned.
  • Include ticket summary changes in the "changes" section.
  • Fall back to "Someone" if the author property isn't set. That's the case for summary only changes.

Fixes #1368.

File:
1 edited

Legend:

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

    r3086 r3087  
    3131        $lines = array_map( 'rtrim', $this->lines );
    3232        $base64 = false;
     33        $subject = '';
    3334
    3435        // Trim off headers.
     
    4748            } elseif ( 0 === strpos( $line, 'Content-Transfer-Encoding: base64' ) ) {
    4849                $base64 = true;
     50            } elseif ( 0 === strpos( $line, 'Subject:' ) ) {
     51                $subject = str_replace( 'Subject: ', '', $line );
     52
     53                $subject_lines = $lines;
     54                while ( $subject_lines && ! preg_match( '/(^[\x21-\x7E][^:]+):/', current( $subject_lines ) ) ) {
     55                    $subject .= array_shift( $subject_lines );
     56                }
     57                unset( $subject_lines );
    4958            }
    5059        }
     
    106115
    107116        $changes = $comment = array();
     117
     118        // Check if the summary of a ticket was changed.
     119        if ( preg_match( '/ \(was: (.*)\)$/', $subject, $matches ) ) {
     120            $changes[] = '_*summary:*_ ' . $matches[1] . ' => ' . $title;
     121        }
     122
    108123        if ( $has_changes ) {
    109124            while ( $lines && '' !== current( $lines ) ) {
     
    157172        $comment         = $this->format_comment_for_slack();
    158173        $main_attachment = $this->changes ? implode( "\n", $this->changes ) : $comment;
    159         $pretext         = sprintf( '*%s updated <%s|#%s %s>*', $this->author, $this->comment_url, $this->ticket_id, htmlspecialchars( $this->title, ENT_NOQUOTES ) );
     174        $author          = $this->author ? $this->author : 'Someone';
     175        $pretext         = sprintf( '*%s updated <%s|#%s %s>*', $author, $this->comment_url, $this->ticket_id, htmlspecialchars( $this->title, ENT_NOQUOTES ) );
    160176        $fallback        = trim( $pretext, '*' ) . "\n" . $main_attachment;
    161177
Note: See TracChangeset for help on using the changeset viewer.