JJ / github-pr-contains-action

Action that checks whether the body or diff in a PR contains a certain word.
MIT License
35 stars 33 forks source link

Error: ❌ TypeError: Cannot read properties of undefined (reading 'body') #87

Closed reetika-roy closed 1 year ago

reetika-roy commented 1 year ago

I have a workflow that runs for a private repository- I am using releases/v9 for it. I see the following error

Error: ❌ TypeError: Cannot read properties of undefined (reading 'body')
    at /home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/lib/main.js:53:1
    at Generator.next (<anonymous>)
    at /home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/lib/main.js:31:1
    at new Promise (<anonymous>)
    at __webpack_modules__.3109.__awaiter (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/lib/main.js:2[7](https://github.com/truera/truera/actions/runs/4108195996/jobs/7088652242#step:2:8):1)
    at run (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v[9](https://github.com/truera/truera/actions/runs/4108195996/jobs/7088652242#step:2:10)/webpack:/github-pr-contains-action/lib/main.js:43:1)
    at Object.3[10](https://github.com/truera/truera/actions/runs/4108195996/jobs/7088652242#step:2:11)9 (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/lib/main.js:[12](https://github.com/truera/truera/actions/runs/4108195996/jobs/7088652242#step:2:13)9:1)
    at __nccwpck_require__ (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/webpack/bootstrap:21:1)
    at /home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/webpack/startup:4:1
    at Object.<anonymous> (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/dist/index.js:[16](https://github.com/truera/truera/actions/runs/4108195996/jobs/7088652242#step:2:17)170:12)

I was working with master earlier and that did not have this issue.

JJ commented 1 year ago

That would happen with an empty body. It can't read anything from it if it's empty. Maybe it should issue a better message?

reetika-roy commented 1 year ago

I am seeing a better error today.

The body of the PR is empty, can't check
JJ commented 1 year ago

Was that the same version?

reetika-roy commented 1 year ago

Yup the same version.

JJ commented 1 year ago

If possible, please give me in the future the whole log; that way, I can try and find where it failed. Anyway, I'm happy it's working for you now. Thanks for the report!

reetika-roy commented 1 year ago

Re-opening this because I am definitely seeing this even when the body is not empty

Checking body contents
Error: ❌ TypeError: Cannot read properties of undefined (reading 'body')
    at /home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/lib/main.js:53:1
    at Generator.next (<anonymous>)
    at /home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/lib/main.js:31:1
    at new Promise (<anonymous>)
    at __webpack_modules__.3109.__awaiter (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/lib/main.js:2[7](https://github.com/truera/truera/actions/runs/4166493054/jobs/7211277068#step:2:8):1)
    at run (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v[9](https://github.com/truera/truera/actions/runs/4166493054/jobs/7211277068#step:2:10)/webpack:/github-pr-contains-action/lib/main.js:43:1)
    at Object.3[10](https://github.com/truera/truera/actions/runs/4166493054/jobs/7211277068#step:2:11)9 (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/lib/main.js:[12](https://github.com/truera/truera/actions/runs/4166493054/jobs/7211277068#step:2:13)9:1)
    at __nccwpck_require__ (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/webpack/bootstrap:21:1)
    at /home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/webpack:/github-pr-contains-action/webpack/startup:4:1
    at Object.<anonymous> (/home/runner/work/_actions/JJ/github-pr-contains-action/releases/v9/dist/index.js:[16](https://github.com/truera/truera/actions/runs/4166493054/jobs/7211277068#step:2:17)[17](https://github.com/truera/truera/actions/runs/4166493054/jobs/7211277068#step:2:18)0:12)

What other logs can I help with?

JJ commented 1 year ago

This will make do for the time being, thanks... Still a private repository, right?

reetika-roy commented 1 year ago

Yes. It was definitely working some time too. Seems flaky.

JJ commented 1 year ago

I have pushed a new version to master, which I think has a finer distinction between different types of "empty". Can you please check and report back?

reetika-roy commented 1 year ago

I will check with this- but in the cases I saw the error, the PR did have a description. So I do not follow how this might help.

JJ commented 1 year ago

I will check with this- but in the cases I saw the error, the PR did have a description. So I do not follow how this might help.

To be honest, I'm not sure either. But the error says clearly there's no "body", so that's what I'm working with...

majora2007 commented 1 year ago

I'm having this exact same issue: https://github.com/Kareadita/Kavita/pull/1886

Body is indeed there, token works as it's used in my pipeline elsewhere.

jobs:
  check_pr:
    runs-on: ubuntu-latest
    steps:
        - name: Check PR Body
          uses: JJ/github-pr-contains-action@releases/v7
          with:
              github-token: ${{ secrets.GITHUB_TOKEN }}
              bodyDoesNotContain: "[\"|`]"
JJ commented 1 year ago

OK, will check. Thanks for your report.

JJ commented 1 year ago

@majora2007 I see you have already upgraded to version 9 here will take a look.

JJ commented 1 year ago

OK, I think I know what's the problem. The problem is that PRs have two different kind of events. The initial pull_request event includes a body and a diff; however, subsequent push events in the same PR do not have a pull_request payload. That's going to need some refactoring, I'm afraid, so it will take some time. I'll try to get around to it next week. Does that seem to be the problem here, would you say?

majora2007 commented 1 year ago

That makes a lot of sense. No rush, I appreciate you taking the time to enhance your software.

reetika-roy commented 1 year ago

I think your assessment is right- I have not seen the issue since I removed push events from my trigger condition.

JJ commented 1 year ago

Just released version 10 should fix, or rather work around, the problem. Can you please check? I'll reopen if it does not.

majora2007 commented 1 year ago

I have indeed check, and it works! Thanks again JJ.