Skip to content

Commit 8175698

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@58092 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1911cba commit 8175698

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

.github/workflows/pull-request-comments.yml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
**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.
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
5555
**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.
@@ -163,3 +163,50 @@ jobs:
163163
`;
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+
}

0 commit comments

Comments
 (0)