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

Method ListSubscriptions

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

Source from the content-addressed store, hash-verified

152const maxPerPage = 100
153
154func (c *eventClient) ListSubscriptions(ctx context.Context, limit int) ([]Subscription, error) {
155 if !SupportedHost(c.host) {
156 return nil, ErrUnsupportedHost
157 }
158
159 path, err := safeurl.JoinPath("event-subscriptions")
160 if err != nil {
161 return nil, err
162 }
163 path.SetQuery("per_page", strconv.Itoa(min(limit, maxPerPage)))
164
165 subs := []Subscription{}
166 for next := path.String(); next != "" && len(subs) < limit; {
167 var page struct {
168 Subscriptions []Subscription `json:"subscriptions"`
169 }
170 next, err = c.api.RESTWithNext(c.host, http.MethodGet, next, nil, &page)
171 if err != nil {
172 if httpErr, ok := errors.AsType[api.HTTPError](err); ok && httpErr.StatusCode == http.StatusForbidden {
173 return nil, forbiddenError(httpErr, err)
174 }
175 return nil, err
176 }
177 // Pages past the last one are empty, so stop there even if a link points further.
178 if len(page.Subscriptions) == 0 {
179 break
180 }
181 subs = append(subs, page.Subscriptions...)
182 }
183 return subs[:min(len(subs), limit)], nil
184}
185
186// decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a
187// 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