fetchDraftRelease returns the first draft release that has tagName as its pending tag.
(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string)
| 235 | |
| 236 | // fetchDraftRelease returns the first draft release that has tagName as its pending tag. |
| 237 | func fetchDraftRelease(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string) (*Release, error) { |
| 238 | // First use GraphQL to find a draft release by pending tag name, since REST doesn't have this ability. |
| 239 | var query struct { |
| 240 | Repository struct { |
| 241 | Release *struct { |
| 242 | DatabaseID int64 |
| 243 | IsDraft bool |
| 244 | } `graphql:"release(tagName: $tagName)"` |
| 245 | } `graphql:"repository(owner: $owner, name: $name)"` |
| 246 | } |
| 247 | |
| 248 | variables := map[string]any{ |
| 249 | "owner": githubv4.String(repo.RepoOwner()), |
| 250 | "name": githubv4.String(repo.RepoName()), |
| 251 | "tagName": githubv4.String(tagName), |
| 252 | } |
| 253 | |
| 254 | gql := api.NewClientFromHTTP(httpClient) |
| 255 | if err := gql.QueryWithContext(ctx, repo.RepoHost(), "RepositoryReleaseByTag", &query, variables); err != nil { |
| 256 | return nil, err |
| 257 | } |
| 258 | |
| 259 | if query.Repository.Release == nil || !query.Repository.Release.IsDraft { |
| 260 | return nil, ErrReleaseNotFound |
| 261 | } |
| 262 | |
| 263 | // Then, use REST to get information about the draft release. In theory, we could have fetched |
| 264 | // all the necessary information via GraphQL, but REST is safer for backwards compatibility. |
| 265 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "releases", strconv.FormatInt(query.Repository.Release.DatabaseID, 10)) |
| 266 | if err != nil { |
| 267 | return nil, err |
| 268 | } |
| 269 | return fetchReleasePath(ctx, httpClient, repo.RepoHost(), path) |
| 270 | } |
| 271 | |
| 272 | func fetchReleasePath(ctx context.Context, httpClient *http.Client, host string, path safeurl.SafeURL) (*Release, error) { |
| 273 | // TODO(api-client-rollout) |
no test coverage detected