Skip to content

getReleaseByTagName does not find draft releases #1983

Description

@MattSturgeon

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
    }
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions