Trigger a github workflow if it matches a particular comment in the Pull Request

I want to trigger a workflow if it matches a particular comment (string) in a pull request.
So let suppose if I comment on a pull request /support then the GitHub action should get a trigger.
Comment Like:

If the action receives /support comment if should trigger the workflow which is running some command say echo “Hello World”
and if I comment /test then it should run some different commands like … echo “test”

Hi @uditgaurav,

There is not a specific event which only monitor the pull request event, you can use ‘issue_comment’ instead, it will monitor comment for both issue and pull request. In the job level, use if expression to filter the comment, exclude the comments from issue.
Code sample as below:

name: pull request comment
on:
  issue_comment:                                     
    types: [created, edited, deleted]

jobs:
 job01:
   if: contains(github.event.comment.html_url, '/pull/')    # check if the comments come from pull request, exclude those from issue.
   runs-on: [ubuntu-latest]
   steps:
     - name: say hello
       if: contains(github.event.comment.body, '/support')   # check the comment if it contains the keywords
       run: |
         echo say hello
     - name: test
       if: contains(github.event.comment.body, '/test')  # check the comment if it contains the keywords
       run: |
         echo test

I tried on my repo, and it works fine.

Thanks

Note: please use issue_comment in default branch,eg: master branch.

1 Like