Making WordPress.org

Changeset 13081


Ignore:
Timestamp:
12/22/2023 06:55:38 AM (16 months ago)
Author:
dd32
Message:

API: GitHub PRs: Tweak how the matching Trac ticket for a PR is found.

This should reduce some cases of the ticket being misidentified.

See #7388.

File:
1 edited

Legend:

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

    r12627 r13081  
    244244    $ticket = false;
    245245
    246     // If the trac found is the key, return the value.
    247     $trac_redirects = [
    248         // Themes trac mentions are likely Meta tickets.
    249         'themes' => 'meta',
    250     ];
    251 
    252246    // For now, we assume everything is destined for the Core Trac.
    253247    $trac = 'core';
     
    271265            }
    272266
    273             // If a specific trac is mentioned within the PR body:
    274             elseif ( preg_match( '!/(?P<trac>[a-z]+).trac.wordpress.org/!i', $pr->body, $m ) ) {
    275                 $trac = $m['trac'];
     267            // If a specific trac is mentioned within the PR body (and only that trac)
     268            elseif (
     269                preg_match_all( '!/(?P<trac>[a-z]+).trac.wordpress.org/!i', $body, $m ) &&
     270                1 === count( array_unique( $m[0] ) )
     271            ) {
     272                $trac = $m['trac'][0];
    276273            }
    277274
     
    284281
    285282    $regexes = [
     283        // Match explicit ticket-ref links, as included in most PR descriptions.
     284        "!Trac ticket:\s*https://(?P<trac>[a-z]+).trac.wordpress.org/ticket/(?P<id>\d+)!i",
     285
     286        // Match any references to the "expected" trac instance first. This covers cases where multiple tracs are mentioned.
     287        "!{$trac}.trac.wordpress.org/ticket/(?P<id>\d+)!i",
     288
     289        // Then any trac instance.
    286290        '!(?P<trac>[a-z]+).trac.wordpress.org/ticket/(?P<id>\d+)!i',
     291
     292        // Now for just plain ticket references without a trac instance.
    287293        '!(?:^|\s)#WP(\d+)!', // #WP1234
    288294        '!(?:^|\s)#(\d{4,5})!', // #1234
    289295        '!Ticket[ /-](\d+)!i',
     296
    290297        // diff filenames.
    291298        '!\b(\d+)(\.\d)?\.(?:diff|patch)!i',
    292         // Formats of common branches
     299
     300        // Formats of common branches.
    293301        '!((?P<trac>core|meta|bbpress|buddypress|themes)|WordPress|fix|trac)[-/](?P<id>\d+)!i',
     302
    294303        // Starts or ends with a ticketish number
    295304        // These match things it really shouldn't, and are a last-ditch effort.
     
    313322                    $trac = $m['trac'];
    314323                }
    315 
    316                 $trac = $trac_redirects[ $trac ] ?? $trac;
    317324
    318325                return [ $trac, $id ];
Note: See TracChangeset for help on using the changeset viewer.