MCPcopy Create free account
hub / github.com/cli/cli / setTopics

Function setTopics

pkg/cmd/repo/edit/edit.go:599–638  ·  view source on GitHub ↗
(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, topics []string)

Source from the content-addressed store, hash-verified

597}
598
599func 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
640func isIncluded(value string, opts []string) bool {
641 for _, opt := range opts {

Callers 1

editRunFunction · 0.85

Calls 11

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
StringMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected