From c2739ba5653177c72dd02220dd24c4ec58e50cc9 Mon Sep 17 00:00:00 2001 From: Muhibul Haque Date: Thu, 22 Oct 2026 18:21:23 +0600 Subject: [PATCH] Build/Test Tools: Restore first-time contributor welcome message using actions/github-script Reimplements the first-time contributor welcome comment job in `.github/workflows/pull-request-comments.yml` using `actions/github-script`. Bypasses the upstream bug in `actions/first-interaction` (actions/first-interaction#365) where disabled issues caused welcome messages to be posted on all PRs. Accurately greets first-time authors and adds the celebratory reaction without external dependencies. See #65432. --- .github/workflows/pull-request-comments.yml | 90 +++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index 6c56326774b8d..fb5774d9db23a 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -20,6 +20,96 @@ concurrency: permissions: {} jobs: + # Comments on a pull request when the author is a first time contributor. + post-welcome-message: + name: Post a welcome comment for first-time contributors + runs-on: ubuntu-24.04 + permissions: + issues: write + pull-requests: write + timeout-minutes: 5 + if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' && github.event.action == 'opened' }} + steps: + - name: Post welcome comment + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + with: + script: | + const { owner, repo } = context.repo; + const pr = context.payload.pull_request; + const author = pr.user.login; + + // Only comment for first-time contributors. + const authorAssociation = pr.author_association; + const isFirstTimer = authorAssociation === 'FIRST_TIME_CONTRIBUTOR' || authorAssociation === 'FIRST_TIMER'; + + if ( ! isFirstTimer ) { + core.info( `Author @${ author } has author association "${ authorAssociation }". Skipping welcome comment.` ); + return; + } + + // Check if the author has opened other pull requests in the repository. + const prs = await github.rest.pulls.list( { + owner, + repo, + creator: author, + state: 'all', + per_page: 2, + } ); + + if ( prs.data.length > 1 ) { + core.info( `Author @${ author } has already opened other pull requests. Skipping welcome comment.` ); + return; + } + + // Check if a welcome comment already exists to avoid duplicate comments. + const comments = ( await github.rest.issues.listComments( { + owner, + repo, + issue_number: pr.number, + } ) ).data; + + const hasWelcomeComment = comments.some( ( comment ) => + comment.user.type === 'Bot' && comment.body.includes( 'first pull request to `wordpress-develop`' ) + ); + + if ( hasWelcomeComment ) { + core.info( 'A welcome comment already exists on this pull request.' ); + return; + } + + const welcomeLines = [ + `Hi @${ author }! 👋`, + 'Thank you for your contribution to WordPress! 💖', + 'It looks like this is your first pull request to `wordpress-develop`. Here are a few things to be aware of that may help you out!', + '**No one monitors this repository for new pull requests.** Pull requests **must** be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket\'s full URL in your pull request description.', + '**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 [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.', + 'If you have not had a chance, please review the [Contribute with Code page](https://make.wordpress.org/core/handbook/contribute/) in the [WordPress Core Handbook](https://make.wordpress.org/core/handbook/).', + 'The [Developer Hub](https://developer.wordpress.org/) also documents the various [coding standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/) that are followed:\n- [PHP Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/)\n- [CSS Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/)\n- [HTML Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/html/)\n- [JavaScript Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/)\n- [Accessibility Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/accessibility/)\n- [Inline Documentation Standards](https://developer.wordpress.org/coding-standards/inline-documentation-standards/)', + 'Thank you,\nThe WordPress Project', + ]; + + await github.rest.issues.createComment( { + owner, + repo, + issue_number: pr.number, + body: welcomeLines.join( '\n\n' ), + } ); + + try { + await github.rest.reactions.createForIssue( { + owner, + repo, + issue_number: pr.number, + content: 'hooray', + } ); + } catch ( error ) { + core.info( `Could not add reaction: ${ error.message }` ); + } + + core.notice( `Created welcome comment for pull request: ${ pr.html_url }` ); + # Leaves a comment on a pull request with a link to test the changes in a WordPress Playground instance. playground-details: name: Comment on a pull request with Playground details