Skip to content

Commit

Permalink
Build/Test Tools: Remind contributors to include a Trac ticket link.
Browse files Browse the repository at this point in the history
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.

git-svn-id: https://develop.svn.wordpress.org/trunk@58092 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
desrosj authored and spacedmonkey committed May 4, 2024
1 parent 1fa55b3 commit ef229d9
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion .github/workflows/pull-request-comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
**Pull requests are never merged on GitHub.** The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.
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/).
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/).
**Please include automated tests.** Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the [Automated Testing](https://make.wordpress.org/core/handbook/testing/automated-testing/) page in the handbook.
Expand Down Expand Up @@ -163,3 +163,50 @@ jobs:
`;
github.rest.issues.createComment( commentInfo );
# Leaves a comment on a pull request when no Trac ticket is included in the pull request description.
trac-ticket-check:
name: Comment on a pull request when no Trac ticket is included
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' && ! github.event.pull_request.draft && github.event.pull_request.state == 'open' }}
steps:
- name: Check for Trac ticket and comment if missing
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { owner, repo } = context.repo;
const { number } = context.issue;
// Check for the presence of a comment and bail early.
const comments = ( await github.rest.issues.listComments( { owner, repo, issue_number: number } ) ).data;
const hasMissingTicketComment = comments.some( comment =>
comment.user.type === 'Bot' && comment.body.includes( 'Trac Ticket Missing' )
);
if ( hasMissingTicketComment ) return;
// No comment was found. Create one.
const pr = ( await github.rest.pulls.get( { owner, repo, pull_number: number } ) ).data;
const prBody = pr.body ?? '';
const prTitle = pr.title ?? '';
const tracTicketRegex = new RegExp( 'https?://core.trac.wordpress.org/ticket/([0-9]+)', 'g' );
const tracTicketMatches = prBody.match( tracTicketRegex ) || prTitle.match( tracTicketRegex );
if ( ! tracTicketMatches ) {
github.rest.issues.createComment( {
owner,
repo,
issue_number: number,
body: `## Trac Ticket Missing
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.
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/).
`,
} );
}

0 comments on commit ef229d9

Please sign in to comment.