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

getReleaseByTagName does not find draft releases #1983

Open
MattSturgeon opened this issue Nov 3, 2024 · 0 comments
Open

getReleaseByTagName does not find draft releases #1983

MattSturgeon opened this issue Nov 3, 2024 · 0 comments

Comments

@MattSturgeon
Copy link

MattSturgeon commented Nov 3, 2024

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 #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
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants