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

Function fetchDraftRelease

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

220
221// fetchDraftRelease returns the first draft release that has tagName as its pending tag.
222func fetchDraftRelease(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string) (*Release, error) {
223 // First use GraphQL to find a draft release by pending tag name, since REST doesn't have this ability.
224 var query struct {
225 Repository struct {
226 Release *struct {
227 DatabaseID int64
228 IsDraft bool
229 } `graphql:"release(tagName: $tagName)"`
230 } `graphql:"repository(owner: $owner, name: $name)"`
231 }
232
233 variables := map[string]interface{}{
234 "owner": githubv4.String(repo.RepoOwner()),
235 "name": githubv4.String(repo.RepoName()),
236 "tagName": githubv4.String(tagName),
237 }
238
239 gql := api.NewClientFromHTTP(httpClient)
240 if err := gql.QueryWithContext(ctx, repo.RepoHost(), "RepositoryReleaseByTag", &query, variables); err != nil {
241 return nil, err
242 }
243
244 if query.Repository.Release == nil || !query.Repository.Release.IsDraft {
245 return nil, ErrReleaseNotFound
246 }
247
248 // Then, use REST to get information about the draft release. In theory, we could have fetched
249 // all the necessary information via GraphQL, but REST is safer for backwards compatibility.
250 path := fmt.Sprintf("repos/%s/%s/releases/%d", repo.RepoOwner(), repo.RepoName(), query.Repository.Release.DatabaseID)
251 return fetchReleasePath(ctx, httpClient, repo.RepoHost(), path)
252}
253
254func fetchReleasePath(ctx context.Context, httpClient *http.Client, host string, p string) (*Release, error) {
255 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