Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment on a PR when no Trac ticket is included #46

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
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
43 changes: 43 additions & 0 deletions .github/workflows/pull-request-comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name: Pull Request Comments

on:
pull_request:
branches:
- trunk
pull_request_target:
types: [ 'opened' ]
workflow_run:
Expand Down Expand Up @@ -163,3 +166,43 @@ jobs:
`;

github.rest.issues.createComment( commentInfo );



no-trac-url-included:
name: Comment on a pull request when no Trac ticket is included
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Add the comment
uses: JJ/github-pr-contains-action@releases/v11
with:
github-token: ${{github.token}}
bodyDoesNotContain: "core\.trac\.wordpress\.org\/ticket\/\d+"
script: |
const fs = require( 'fs' );
const issue_number = Number( fs.readFileSync( './NR' ) );

// 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,
repo: context.repo.repo,
issue_number,
};

const comments = ( await github.rest.issues.listComments( commentInfo ) ).data;

for ( const currentComment of comments ) {
if ( currentComment.user.type === 'Bot' && currentComment.body.includes( 'Test Comment from ahmed' ) ) {
return;
}
};

// No comment was found. Create one.
commentInfo.body = `## Test Comment from ahmed
Hi Hi Hi
`;

github.rest.issues.createComment( commentInfo );
Loading