Skip to content

Commit c5ba3fd

Browse files
feat(api): add pagination support and query parameter to runners.ListScmOrganizations
1 parent 5c87689 commit c5ba3fd

5 files changed

Lines changed: 224 additions & 36 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 193
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gitpod%2Fgitpod-ef5f6cba1c63c41cf94bc6fddfd14f05d5e9c647a213de3ec89943bf986e05e5.yml
3-
openapi_spec_hash: 814d0b47e5a024094aa761667b9d8c5e
4-
config_hash: 7071055865674e138d6c01fea5e7c44c
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gitpod%2Fgitpod-162fdc304a6f1f8e282b49c7cde2e2aa282e58045ac814869491340f932982d4.yml
3+
openapi_spec_hash: 017607fc78184b5a49249ed134e1ad7c
4+
config_hash: 4447d1e1149a80d1bec70d353fb8acbf

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ Methods:
774774
- <code title="post /gitpod.v1.RunnerService/CheckRepositoryAccess">client.Runners.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerService.CheckRepositoryAccess">CheckRepositoryAccess</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerCheckRepositoryAccessParams">RunnerCheckRepositoryAccessParams</a>) (\*<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerCheckRepositoryAccessResponse">RunnerCheckRepositoryAccessResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
775775
- <code title="post /gitpod.v1.RunnerService/CreateRunnerLogsToken">client.Runners.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerService.NewLogsToken">NewLogsToken</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerNewLogsTokenParams">RunnerNewLogsTokenParams</a>) (\*<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerNewLogsTokenResponse">RunnerNewLogsTokenResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
776776
- <code title="post /gitpod.v1.RunnerService/CreateRunnerToken">client.Runners.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerService.NewRunnerToken">NewRunnerToken</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerNewRunnerTokenParams">RunnerNewRunnerTokenParams</a>) (\*<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerNewRunnerTokenResponse">RunnerNewRunnerTokenResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
777-
- <code title="post /gitpod.v1.RunnerService/ListSCMOrganizations">client.Runners.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerService.ListScmOrganizations">ListScmOrganizations</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, params <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerListScmOrganizationsParams">RunnerListScmOrganizationsParams</a>) (\*<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerListScmOrganizationsResponse">RunnerListScmOrganizationsResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
777+
- <code title="post /gitpod.v1.RunnerService/ListSCMOrganizations">client.Runners.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerService.ListScmOrganizations">ListScmOrganizations</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, params <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerListScmOrganizationsParams">RunnerListScmOrganizationsParams</a>) (\*<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go/packages/pagination#OrganizationsPage">OrganizationsPage</a>[<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerListScmOrganizationsResponse">RunnerListScmOrganizationsResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
778778
- <code title="post /gitpod.v1.RunnerService/ParseContextURL">client.Runners.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerService.ParseContextURL">ParseContextURL</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerParseContextURLParams">RunnerParseContextURLParams</a>) (\*<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerParseContextURLResponse">RunnerParseContextURLResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
779779
- <code title="post /gitpod.v1.RunnerService/SearchRepositories">client.Runners.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerService.SearchRepositories">SearchRepositories</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerSearchRepositoriesParams">RunnerSearchRepositoriesParams</a>) (\*<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#RunnerSearchRepositoriesResponse">RunnerSearchRepositoriesResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
780780

packages/pagination/pagination.go

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,131 @@ func (r *MembersPageAutoPager[T]) Index() int {
17541754
return r.run
17551755
}
17561756

1757+
type OrganizationsPagePagination struct {
1758+
NextToken string `json:"nextToken"`
1759+
JSON organizationsPagePaginationJSON `json:"-"`
1760+
}
1761+
1762+
// organizationsPagePaginationJSON contains the JSON metadata for the struct
1763+
// [OrganizationsPagePagination]
1764+
type organizationsPagePaginationJSON struct {
1765+
NextToken apijson.Field
1766+
raw string
1767+
ExtraFields map[string]apijson.Field
1768+
}
1769+
1770+
func (r *OrganizationsPagePagination) UnmarshalJSON(data []byte) (err error) {
1771+
return apijson.UnmarshalRoot(data, r)
1772+
}
1773+
1774+
func (r organizationsPagePaginationJSON) RawJSON() string {
1775+
return r.raw
1776+
}
1777+
1778+
type OrganizationsPage[T any] struct {
1779+
Organizations []T `json:"organizations"`
1780+
Pagination OrganizationsPagePagination `json:"pagination"`
1781+
JSON organizationsPageJSON `json:"-"`
1782+
cfg *requestconfig.RequestConfig
1783+
res *http.Response
1784+
}
1785+
1786+
// organizationsPageJSON contains the JSON metadata for the struct
1787+
// [OrganizationsPage[T]]
1788+
type organizationsPageJSON struct {
1789+
Organizations apijson.Field
1790+
Pagination apijson.Field
1791+
raw string
1792+
ExtraFields map[string]apijson.Field
1793+
}
1794+
1795+
func (r *OrganizationsPage[T]) UnmarshalJSON(data []byte) (err error) {
1796+
return apijson.UnmarshalRoot(data, r)
1797+
}
1798+
1799+
func (r organizationsPageJSON) RawJSON() string {
1800+
return r.raw
1801+
}
1802+
1803+
// GetNextPage returns the next page as defined by this pagination style. When
1804+
// there is no next page, this function will return a 'nil' for the page value, but
1805+
// will not return an error
1806+
func (r *OrganizationsPage[T]) GetNextPage() (res *OrganizationsPage[T], err error) {
1807+
if len(r.Organizations) == 0 {
1808+
return nil, nil
1809+
}
1810+
next := r.Pagination.NextToken
1811+
if len(next) == 0 {
1812+
return nil, nil
1813+
}
1814+
cfg := r.cfg.Clone(r.cfg.Context)
1815+
err = cfg.Apply(option.WithQuery("token", next))
1816+
if err != nil {
1817+
return nil, err
1818+
}
1819+
var raw *http.Response
1820+
cfg.ResponseInto = &raw
1821+
cfg.ResponseBodyInto = &res
1822+
err = cfg.Execute()
1823+
if err != nil {
1824+
return nil, err
1825+
}
1826+
res.SetPageConfig(cfg, raw)
1827+
return res, nil
1828+
}
1829+
1830+
func (r *OrganizationsPage[T]) SetPageConfig(cfg *requestconfig.RequestConfig, res *http.Response) {
1831+
if r == nil {
1832+
r = &OrganizationsPage[T]{}
1833+
}
1834+
r.cfg = cfg
1835+
r.res = res
1836+
}
1837+
1838+
type OrganizationsPageAutoPager[T any] struct {
1839+
page *OrganizationsPage[T]
1840+
cur T
1841+
idx int
1842+
run int
1843+
err error
1844+
}
1845+
1846+
func NewOrganizationsPageAutoPager[T any](page *OrganizationsPage[T], err error) *OrganizationsPageAutoPager[T] {
1847+
return &OrganizationsPageAutoPager[T]{
1848+
page: page,
1849+
err: err,
1850+
}
1851+
}
1852+
1853+
func (r *OrganizationsPageAutoPager[T]) Next() bool {
1854+
if r.page == nil || len(r.page.Organizations) == 0 {
1855+
return false
1856+
}
1857+
if r.idx >= len(r.page.Organizations) {
1858+
r.idx = 0
1859+
r.page, r.err = r.page.GetNextPage()
1860+
if r.err != nil || r.page == nil || len(r.page.Organizations) == 0 {
1861+
return false
1862+
}
1863+
}
1864+
r.cur = r.page.Organizations[r.idx]
1865+
r.run += 1
1866+
r.idx += 1
1867+
return true
1868+
}
1869+
1870+
func (r *OrganizationsPageAutoPager[T]) Current() T {
1871+
return r.cur
1872+
}
1873+
1874+
func (r *OrganizationsPageAutoPager[T]) Err() error {
1875+
return r.err
1876+
}
1877+
1878+
func (r *OrganizationsPageAutoPager[T]) Index() int {
1879+
return r.run
1880+
}
1881+
17571882
type OutputsPagePagination struct {
17581883
NextToken string `json:"nextToken"`
17591884
JSON outputsPagePaginationJSON `json:"-"`

runner.go

Lines changed: 90 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,66 @@ func (r *RunnerService) NewRunnerToken(ctx context.Context, body RunnerNewRunner
365365
// runnerId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
366366
// scmHost: "github.com"
367367
// ```
368-
func (r *RunnerService) ListScmOrganizations(ctx context.Context, params RunnerListScmOrganizationsParams, opts ...option.RequestOption) (res *RunnerListScmOrganizationsResponse, err error) {
368+
//
369+
// - Search GitLab groups:
370+
//
371+
// Returns the first page of GitLab groups matching the substring.
372+
//
373+
// ```yaml
374+
// runnerId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
375+
// scmHost: "gitlab.com"
376+
// query: "platform"
377+
// pagination:
378+
// pageSize: 25
379+
// ```
380+
func (r *RunnerService) ListScmOrganizations(ctx context.Context, params RunnerListScmOrganizationsParams, opts ...option.RequestOption) (res *pagination.OrganizationsPage[RunnerListScmOrganizationsResponse], err error) {
381+
var raw *http.Response
369382
opts = slices.Concat(r.Options, opts)
383+
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
370384
path := "gitpod.v1.RunnerService/ListSCMOrganizations"
371-
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
372-
return res, err
385+
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, params, &res, opts...)
386+
if err != nil {
387+
return nil, err
388+
}
389+
err = cfg.Execute()
390+
if err != nil {
391+
return nil, err
392+
}
393+
res.SetPageConfig(cfg, raw)
394+
return res, nil
395+
}
396+
397+
// Lists SCM organizations the user belongs to.
398+
//
399+
// Use this method to:
400+
//
401+
// - Get all organizations for a user on a specific SCM host
402+
// - Check organization admin permissions for webhook creation
403+
//
404+
// ### Examples
405+
//
406+
// - List GitHub organizations:
407+
//
408+
// Lists all organizations the user belongs to on GitHub.
409+
//
410+
// ```yaml
411+
// runnerId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
412+
// scmHost: "github.com"
413+
// ```
414+
//
415+
// - Search GitLab groups:
416+
//
417+
// Returns the first page of GitLab groups matching the substring.
418+
//
419+
// ```yaml
420+
// runnerId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
421+
// scmHost: "gitlab.com"
422+
// query: "platform"
423+
// pagination:
424+
// pageSize: 25
425+
// ```
426+
func (r *RunnerService) ListScmOrganizationsAutoPaging(ctx context.Context, params RunnerListScmOrganizationsParams, opts ...option.RequestOption) *pagination.OrganizationsPageAutoPager[RunnerListScmOrganizationsResponse] {
427+
return pagination.NewOrganizationsPageAutoPager(r.ListScmOrganizations(ctx, params, opts...))
373428
}
374429

375430
// Parses a context URL and returns the parsed result.
@@ -1169,28 +1224,6 @@ func (r runnerNewRunnerTokenResponseJSON) RawJSON() string {
11691224
}
11701225

11711226
type RunnerListScmOrganizationsResponse struct {
1172-
// List of organizations the user belongs to
1173-
Organizations []RunnerListScmOrganizationsResponseOrganization `json:"organizations"`
1174-
JSON runnerListScmOrganizationsResponseJSON `json:"-"`
1175-
}
1176-
1177-
// runnerListScmOrganizationsResponseJSON contains the JSON metadata for the struct
1178-
// [RunnerListScmOrganizationsResponse]
1179-
type runnerListScmOrganizationsResponseJSON struct {
1180-
Organizations apijson.Field
1181-
raw string
1182-
ExtraFields map[string]apijson.Field
1183-
}
1184-
1185-
func (r *RunnerListScmOrganizationsResponse) UnmarshalJSON(data []byte) (err error) {
1186-
return apijson.UnmarshalRoot(data, r)
1187-
}
1188-
1189-
func (r runnerListScmOrganizationsResponseJSON) RawJSON() string {
1190-
return r.raw
1191-
}
1192-
1193-
type RunnerListScmOrganizationsResponseOrganization struct {
11941227
// Deprecated: this field is unused by all known consumers and is scheduled for
11951228
// removal in a future release. Do not read it.
11961229
//
@@ -1204,25 +1237,25 @@ type RunnerListScmOrganizationsResponseOrganization struct {
12041237
// Organization name/slug (e.g., "gitpod-io")
12051238
Name string `json:"name"`
12061239
// Organization URL (e.g., "https://github.com/gitpod-io")
1207-
URL string `json:"url"`
1208-
JSON runnerListScmOrganizationsResponseOrganizationJSON `json:"-"`
1240+
URL string `json:"url"`
1241+
JSON runnerListScmOrganizationsResponseJSON `json:"-"`
12091242
}
12101243

1211-
// runnerListScmOrganizationsResponseOrganizationJSON contains the JSON metadata
1212-
// for the struct [RunnerListScmOrganizationsResponseOrganization]
1213-
type runnerListScmOrganizationsResponseOrganizationJSON struct {
1244+
// runnerListScmOrganizationsResponseJSON contains the JSON metadata for the struct
1245+
// [RunnerListScmOrganizationsResponse]
1246+
type runnerListScmOrganizationsResponseJSON struct {
12141247
IsAdmin apijson.Field
12151248
Name apijson.Field
12161249
URL apijson.Field
12171250
raw string
12181251
ExtraFields map[string]apijson.Field
12191252
}
12201253

1221-
func (r *RunnerListScmOrganizationsResponseOrganization) UnmarshalJSON(data []byte) (err error) {
1254+
func (r *RunnerListScmOrganizationsResponse) UnmarshalJSON(data []byte) (err error) {
12221255
return apijson.UnmarshalRoot(data, r)
12231256
}
12241257

1225-
func (r runnerListScmOrganizationsResponseOrganizationJSON) RawJSON() string {
1258+
func (r runnerListScmOrganizationsResponseJSON) RawJSON() string {
12261259
return r.raw
12271260
}
12281261

@@ -1723,6 +1756,16 @@ func (r RunnerNewRunnerTokenParams) MarshalJSON() (data []byte, err error) {
17231756
type RunnerListScmOrganizationsParams struct {
17241757
Token param.Field[string] `query:"token"`
17251758
PageSize param.Field[int64] `query:"pageSize"`
1759+
// Pagination parameters. When unset, defaults to the standard PaginationRequest
1760+
// defaults (page_size 25, max 100). Tokens are opaque and provider-specific.
1761+
Pagination param.Field[RunnerListScmOrganizationsParamsPagination] `json:"pagination"`
1762+
// Optional substring filter applied to the organization name.
1763+
//
1764+
// - GitLab: forwarded to the upstream `search` parameter (server-side,
1765+
// case-insensitive substring on name/path).
1766+
// - GitHub and Bitbucket: not implemented as they don't support searching Empty
1767+
// value means no filter.
1768+
Query param.Field[string] `json:"query"`
17261769
RunnerID param.Field[string] `json:"runnerId" format:"uuid"`
17271770
// The SCM host to list organizations from (e.g., "github.com", "gitlab.com")
17281771
ScmHost param.Field[string] `json:"scmHost"`
@@ -1741,6 +1784,21 @@ func (r RunnerListScmOrganizationsParams) URLQuery() (v url.Values) {
17411784
})
17421785
}
17431786

1787+
// Pagination parameters. When unset, defaults to the standard PaginationRequest
1788+
// defaults (page_size 25, max 100). Tokens are opaque and provider-specific.
1789+
type RunnerListScmOrganizationsParamsPagination struct {
1790+
// Token for the next set of results that was returned as next_token of a
1791+
// PaginationResponse
1792+
Token param.Field[string] `json:"token"`
1793+
// Page size is the maximum number of results to retrieve per page. Defaults to 25.
1794+
// Maximum 100.
1795+
PageSize param.Field[int64] `json:"pageSize"`
1796+
}
1797+
1798+
func (r RunnerListScmOrganizationsParamsPagination) MarshalJSON() (data []byte, err error) {
1799+
return apijson.MarshalRoot(r)
1800+
}
1801+
17441802
type RunnerParseContextURLParams struct {
17451803
ContextURL param.Field[string] `json:"contextUrl" format:"uri"`
17461804
RunnerID param.Field[string] `json:"runnerId" format:"uuid"`

runner_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ func TestRunnerListScmOrganizationsWithOptionalParams(t *testing.T) {
313313
_, err := client.Runners.ListScmOrganizations(context.TODO(), gitpod.RunnerListScmOrganizationsParams{
314314
Token: gitpod.F("token"),
315315
PageSize: gitpod.F(int64(0)),
316+
Pagination: gitpod.F(gitpod.RunnerListScmOrganizationsParamsPagination{
317+
Token: gitpod.F("token"),
318+
PageSize: gitpod.F(int64(100)),
319+
}),
320+
Query: gitpod.F("query"),
316321
RunnerID: gitpod.F("d2c94c27-3b76-4a42-b88c-95a85e392c68"),
317322
ScmHost: gitpod.F("github.com"),
318323
})

0 commit comments

Comments
 (0)