Description
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:
- Create a draft release on a GitHub repo
- Attempt to use
getReleaseByTagName
to retrieve the release information - 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:
- Lookup
GET /repos/:owner/:repo/releases/tags/:tag
(404) - Lookup GraphQL query
- 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
}
}
}