Making WordPress.org

Changeset 11582


Ignore:
Timestamp:
02/18/2022 05:43:57 AM (3 years ago)
Author:
dd32
Message:

Slack: Don't post a "This ticket was mentioned in.." on old closed Trac tickets.

This still posts the Ticket reference to Slack, but if the ticket has been has been closed over 2 years avoids littering it with references that were probably not about it.

See the ticket for an example of where a GitHub reference posted to a ticket that had been closed for 14 years.

Fixes #3650.

Location:
sites/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/slack/trac-bot.php

    r11359 r11582  
    3838        $slack->set_user( $trac_obj );
    3939
     40        $parsed_objects = array(
     41            'ticket' => array(),
     42            'commit' => array(),
     43        );
     44
    4045        foreach ( $results as $type => $values ) {
    4146            // Loop through all tickets and commits for this Trac.
     
    4651                // Get the Ticket or Commit object for this Trac + ID.
    4752                $obj = call_user_func( array( $class, 'get' ), $trac_obj, $id );
     53
     54                // Keep a reference to this object for later.
     55                $parsed_objects[ $type ][ $id ] = $obj;
    4856
    4957                // Check if we should be posting this to Slack so quickly.
     
    97105        }
    98106
    99         // If there's no tickets referenced (ie. just commits) then there's no need to flag tghe reference on Trac.
     107        // If there's no tickets referenced (ie. just commits) then there's no need to flag the reference on Trac.
    100108        if ( empty( $results['ticket'] ) ) {
    101109            continue;
     
    106114        $comment = sprintf( $comment_template, $_POST['channel_name'], $_POST['user_name'], str_replace( '.', '', $_POST['timestamp'] ) );
    107115        foreach ( $results['ticket'] as $ticket ) {
    108             if ( is_array( $ticket ) ) {
    109                 $ticket = $ticket['id'];
     116            $ticket_id = is_array( $ticket ) ? $ticket['id'] : $ticket;
     117
     118            // If the ticket is closed and hasn't been modified in over 2 years, don't post a reference to it.
     119            if ( ! empty( $parsed_objects[ 'ticket' ][ $ticket_id ] ) ) {
     120                $ticket_object = $parsed_objects[ 'ticket' ][ $ticket_id ];
     121                $ticket_object->fetch();
     122
     123                $is_closed         = ( 'closed' === $ticket_object->status );
     124                $last_modified     = strtotime( $ticket_object->modified );
     125                $has_recent_change = ( ! $last_modified || $last_modified > ( time() - 2 * YEAR_IN_SECONDS ) );
     126
     127                if ( $is_closed && ! $has_recent_change ) {
     128                    continue;
     129                }
    110130            }
    111131
    112             if ( $parser->is_redundant( 'trac', $trac, 'ticket', $ticket ) ) { 
     132            if ( $parser->is_redundant( 'trac', $trac, 'ticket', $ticket_id ) ) {
    113133                continue;
    114134            }
    115             $parser->set_redundancy( 'trac', $trac, 'ticket', $ticket );
    116135
    117             $trac_xmlrpc->ticket_update( $ticket, $comment );
     136            $parser->set_redundancy( 'trac', $trac, 'ticket', $ticket_id );
     137
     138            $trac_xmlrpc->ticket_update( $ticket_id, $comment );
    118139        }
    119140    }
  • sites/trunk/common/includes/slack/trac/ticket.php

    r10001 r11582  
    6464
    6565        $url = sprintf(
    66             '%s/query?id=%s&col=id&col=summary&col=owner&col=type&col=cc&col=status&col=priority&col=milestone&col=component&col=version&col=severity&col=resolution&col=time&col=focuses&col=reporter&col=keywords&col=description&format=csv',
     66            '%s/query?id=%s&col=id&col=summary&col=owner&col=type&col=cc&col=status&col=priority&col=milestone&col=component&col=version&col=severity&col=resolution&col=time&col=changetime&col=focuses&col=reporter&col=keywords&col=description&format=csv',
    6767            $this->trac->get_url(),
    6868            $this->id
Note: See TracChangeset for help on using the changeset viewer.