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

`getReleaseByTagName` does not find draft releases

Open MattSturgeon opened this issue 1 year ago • 0 comments

Describe the bug getReleaseByTagName is only able to find published releases, not draft releases.

This is caused by draft releases not being accessible via the GET /repos/:owner/:repo/releases/tags/:tag endpoint.

Draft releases do have the tag_name attribute set correctly, however they are only accessible via:

  • GET /repos/:owner/:repo/releases
  • GET /repos/:owner/:repo/releases/:id
  • GraphQL

Without this, the only way I am able to find draft releases is by iterating over listReleases().

To Reproduce Steps to reproduce the behavior:

  1. Create a draft release on a GitHub repo
  2. Attempt to use getReleaseByTagName to retrieve the release information
  3. See that null is returned instead

Expected behavior I expect either getReleaseByTagName to lookup draft releases, or an alternative method be added to do so.

If a new method is added, I'm not sure the best name for it.

Desktop (please complete the following information):

  • OS: NixOS 24.11
  • Browser Firefox 131
  • Version github-api 1.318

Additional context getReleaseByTagName was added in https://github.com/hub4j/github-api/pull/411

The gh CLI implements its FetchReleases function as first using the GET /repos/:owner/:repo/releases/tags/:tag endpoint, and then falling back to a fetchDraftRelease function which finds the release via a GraphQL qurey and then gets all the data via a GET /repos/:owner/:repo/releases/:id request.

In the gh CLI implementation, fetching a draft release requires three requests:

  1. Lookup GET /repos/:owner/:repo/releases/tags/:tag (404)
  2. Lookup GraphQL query
  3. Lookup GET /repos/:owner/:repo/releases/:id

The first request is not strictly necessary, since the GraphQL query will also find non-draft releases.

I was able to use the following query to get the tag's id for draft tags:

query($owner:String!, $repo:String!, $tagName:String!){
  repository(owner: $owner, name: $repo) {
    release(tagName: $tagName) {
      databaseId,
      isDraft
    }
  }
}

MattSturgeon avatar Nov 03 '24 21:11 MattSturgeon