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

Function setTopics

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

Source from the content-addressed store, hash-verified

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