Skip to content

Commit

Permalink
Merge pull request #406 from Scalingo/feat/scm_orgs_pagination
Browse files Browse the repository at this point in the history
feat(scm_orgs) : add pagination support
  • Loading branch information
samiFakhfakhScalingo authored Dec 20, 2024
2 parents 76e28ae + 530411b commit 7768f63
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/SCMIntegrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Repository,
Organization,
Branch,
OrganizationsMeta,
} from "../models/auth/scm_integrations";
import { CreateParams } from "../params/auth/scm_integrations";
import { unpackData } from "../utils";
Expand Down Expand Up @@ -139,14 +140,21 @@ export default class SCMIntegrations {
* Get list of organizations attached to an SCM integration account.
* @see https://developers.scalingo.com/scm_integrations#
* @param integrationID ID of the integration
* @param page Page number
* @param per_page Number of organizations per page
* @return Promise that when resolved returns the list of organizations.
*/
organizations(integrationID: string): Promise<Organization[]> {
organizations(
integrationID: string,
page: number = 1,
per_page: number = 20,
): Promise<{ organizations: Organization[]; meta: OrganizationsMeta }> {
return unpackData(
this._client
.authApiClient()
.get(`/scm_integrations/${integrationID}/orgs`),
"organizations",
.get(`/scm_integrations/${integrationID}/orgs`, {
params: { page, per_page },
}),
);
}

Expand Down
6 changes: 6 additions & 0 deletions src/models/auth/scm_integrations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PaginationMeta } from "src/meta";

import { User } from "./user";

/**
Expand Down Expand Up @@ -81,6 +83,10 @@ export interface Organization {
url: string;
}

export interface OrganizationsMeta {
pagination: PaginationMeta;
}

/** @see https://developers.scalingo.com/scm_repo_link */
export interface Branch {
/** Name of the branch */
Expand Down
2 changes: 1 addition & 1 deletion test/SCMIntegrations/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("SCMIntegrations#organizations", () => {
testGetter(
"https://auth.scalingo.com/v1/scm_integrations/biniou/orgs",
null,
"organizations",
null,
(client) => {
return new SCMIntegrations(client).organizations("biniou");
},
Expand Down

0 comments on commit 7768f63

Please sign in to comment.