MCPcopy
hub / github.com/cli/cli / getTopics

Function getTopics

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

Source from the content-addressed store, hash-verified

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

Callers 1

editRunFunction · 0.85

Calls 8

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

Tested by

no test coverage detected