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

Function setTopics

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

Source from the content-addressed store, hash-verified

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

Callers 1

editRunFunction · 0.85

Calls 11

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
WithHeaderFunction · 0.92
UnexpectedStatusErrorFunction · 0.92
RequestWithContextMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected