MCPcopy Index your code
hub / github.com/cli/cli / fetchDraftRelease

Function fetchDraftRelease

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

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

Callers 1

FetchReleaseFunction · 0.85

Calls 7

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

Tested by

no test coverage detected