peter-evans / create-or-update-comment

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

Unable to Create the comment #212

Closed BasantPandey closed 1 year ago

BasantPandey commented 1 year ago

Hello Team,

I am trying to create a comment. But not sure what goes wrong here. here is my example Pipeline. link


on: 
  issues:
    types: [opened]

env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  COMMENTS_URL: ${{ github.event.issue.comments_url }}
  ISSUE_NUMBER: ${{ github.event.issue.number }}
  OWNER: ${{ github.event.issue.user.login }}
  REPO: ${{ github.event.repository.name }}

jobs:
   Comment-with-action:
    runs-on: ubuntu-latest

    steps:
      - name: "Dump github context"
        run: | 
          echo '${{ toJSON(github.event) }}' | jq
        shell: bash

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v3
        with:
          issue-number: ${{ github.event.issue.number }}
          body: |
            This is a multi-line test comment
            - With GitHub **Markdown** :sparkles:
            - Created by [create-or-update-comment][1]

            [1]: https://github.com/peter-evans/create-or-update-comment
          reactions: '+1'`

Here is the error message.


/home/runner/work/_actions/peter-evans/create-or-update-comment/v3/dist/index.js:4694
      const error = new requestError.RequestError(toErrorMessage(data), status, {
                    ^

RequestError [HttpError]: Resource not accessible by integration
    at /home/runner/work/_actions/peter-evans/create-or-update-comment/v3/dist/index.js:4694:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  status: 403,
  response: {
    url: 'https://api.github.com/repos/BasantPandey/LearnTerraform/issues/18/comments',
    status: 403,
    headers: {
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
      connection: 'close',
      'content-encoding': 'gzip',
      'content-security-policy': "default-src 'none'",
      'content-type': 'application/json; charset=utf-8',
      date: 'Mon, 12 Jun 20[23](https://github.com/BasantPandey/LearnTerraform/actions/runs/5241207088/jobs/9462995414#step:3:24) 08:19:31 GMT',
      'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
      server: 'GitHub.com',
      'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
      'transfer-encoding': 'chunked',
      vary: 'Accept-Encoding, Accept, X-Requested-With',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'deny',
      'x-github-api-version-selected': '2022-11-28',
      'x-github-media-type': 'github.v3; format=json',
      'x-github-request-id': '8C81:6ABE:7409477:ED4CFA6:6486D513',
      'x-ratelimit-limit': '1000',
      'x-ratelimit-remaining': '994',
      'x-ratelimit-reset': '1686558100',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '6',
      'x-xss-protection': '0'
    },
    data: {
      message: 'Resource not accessible by integration',
      documentation_url: 'https://docs.github.com/rest/reference/issues#create-an-issue-comment'
    }
  },
  request: {
    method: 'POST',
    url: 'https://api.github.com/repos/BasantPandey/LearnTerraform/issues/18/comments',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-core.js/3.6.0 Node.js/16.16.0 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"body":"This is a multi-line test comment\\n- With GitHub **Markdown** :sparkles:\\n- Created by [create-or-update-comment][1]\\n\\n[1]: https://github.com/peter-evans/create-or-update-comment"}',
    request: {
      agent: Agent {
        _events: [Object: null prototype] {
          free: [Function (anonymous)],
          newListener: [Function: maybeEnableKeylog]
        },
        _eventsCount: 2,
        _maxListeners: undefined,
        defaultPort: 443,
        protocol: 'https:',
        options: [Object: null prototype] { path: null },
        requests: [Object: null prototype] {},
        sockets: [Object: null prototype] {},
        freeSockets: [Object: null prototype] {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: [25](https://github.com/BasantPandey/LearnTerraform/actions/runs/5241207088/jobs/9462995414#step:3:26)6,
        scheduling: 'lifo',
        maxTotalSockets: Infinity,
        totalSocketCount: 0,
        maxCachedSessions: 100,
        _sessionCache: {
          map: {
            'api.github.com:4[43](https://github.com/BasantPandey/LearnTerraform/actions/runs/5241207088/jobs/9462995414#step:3:44):::::::::::::::::::::': [Buffer [Uint8Array]]
          },
          list: [ 'api.github.com:[44](https://github.com/BasantPandey/LearnTerraform/actions/runs/5241207088/jobs/9462995414#step:3:45)3:::::::::::::::::::::' ]
        },
        [Symbol(kCapture)]: false
      },
      hook: [Function: bound bound register]
    }
  }
}```
BasantPandey commented 1 year ago

This issue is related to the token, marked as close as I am able to fix it.

bblommers commented 1 year ago

Hi @BasantPandey, can you share what the fix was? DId you have to specify the permissions-field?

BasantPandey commented 1 year ago

I have created PAT token with full permission for the time being to fixed it.

The example provided in docs not working as expected. I think this secrets.GITHUB_TOKEN doesn't has permission to add comment on the issue. Will share you more details tomorrow.

abiralkhadka88 commented 1 year ago

I have created PAT token with full permission for the time being to fixed it.

The example provided in docs not working as expected. I think this secrets.GITHUB_TOKEN doesn't has permission to add comment on the issue. Will share you more details tomorrow.

Where can i find the details

hyrodium commented 9 months ago

The example provided in docs not working as expected. I think this secrets.GITHUB_TOKEN doesn't has permission to add comment on the issue.

We need to configure permissions like this:

    permissions:
      pull-requests: write

See GitHub official documentation about permissions for more information.

mialdi98 commented 8 months ago

We need to configure permissions like this:

    permissions:
      pull-requests: write

Adding issues: write with already existing pull-requests: write solved my issue (but I was using it only for pull-requests)