MCPcopy Create free account
hub / github.com/cli/cli / fetchDraftRelease

Function fetchDraftRelease

pkg/cmd/release/shared/fetch.go:237–270  ·  view source on GitHub ↗

fetchDraftRelease returns the first draft release that has tagName as its pending tag.

(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string)

Source from the content-addressed store, hash-verified

235
236// fetchDraftRelease returns the first draft release that has tagName as its pending tag.
237func fetchDraftRelease(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string) (*Release, error) {
238 // First use GraphQL to find a draft release by pending tag name, since REST doesn't have this ability.
239 var query struct {
240 Repository struct {
241 Release *struct {
242 DatabaseID int64
243 IsDraft bool
244 } `graphql:"release(tagName: $tagName)"`
245 } `graphql:"repository(owner: $owner, name: $name)"`
246 }
247
248 variables := map[string]any{
249 "owner": githubv4.String(repo.RepoOwner()),
250 "name": githubv4.String(repo.RepoName()),
251 "tagName": githubv4.String(tagName),
252 }
253
254 gql := api.NewClientFromHTTP(httpClient)
255 if err := gql.QueryWithContext(ctx, repo.RepoHost(), "RepositoryReleaseByTag", &query, variables); err != nil {
256 return nil, err
257 }
258
259 if query.Repository.Release == nil || !query.Repository.Release.IsDraft {
260 return nil, ErrReleaseNotFound
261 }
262
263 // Then, use REST to get information about the draft release. In theory, we could have fetched
264 // all the necessary information via GraphQL, but REST is safer for backwards compatibility.
265 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "releases", strconv.FormatInt(query.Repository.Release.DatabaseID, 10))
266 if err != nil {
267 return nil, err
268 }
269 return fetchReleasePath(ctx, httpClient, repo.RepoHost(), path)
270}
271
272func fetchReleasePath(ctx context.Context, httpClient *http.Client, host string, path safeurl.SafeURL) (*Release, error) {
273 // TODO(api-client-rollout)

Callers 1

FetchReleaseFunction · 0.85

Calls 8

NewClientFromHTTPFunction · 0.92
JoinPathFunction · 0.92
fetchReleasePathFunction · 0.85
QueryWithContextMethod · 0.80
StringMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected