(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, topics []string)
| 597 | } |
| 598 | |
| 599 | func setTopics(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, topics []string) error { |
| 600 | payload := struct { |
| 601 | Names []string `json:"names"` |
| 602 | }{ |
| 603 | Names: topics, |
| 604 | } |
| 605 | body := &bytes.Buffer{} |
| 606 | dec := json.NewEncoder(body) |
| 607 | if err := dec.Encode(&payload); err != nil { |
| 608 | return err |
| 609 | } |
| 610 | |
| 611 | url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "topics") |
| 612 | if err != nil { |
| 613 | return err |
| 614 | } |
| 615 | req, err := http.NewRequestWithContext(ctx, "PUT", url.String(), body) |
| 616 | if err != nil { |
| 617 | return err |
| 618 | } |
| 619 | |
| 620 | req.Header.Set("Content-type", "application/json") |
| 621 | // "mercy-preview" is still needed for some GitHub Enterprise versions |
| 622 | req.Header.Set("Accept", "application/vnd.github.mercy-preview+json") |
| 623 | res, err := httpClient.Do(req) |
| 624 | if err != nil { |
| 625 | return err |
| 626 | } |
| 627 | defer res.Body.Close() |
| 628 | |
| 629 | if res.StatusCode != http.StatusOK { |
| 630 | return api.HandleHTTPError(res) |
| 631 | } |
| 632 | |
| 633 | if res.Body != nil { |
| 634 | _, _ = io.Copy(io.Discard, res.Body) |
| 635 | } |
| 636 | |
| 637 | return nil |
| 638 | } |
| 639 | |
| 640 | func isIncluded(value string, opts []string) bool { |
| 641 | for _, opt := range opts { |
no test coverage detected