octokit / octokit.js

The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno.
MIT License
7.06k stars 1.04k forks source link

Workflow dispatch does not respect supplied ref #2286

Closed thburghout closed 2 years ago

thburghout commented 2 years ago

Please avoid duplicates

Reproducible test case

see below

Please select the environment(s) that are relevant to your bug report

Version

Octokit.VERSION "4.0.4"

What happened?

When invoking create workflow dispatch for a specific workflow on a specific branch, it yields a 404. The workflow is only present on the specific branch.

> await octokit.request("POST /repos/OWNER/REPO/actions/workflows/workflow.yml/dispatches", {ref: "refs/heads/some-branch-name", inputs: {}})
request { method: 'POST',
  baseUrl: 'https://api.github.com',
  headers: 
   { accept: 'application/vnd.github.v3+json',
     'user-agent': 'octokit.js/2.0.7 octokit-core.js/4.0.4 Deno/1.24.3' },
  mediaType: { format: '', previews: [] },
  request: { hook: [Function: bound bound register], retryCount: 1 },
  url: '/repos/OWNER/REPO/actions/workflows/workflow.yml/dispatches',
  ref: 'refs/heads/some-branch-name',
  inputs: {} }
POST /repos/OWNER/REPO/actions/workflows/workflow.yml/dispatches - 404 in 161ms
Uncaught HttpError: Not Found
    at https://cdn.skypack.dev/-/@octokit/request@v6.0.1-rQnUxH7bEDeCW9jn9uoR/dist=es2019,mode=imports/optimized/@octokit/request.js:81:21
    at async Job.doExecute (https://cdn.skypack.dev/-/bottleneck@v2.19.5-WnyfIkTTdKNNPUEySJVJ/dist=es2019,mode=imports/unoptimized/light.js:354:20)

Also tried with numeric id instead of yml filename.

The expected behavior (as with gh-client) is a 204 response:

➜  ~ echo '{"ref": "refs/heads/some-branch-name", "inputs": { }}' | GH_DEBUG=api gh api -X POST repos/OWNER/REPO/actions/workflows/workflow.yml/dispatches --input -
* Request at 2022-08-25 22:41:27.353387571 +0200 CEST m=+0.007755112
* Request to https://api.github.com/repos/OWNER/REPO/actions/workflows/workflow.yml/dispatches
> POST /repos/OWNER/REPO/actions/workflows/workflow.yml/dispatches HTTP/1.1
> Host: api.github.com
> Accept: 
> Authorization: token xxxxxx
> Content-Type: application/json; charset=utf-8
> Time-Zone: Europe/Amsterdam
> User-Agent: GitHub CLI v2.14.4

{
  "ref": "refs/heads/some-branch-name",
  "inputs": {}
}

< HTTP/2.0 204 No Content
< 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-Security-Policy: default-src 'none'
< Date: Thu, 25 Aug 2022 20:41:27 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: 
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Api-Version-Selected: 2022-08-09
< X-Github-Media-Type: github.v3; format=json
< X-Github-Request-Id: A5D2:3C2D:7BA46F:7EF84F:6307DE77
< X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
< X-Oauth-Scopes: admin:public_key, gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4973
< X-Ratelimit-Reset: 1661460507
< X-Ratelimit-Resource: core
< X-Ratelimit-Used: 27
< X-Xss-Protection: 0

* Request took 388.331557ms

It seems that the ref param is not correctly passed. Tried with both a simple branch name as the shown git ref specifier.

Unfortunately, I was not able to get the exact http request to be logged.

Would you be interested in contributing a fix?

thburghout commented 2 years ago

bug in my code :clown_face: (still no clue why the above example didn't work, but my project is now working)