Making WordPress.org


Ignore:
Timestamp:
02/26/2020 06:13:24 AM (4 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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.