wagoid/commitlint-github-action

error running commitlint: undefined is not iterable

shanduur opened this issue · 1 comments

Encountered the following issue today:

error trying to get list of pull request's commits
Resource not accessible by integration
HttpError: Resource not accessible by integration
    at /node_modules/@octokit/request/dist-node/index.js:86:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async getRangeForEvent (/run.js:234:7)
Error: You have commit messages with errors

error running commitlint
undefined is not iterable (cannot read property Symbol(Symbol.iterator))
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at showLintResults (/run.js:300:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

I was able to get rid of this error by adding permissions to the workflow yaml. The wagoid/commitlint-github-action uses octokit.rest.pulls.listCommits() to fetch the commits for a pull request. As described in the GitHub Developer Guide documentation, this operation needs the permission to access the API endpoint GET /repos/{owner}/{repo}/pulls/{pull_number}/commits. As you can read at Permissions required for GitHub Apps this endpoint requires the PullRequests: read permission as well as the repository permission for Contents. So, adding the following to the workflow yaml file solves this issue:

permissions:
  contents: read
  pull-requests: read