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

Function fetchDraftRelease

pkg/cmd/release/shared/fetch.go:246–279  ·  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

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

Callers 1

FetchReleaseFunction · 0.85

Calls 9

NewClientFromHTTPFunction · 0.92
JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 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