Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/pull-request-comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading