(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, topics []string)
| 595 | } |
| 596 | |
| 597 | func setTopics(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, topics []string) error { |
| 598 | payload := struct { |
| 599 | Names []string `json:"names"` |
| 600 | }{ |
| 601 | Names: topics, |
| 602 | } |
| 603 | body := &bytes.Buffer{} |
| 604 | dec := json.NewEncoder(body) |
| 605 | if err := dec.Encode(&payload); err != nil { |
| 606 | return err |
| 607 | } |
| 608 | |
| 609 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "topics") |
| 610 | if err != nil { |
| 611 | return err |
| 612 | } |
| 613 | |
| 614 | // "mercy-preview" is still needed for some GitHub Enterprise versions |
| 615 | // TODO(api-client-rollout) |
| 616 | // This line of code is part of a mechanical roll out of the api client. |
| 617 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 618 | res, err := api.NewClientFromHTTP(httpClient).RequestWithContext(ctx, repo.RepoHost(), http.MethodPut, path.String(), body, |
| 619 | api.WithHeader("Content-Type", "application/json"), |
| 620 | api.WithHeader("Accept", "application/vnd.github.mercy-preview+json")) |
| 621 | if err != nil { |
| 622 | return err |
| 623 | } |
| 624 | defer res.Body.Close() |
| 625 | |
| 626 | if res.StatusCode != http.StatusOK { |
| 627 | return api.UnexpectedStatusError(res) |
| 628 | } |
| 629 | |
| 630 | if res.Body != nil { |
| 631 | _, _ = io.Copy(io.Discard, res.Body) |
| 632 | } |
| 633 | |
| 634 | return nil |
| 635 | } |
| 636 | |
| 637 | func isIncluded(value string, opts []string) bool { |
| 638 | for _, opt := range opts { |
no test coverage detected