(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface)
| 566 | } |
| 567 | |
| 568 | func getTopics(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface) ([]string, error) { |
| 569 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "topics") |
| 570 | if err != nil { |
| 571 | return nil, err |
| 572 | } |
| 573 | |
| 574 | // "mercy-preview" is still needed for some GitHub Enterprise versions |
| 575 | // TODO(api-client-rollout) |
| 576 | // This line of code is part of a mechanical roll out of the api client. |
| 577 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 578 | res, err := api.NewClientFromHTTP(httpClient).RequestWithContext(ctx, repo.RepoHost(), http.MethodGet, path.String(), nil, |
| 579 | api.WithHeader("Accept", "application/vnd.github.mercy-preview+json")) |
| 580 | if err != nil { |
| 581 | return nil, err |
| 582 | } |
| 583 | defer res.Body.Close() |
| 584 | |
| 585 | if res.StatusCode != http.StatusOK { |
| 586 | return nil, api.UnexpectedStatusError(res) |
| 587 | } |
| 588 | |
| 589 | var responseData struct { |
| 590 | Names []string `json:"names"` |
| 591 | } |
| 592 | dec := json.NewDecoder(res.Body) |
| 593 | err = dec.Decode(&responseData) |
| 594 | return responseData.Names, err |
| 595 | } |
| 596 | |
| 597 | func setTopics(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, topics []string) error { |
| 598 | payload := struct { |
no test coverage detected