From 4539b46cbb5c1d3d0b42198d13ccc6a056e35056 Mon Sep 17 00:00:00 2001 From: Igor Rozum Date: Tue, 18 Aug 2026 19:09:14 -0400 Subject: [PATCH] Build/Test Tools: Match raw PR body when closing PRs for fixed Trac tickets --- .../workflows/reusable-cleanup-pull-requests.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/reusable-cleanup-pull-requests.yml b/.github/workflows/reusable-cleanup-pull-requests.yml index 012f99adbec3b..8a382bb8744a7 100644 --- a/.github/workflows/reusable-cleanup-pull-requests.yml +++ b/.github/workflows/reusable-cleanup-pull-requests.yml @@ -66,23 +66,31 @@ jobs: nodes { ... on PullRequest { number - bodyText + body } } } } `; - const searchQuery = `repo:${context.repo.owner}/${context.repo.repo} is:pr is:open ( "${tracTicketUrl}" OR "${corePrefix}" )`; + // The PR template only asks for "a link to the WordPress Trac ticket", so some + // PRs reference it as a Markdown link with just the ticket number as the link + // text (e.g. "Trac ticket: [65864](https://core.trac.wordpress.org/ticket/65864)"). + // GitHub's search index doesn't cover Markdown link targets, only the rendered + // text, so the bare ticket number is searched for too to surface those PRs. + const searchQuery = `repo:${context.repo.owner}/${context.repo.repo} is:pr is:open ( "${tracTicketUrl}" OR "${corePrefix}" OR "${ticket}" )`; const result = await github.graphql(query, { searchQuery, }); - // Since search queries will match anywhere for any activity on a pull request, the body specifically needs to be manually checked. + // Since search queries will match anywhere for any activity on a pull request, the body + // specifically needs to be manually checked. The raw `body` (rather than `bodyText`) is used + // here because `bodyText` strips Markdown links down to just their visible text, which would + // drop the Trac ticket URL entirely for PRs that link the ticket via its number. const matchingPRs = result.search.nodes .filter(pr => { - const bodyLower = pr.bodyText.toLowerCase(); + const bodyLower = pr.body.toLowerCase(); return bodyLower.includes(tracTicketUrl.toLowerCase()) || bodyLower.includes(corePrefix.toLowerCase()); }).map(pr => pr.number);