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

Function getTopics

pkg/cmd/repo/edit/edit.go:568–595  ·  view source on GitHub ↗
(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

566}
567
568func getTopics(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface) ([]string, error) {
569 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "topics")
570 if err != nil {
571 return nil, err
572 }
573
574 // "mercy-preview" is still needed for some GitHub Enterprise versions
575 // TODO(api-client-rollout)
576 // This line of code is part of a mechanical roll out of the api client.
577 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
578 res, err := api.NewClientFromHTTP(httpClient).RequestWithContext(ctx, repo.RepoHost(), http.MethodGet, path.String(), nil,
579 api.WithHeader("Accept", "application/vnd.github.mercy-preview+json"))
580 if err != nil {
581 return nil, err
582 }
583 defer res.Body.Close()
584
585 if res.StatusCode != http.StatusOK {
586 return nil, api.UnexpectedStatusError(res)
587 }
588
589 var responseData struct {
590 Names []string `json:"names"`
591 }
592 dec := json.NewDecoder(res.Body)
593 err = dec.Decode(&responseData)
594 return responseData.Names, err
595}
596
597func setTopics(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, topics []string) error {
598 payload := struct {

Callers 1

editRunFunction · 0.85

Calls 10

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

Tested by

no test coverage detected