MCPcopy
hub / github.com/cli/cli / setTopics

Function setTopics

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

Source from the content-addressed store, hash-verified

590}
591
592func 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
630func isIncluded(value string, opts []string) bool {
631 for _, opt := range opts {

Callers 1

editRunFunction · 0.85

Calls 9

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

Tested by

no test coverage detected