How to comment on PR with "if","then" in GitHub Actions?

I am trying this:

name: CRAZY

on:
  push:
    
  pull_request:
    
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: checkout
      uses: actions/checkout@v2
      
    - name: check value and set label milestone
      run: |
           STR="name: Octocat"
           if [ `grep -c "$STR" crazy` -ne '0' ];
           then
             echo "Found"
             github.issues.createComment({body: '👋 Thanks for reporting!'})
             curl --request PATCH \
             --url ${{ github.event.pull_request.issue_url }} \
             --header 'authorization: token ${{ secrets.GITHUB_TOKEN }}' \
             --data '{"milestone": 1, "labels": [ "bug" ]}'
           else
             echo "NotFound"
             exit 1
           fi

what is wrong with the comment part? why isn’t it working?

is not something Bash can understand. To me it looks like it might be meant as a Javascript function call?

Hi @ojedavidea,

For jobs.<job_id>.steps.run , it will run command-line programs using the operating system’s shell, however your comment script is javascript which cannot be understand.

You can use rest api here to add the pull request comment. Code sample as below:

          curl --request POST \
            --url ${{ github.event.pull_request.issue_url }}/comments \
            --header 'authorization: token ${{ secrets.GITHUB_TOKEN }}' \
            --data '{"body": "test comment"}'     # add your comment content for the body.

Please kindly let me know if it works for you.
Thanks.

Hi @ojedavidea,

Based on your another ticket here, looks it’s resolved to add comment to pull request via the curl command, could you please kinldy help to confirm?

It’s recommended to mark the answer if the question is resolved, it will be helpful to other who have same queries.

Thanks a lot!