peter-evans / create-or-update-comment

A GitHub action to create or update an issue or pull request comment
MIT License
707 stars 113 forks source link

find-comment@v3 fails with "not found" when running on a pull request #324

Closed jason-curtis closed 8 months ago

jason-curtis commented 8 months ago

I'm using an example from the README, but on initial PR creation, the step that uses peter-evans/find-comment@v3 is failing with the error message Error: Not Found.

Example in the README: image

Here is my exact YAML

      - name: Find Deploy Comment
        uses: peter-evans/find-comment@v3
        if: github.event_name == 'pull_request'
        id: find-deploy-comment
        with:
          token: ${{ secrets.COMMENTING_ACCESS_TOKEN }}
          issue-number: ${{ github.event.pull_request.number }}
          comment-author: 'github-actions[bot]'
          body-includes: Deploy
      - name: Create or Update Deploy Comment
        uses: peter-evans/create-or-update-comment@v4
        if: github.event_name == 'pull_request'
        with:
          token: ${{ secrets.COMMENTING_ACCESS_TOKEN }}
          comment-id: ${{ steps.find-deploy-comment.outputs.comment-id }}
          issue-number: ${{ github.event.pull_request.number }}
          body: |
            Deployed to: ${{ steps.deploy.outputs.url }}
          edit-mode: replace

Full log output: https://gist.github.com/jason-curtis/ab29324877cccd8da957e7ab439cdcd1

It appears that even though I'm running on a pull request with a pull request ID, the action is attempting to find a GitHub issue with that number, and it is failing when it receives a 404 response from GitHub.

This project is not using GitHub issues at all, so when the action tries to access https://api.github.com/repos/carbon-yield/farm-data/issues/9/comments, a 404 error is expected!

peter-evans commented 8 months ago

Hi @jason-curtis

In the backend of GitHub, pull requests are extended issues. They use the same API. So the action is correct to try and find an issue with that number.

If you are consistently getting a 404 from the API then that would probably indicate that the token you are using doesn't have the correct permissions to access the repository contents.

jason-curtis commented 8 months ago

Ah, I see. Thank you for the response! I forgot that GH likes to return 404s instead of 401s, and I was confused because I had earlier had an explicit permissions error (something like this token does not have access to this resource).

In any case, I worked around it by using the GITHUB_TOKEN directly and setting up permissions within the action:

    permissions:
      contents: read
      pull-requests: write

I also ended up using @mshick/add-pr-comment since it was a bit more straightforward for my use case.