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

Method ListSubscriptions

pkg/cmd/event/client/client.go:143–173  ·  view source on GitHub ↗
(ctx context.Context, limit int)

Source from the content-addressed store, hash-verified

141const maxPerPage = 100
142
143func (c *eventClient) ListSubscriptions(ctx context.Context, limit int) ([]Subscription, error) {
144 if !SupportedHost(c.host) {
145 return nil, ErrUnsupportedHost
146 }
147
148 path, err := safeurl.JoinPath("event-subscriptions")
149 if err != nil {
150 return nil, err
151 }
152 path.SetQuery("per_page", strconv.Itoa(min(limit, maxPerPage)))
153
154 subs := []Subscription{}
155 for next := path.String(); next != "" && len(subs) < limit; {
156 var page struct {
157 Subscriptions []Subscription `json:"subscriptions"`
158 }
159 next, err = c.api.RESTWithNext(c.host, http.MethodGet, next, nil, &page)
160 if err != nil {
161 if httpErr, ok := errors.AsType[api.HTTPError](err); ok && httpErr.StatusCode == http.StatusForbidden {
162 return nil, forbiddenError(httpErr, err)
163 }
164 return nil, err
165 }
166 // Pages past the last one are empty, so stop there even if a link points further.
167 if len(page.Subscriptions) == 0 {
168 break
169 }
170 subs = append(subs, page.Subscriptions...)
171 }
172 return subs[:min(len(subs), limit)], nil
173}
174
175// decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a
176// request that failed in transit, so callers can tell it apart from a response of an unexpected shape.

Callers

nothing calls this directly

Calls 6

JoinPathFunction · 0.92
SupportedHostFunction · 0.85
forbiddenErrorFunction · 0.85
SetQueryMethod · 0.80
StringMethod · 0.65
RESTWithNextMethod · 0.65

Tested by

no test coverage detected