Making WordPress.org

Changeset 10072


Ignore:
Timestamp:
07/16/2020 01:38:46 AM (4 years ago)
Author:
dd32
Message:

Trac: PRs: Transform Github comments to Trac syntax in addition to the PR description.
This also converts links and images to Trac syntax.

Fixes #5308.

Location:
sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr
Files:
2 edited

Legend:

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

    r10031 r10072  
    289289
    290290/**
    291  * Formats a PR description for usage on Trac.
     291 * Formats a PR description/comment for usage on Trac.
     292 *
     293 * This:
     294 *  - Strips standard boilerplate text
     295 *  - format_github_content_for_trac_comment();
     296 *
     297 * @param string $desc.
     298 * @return string Converted PR Description
     299 */
     300function format_pr_desc_for_trac_comment( $desc ) {
     301    $desc = trim( $desc );
     302
     303    // Remove the final line if it matches the specific boilerplate format.
     304    $desc = preg_replace( "#---\r?\n\*\*.+\*\*$#", '', $desc );
     305
     306    return format_github_content_for_trac_comment( $desc );
     307}
     308
     309/**
     310 * Formats github content for usage on Trac.
    292311 *
    293312 * This:
    294313 *  - Strips HTML comments
    295  *  - Strips standard boilerplate text
    296314 *  - Converts code blocks
    297  *
    298  * @param object $pr_data PR Data.
     315 *  - Converts image embeds
     316 *  - Converts links
     317 *
     318 * @param string $desc.
    299319 * @return string Converted PR Description
    300320 */
    301 function format_pr_desc_for_trac_comment( $pr_data ) {
    302     $desc = trim( $pr_data->body );
    303 
     321function format_github_content_for_trac_comment( $desc ) {
    304322    // Remove HTML comments
    305323    $desc = preg_replace( '#<!--.+?-->#s', '', $desc );
     
    308326    $desc = preg_replace( '#```(.+?)```#s', '{{{$1}}}', $desc );
    309327
    310     // Remove the final line if it matches the specific boilerplate format.
    311     $desc = preg_replace( "#---\r?\n\*\*.+\*\*$#", '', $desc );
     328    // Convert Images (Must happen prior to Links, as the only difference is a preceeding !)
     329    $desc = preg_replace( '#!\[(.+?)\]\((.+?)\)#', '[[Image($2)]]', $desc );
     330
     331    // Convert Links.
     332    $desc = preg_replace( '#\[(.+?)\]\((.+?)\)#', '[$2 $1]', $desc );
    312333
    313334    return trim( $desc );
  • sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/webhook.php

    r9900 r10072  
    8282            $trac = get_trac_instance( $pr_data->trac_ticket[0] );
    8383
    84             $pr_description = format_pr_desc_for_trac_comment( $pr_data );
     84            $pr_description = format_pr_desc_for_trac_comment( $pr_data->body );
    8585            $attributes     = [];
    8686
     
    181181            $payload->comment->html_url,
    182182            'PR #' . $payload->issue->number,
    183             $payload->comment->body
     183            format_github_content_for_trac_comment( $payload->comment->body )
    184184        );
    185185
Note: See TracChangeset for help on using the changeset viewer.