Skip to content

Commit

Permalink
Build/Test Tools: Clean up PR comments after action is taken.
Browse files Browse the repository at this point in the history
There’s now a number of automated comments left on pull requests to help contributors that a PR can easily be overridden with activity.

Some of the comments are only relevant until a specific action is taken. One such comment is for informing the PR author that a link to a Trac ticket is a requirement for considering any suggested changes.

This updates the pull request comment workflow to remove the comment once a link to a Trac ticket is properly included.

Props debarghyabanerjee.
Fixes #61567.

git-svn-id: https://develop.svn.wordpress.org/trunk@59169 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
desrosj committed Oct 4, 2024
1 parent 2c17f65 commit b59d154
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/pull-request-comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Pull Request Comments

on:
pull_request_target:
types: [ 'opened' ]
types: [ 'opened', 'synchronize', 'reopened', 'edited' ]
workflow_run:
workflows: [ 'Test Build Processes' ]
types:
Expand Down Expand Up @@ -164,16 +164,16 @@ jobs:
github.rest.issues.createComment( commentInfo );
# Leaves a comment on a pull request when no Trac ticket is included in the pull request description.
# Manages comments reminding contributors to include a Trac ticket link when opening a pull request.
trac-ticket-check:
name: Comment on a pull request when no Trac ticket is included
name: Manage Trac ticket reminders for pull requests
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
- name: Check for Trac ticket and manage comment
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
Expand All @@ -183,11 +183,13 @@ jobs:
// 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' )
);
const hasMissingTicketComment = comments.find( comment => comment.user.type === 'Bot' && comment.body.includes( 'Trac Ticket Missing' ) );
if ( hasMissingTicketComment ) return;
if ( hasMissingTicketComment ) {
// Trac ticket link found, delete existing "Trac Ticket Missing" comment.
await github.rest.issues.deleteComment( { owner, repo, comment_id: hasMissingTicketComment.id } );
return;
}
// No comment was found. Create one.
const pr = ( await github.rest.pulls.get( { owner, repo, pull_number: number } ) ).data;
Expand Down

0 comments on commit b59d154

Please sign in to comment.