Make WordPress Core

Changeset 58092


Ignore:
Timestamp:
05/03/2024 12:37:05 PM (4 months ago)
Author:
desrosj
Message:

Build/Test Tools: Remind contributors to include a Trac ticket link.

Contributing to WordPress using wordpress-develop on GitHub is a useful way collaborate, test, and review suggested changes to the code base. One of the required criteria, though, is including a link to a corresponding Trac ticket. This ensures the PR and associated activity is listed on the Trac ticket, which serves as the source of truth.

It’s easy to forget this and newer contributors aren’t always aware of this requirement. This adds a GitHub Actions job that will add a comment as a reminder when no Trac ticket is included.

Is the waiting really ended? Two thousand years.

Props anamarijapapic, peterwilsoncc.
Fixes #60129.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/pull-request-comments.yml

    r57210 r58092  
    5050
    5151
    52             More information about how GitHub pull requests can be used to contribute to WordPress can be found in [this blog post](https://make.wordpress.org/core/2020/02/21/working-on-trac-tickets-using-github-pull-requests/).
     52            More information about how GitHub pull requests can be used to contribute to WordPress can be found in [the Core Handbook](https://make.wordpress.org/core/handbook/contribute/git/github-pull-requests-for-code-review/).
    5353
    5454
     
    164164
    165165            github.rest.issues.createComment( commentInfo );
     166
     167  # Leaves a comment on a pull request when no Trac ticket is included in the pull request description.
     168  trac-ticket-check:
     169    name: Comment on a pull request when no Trac ticket is included
     170    runs-on: ubuntu-latest
     171    permissions:
     172      issues: write
     173      pull-requests: write
     174    if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' && ! github.event.pull_request.draft && github.event.pull_request.state == 'open' }}
     175    steps:
     176      - name: Check for Trac ticket and comment if missing
     177        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
     178        with:
     179          script: |
     180            const { owner, repo } = context.repo;
     181            const { number } = context.issue;
     182
     183            // Check for the presence of a comment and bail early.
     184            const comments = ( await github.rest.issues.listComments( { owner, repo, issue_number: number } ) ).data;
     185
     186            const hasMissingTicketComment = comments.some( comment =>
     187              comment.user.type === 'Bot' && comment.body.includes( 'Trac Ticket Missing' )
     188            );
     189
     190            if ( hasMissingTicketComment ) return;
     191
     192            // No comment was found. Create one.
     193            const pr = ( await github.rest.pulls.get( { owner, repo, pull_number: number } ) ).data;
     194
     195            const prBody = pr.body ?? '';
     196            const prTitle = pr.title ?? '';
     197
     198            const tracTicketRegex = new RegExp( 'https?://core.trac.wordpress.org/ticket/([0-9]+)', 'g' );
     199            const tracTicketMatches = prBody.match( tracTicketRegex ) || prTitle.match( tracTicketRegex );
     200
     201            if ( ! tracTicketMatches ) {
     202              github.rest.issues.createComment( {
     203                owner,
     204                repo,
     205                issue_number: number,
     206                body: `## Trac Ticket Missing
     207            This pull request is missing a link to a [Trac ticket](https://core.trac.wordpress.org/). For a contribution to be considered, there must be a corresponding ticket in Trac.
     208
     209            To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in [the Core Handbook](https://make.wordpress.org/core/handbook/contribute/git/github-pull-requests-for-code-review/).
     210            `,
     211              } );
     212            }
Note: See TracChangeset for help on using the changeset viewer.