Making WordPress.org

Changeset 9539


Ignore:
Timestamp:
02/26/2020 06:13:24 AM (5 years ago)
Author:
dd32
Message:

Trac: Github PRs: Filter out HTML comments and standard code-review-only boilerplate from PR descriptions before posting them to Trac.

Props isabel_brison for the suggestion.
Fixes #5057.

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

    r9534 r9539  
    153153    return new Trac( GH_PRBOT_USER, GH_PRBOT_PASS, $trac_uri );
    154154}
     155
     156/**
     157 * Formats a PR description for usage on Trac.
     158 *
     159 * This strips out HTML comments and standard boilerplate text.
     160 *
     161 * @param object $pr_data PR Data.
     162 * @return string Stripped down PR Description
     163 */
     164function format_pr_desc_for_trac_comment( $pr_data ) {
     165    $desc = trim( $pr_data->body );
     166
     167    // Remove HTML comments
     168    $desc = preg_replace( '#<!--.+?-->#', '', $desc );
     169
     170    // Remove the final line if it matches the specific boilerplate format.
     171    $desc = preg_replace( "#---\r?\n\*\*.+\*\*$#", '', $desc );
     172
     173    return trim( $desc );
     174}
  • sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/webhook.php

    r9532 r9539  
    8080            $trac = get_trac_instance( $pr_data->trac_ticket[0] );
    8181
     82            $pr_description = format_pr_desc_for_trac_comment( $pr_data );
     83
    8284            $trac->update(
    8385                $pr_data->trac_ticket[1],
     
    8587                    "on [https://github.com/{$pr_repo}/ {$pr_repo}] " .
    8688                    "by [{$pr_data->user->url} {$pr_data->user->name}].''" .
    87                     ( trim( $pr_data->body ) ? "\n{$pr_data->body}" : '' ),
     89                    ( $pr_description ? "\n{$pr_description}" : '' ),
    8890                [],  // Attributes changed
    8991                true // Notify
Note: See TracChangeset for help on using the changeset viewer.