github-script icon indicating copy to clipboard operation
github-script copied to clipboard

REST API "CreateCommitStatus" returning a 404

Open aiell0 opened this issue 1 year ago • 1 comments

Describe the bug Get an error 404 not found when trying to create a commit status.

To Reproduce Steps to reproduce the behavior:

  1. Create a github action that runs each time a pull request has to synchronize.
  2. Place the following action inside of it:
    - name: Set final commit status
      uses: actions/github-script@v7
      if: always()
      env:
        GITHUB_TOKEN: ${{ github.token }}
      with:
        script: |
          github.rest.repos.createCommitStatus({
            owner: context.repo.owner,
            repo: context.repo.repo,
            sha: context.repo.sha,
            state: 'success',
            description: "Helm check succeeded!",
            context: 'continuous-integration/helm'
          })
  1. Open a PR.
  2. Commit to that PR to trigger this action.

Expected behavior API runs successfully and the check is created/updated.

Screenshots

RequestError [HttpError]: Not Found
    at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:9537:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 404,
  response: {
    url: 'https://api.github.com/repos/<redacted>/<redacted>/statuses/',
    status: 404,
    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',
      'content-encoding': 'gzip',
      'content-security-policy': "default-src 'none'",
      'content-type': 'application/json; charset=utf-8',
      date: 'Mon, 13 Nov 2023 [22](https://github.com/<redacted>/<redacted>/actions/runs/6856365777/job/18643404579#step:10:23):13:52 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': '2904:52C9:C9EBB1:1A149B8:65529FA0',
      'x-ratelimit-limit': '15000',
      'x-ratelimit-remaining': '14992',
      'x-ratelimit-reset': '1699917205',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '8',
      'x-xss-protection': '0'
    },
    data: {
      message: 'Not Found',
      documentation_url: 'https://docs.github.com/rest'
    }
  },
  request: {
    method: 'POST',
    url: 'https://api.github.com/repos/<redacted>/<redacted>/statuses/',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'actions/github-script octokit-core.js/5.0.1 Node.js/20.8.1 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"state":"success","description":"Helm check succeeded!","context":"continuous-integration/helm"}',
    request: {
      agent: [Agent],
      fetch: [Function: proxyFetch],
      hook: [Function: bound bound register]
    }
  }
}
Error: Unhandled error: HttpError: Not Found

Desktop (please complete the following information): N/A

Smartphone (please complete the following information): N/A

Additional context I am fairly sure it is because the sha is not at the end of the endpoint, like it is documented here. I went back to using the gh api command like in the docs and it is working now.

aiell0 avatar Nov 13 '23 22:11 aiell0

Had the same issue with creating a comment. The problem was that actions triggered by push event don't have pull request context (number to be specific). Had to switch to pull_request trigger.

gaikaz avatar Feb 02 '24 15:02 gaikaz

I set it up as below and it worked.

github.rest.repos.createCommitStatus({
  owner: context.repo.owner,
  repo: context.repo.repo,
  sha: context.payload.pull_request.head.sha
  state: 'success',
  target_url: context.payload.repository.commits_url,
})

chisatokashima-eizo avatar Feb 20 '24 05:02 chisatokashima-eizo

@gaikaz's suggestion worked so I will close this for now.

aiell0 avatar Apr 09 '24 00:04 aiell0