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