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

Unable to Create the comment #212

Closed
BasantPandey opened this issue Jun 12, 2023 · 6 comments
Closed

Unable to Create the comment #212

BasantPandey opened this issue Jun 12, 2023 · 6 comments

Comments

@BasantPandey
Copy link

BasantPandey commented Jun 12, 2023

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

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

@bblommers
Copy link

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

@BasantPandey
Copy link
Author

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

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

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

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)

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

5 participants