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

Function getTopics

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

Source from the content-addressed store, hash-verified

567}
568
569func getTopics(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface) ([]string, error) {
570 url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "topics")
571 if err != nil {
572 return nil, err
573 }
574 req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
575 if err != nil {
576 return nil, err
577 }
578
579 // "mercy-preview" is still needed for some GitHub Enterprise versions
580 req.Header.Set("Accept", "application/vnd.github.mercy-preview+json")
581 res, err := httpClient.Do(req)
582 if err != nil {
583 return nil, err
584 }
585 defer res.Body.Close()
586
587 if res.StatusCode != http.StatusOK {
588 return nil, api.HandleHTTPError(res)
589 }
590
591 var responseData struct {
592 Names []string `json:"names"`
593 }
594 dec := json.NewDecoder(res.Body)
595 err = dec.Decode(&responseData)
596 return responseData.Names, err
597}
598
599func setTopics(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, topics []string) error {
600 payload := struct {

Callers 1

editRunFunction · 0.85

Calls 10

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
StringMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected