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

Function getTopics

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

Source from the content-addressed store, hash-verified

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