fetchDraftRelease returns the first draft release that has tagName as its pending tag.
(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string)
| 220 | |
| 221 | // fetchDraftRelease returns the first draft release that has tagName as its pending tag. |
| 222 | func 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 | |
| 254 | func 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) |
no test coverage detected