diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index 799f2d04c107c..6611309bd3047 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -130,6 +130,20 @@ jobs: const fs = require( 'fs' ); const issue_number = Number( fs.readFileSync( './NR' ) ); + core.info( `Checking pull request #${issue_number}.` ); + + // Confirm that the pull request is still open before leaving a comment. + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: issue_number, + }); + + if ( pr.data.state !== 'open' ) { + core.info( 'The pull request has been closed. No comment will be left.' ); + return; + } + // Comments are only added after the first successful build. Check for the presence of a comment and bail early. const commentInfo = { owner: context.repo.owner, @@ -141,6 +155,7 @@ jobs: for ( const currentComment of comments ) { if ( currentComment.user.type === 'Bot' && currentComment.body.includes( 'Test using WordPress Playground' ) ) { + core.info( 'A comment with instructions to test within a Playground instance already exists.' ); return; } };