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