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

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

Closed
jason-curtis opened this issue Mar 15, 2024 · 2 comments
Closed

Comments

@jason-curtis
Copy link

jason-curtis commented Mar 15, 2024

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
Copy link
Owner

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.

  • Check the COMMENTING_ACCESS_TOKEN secret actually contains the full PAT and hasn't been accidentally truncated. Copy/paste it again.
  • Check that the PAT is created on a user that has read and write access to the target repository.
  • Check that the PAT has the correct scopes. repo for classic tokens.

@jason-curtis
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants