Making WordPress.org

Changeset 9900


Ignore:
Timestamp:
05/22/2020 05:52:27 AM (6 years ago)
Author:
dd32
Message:

Trac: When a PR is added to a ticket, toggle the has-patch/needs-patch/needs-refresh and needs-unit-tests/has-unit-tests if it touches a tests-looking directory.

Fixes #5080.

Location:
sites/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/functions.php

    r9898 r9900  
    5959        }
    6060
     61        $touches_tests = false;
     62        $_files = api_request(
     63                '/repos/' . $repo . '/pulls/' . intval( $pr ) . '/files?per_page=999',
     64                null,
     65                [ 'Accept: application/vnd.github.antiope-preview+json' ]
     66        );
     67        foreach ( $_files as $f ) {
     68                if ( preg_match( '!(^tests/|/tests/)!', $f->filename ) ) {
     69                        $touches_tests = true;
     70                        break;
     71                }
     72        }
     73
    6174        return (object) [
    6275                'repo'            => $data->base->repo->full_name,
     
    7184                'check_runs'      => $check_runs,
    7285                'reviews'         => $reviews,
     86                'touches_tests'   => $touches_tests,
    7387                'body'            => $data->body,
    7488                'user'            => (object) [
  • sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/webhook.php

    r9564 r9900  
    8383
    8484                        $pr_description = format_pr_desc_for_trac_comment( $pr_data );
     85                        $attributes     = [];
     86
     87                        // Update ticket keywords if possible.
     88                        $ticket = $trac->get( $pr_data->trac_ticket[1] );
     89                        if ( $ticket ) {
     90                                $keywords = preg_split( '![,\s]+!', $ticket['keywords'] );
     91
     92                                // Remove needs-patch
     93                                if ( false !== ( $key = array_search( 'needs-patch', $keywords ) ) ) {
     94                                        unset( $keywords[ $key ] );
     95                                }
     96                                if ( false !== ( $key = array_search( 'needs-refresh', $keywords ) ) ) {
     97                                        unset( $keywords[ $key ] );
     98                                }
     99
     100                                // Add has-patch if not already there.
     101                                if ( false === array_search( 'has-patch', $keywords ) ) {
     102                                        $keywords[] = 'has-patch';
     103                                }
     104
     105                                if ( $pr_data->touches_tests ) {
     106                                        if ( false !== ( $key = array_search( 'needs-unit-tests', $keywords ) ) ) {
     107                                                unset( $keywords[ $key ] );
     108                                        }
     109                                        if ( false === array_search( 'has-unit-tests', $keywords ) ) {
     110                                                $keywords[] = 'has-unit-tests';
     111                                        }
     112                                }
     113
     114                                $attributes['keywords'] = implode( ' ', $keywords );
     115                        }
    85116
    86117                        $trac->update(
     
    90121                                        "by [{$pr_data->user->url} {$pr_data->user->name}].''" .
    91122                                        ( $pr_description ? "\n{$pr_description}" : '' ),
    92                                 [],  // Attributes changed
     123                                $attributes,  // Attributes changed
    93124                                true // Notify
    94125                        );
  • sites/trunk/trac.wordpress.org/templates/ticket_change.html

    r9531 r9900  
    5959           pr_byline   = change.comment.partition('\n')[0];
    6060           pr_comment  = ''.join(change.comment.partition('\n')[1:]) or False;
    61            prbot_class = 'prbot with-context' if pr_comment else 'prbot without-context';
     61           prbot_class = 'prbot with-context' if pr_comment or change.fields else 'prbot without-context';
    6262         ">
    6363  <h3 class="change chat-bot ${prbot_class}">
     
    7070    </span>
    7171  </h3>
     72  <ul py:if="change.fields" class="changes">
     73    <li py:for="field_name, field in sorted(change.fields.iteritems(), key=lambda item: item[1].label.lower())"
     74        class="trac-field-${field_name}">
     75      <strong class="trac-field-${field_name}">${field.label}</strong>
     76      <py:choose>
     77        <py:when test="'rendered' in field">${field.rendered}</py:when>
     78        <py:when test="field.old and field.new"><i18n:msg params="old, new">
     79          changed from <em>${field.old}</em> to <em>${field.new}</em>
     80        </i18n:msg></py:when>
     81        <py:when test="not field.old and field.new"><i18n:msg params="value">
     82          set to <em>${field.new}</em>
     83        </i18n:msg></py:when>
     84        <py:otherwise><i18n:msg params="value">
     85          <em>${field.old}</em> deleted
     86        </i18n:msg></py:otherwise>
     87      </py:choose>
     88    </li>
     89  </ul>
    7290  <div py:if="pr_comment" class="comment searchable" xml:space="preserve">
    7391    ${wiki_to_html(context, pr_comment, escape_newlines=preserve_newlines)}
Note: See TracChangeset for help on using the changeset viewer.