Bitrise getter should be paginated
Signed-off-by: GregoireW <24318548+GregoireW@users.noreply.github.com>
This commit is contained in:
@@ -80,6 +80,42 @@ describe('BitriseClientApi', () => {
|
||||
});
|
||||
|
||||
describe('getApp()', () => {
|
||||
it('should get all apps', async () => {
|
||||
server.use(
|
||||
rest.get(
|
||||
`${mockBaseUrl}/bitrise/apps?next=slug-2-1`,
|
||||
(_req, res, ctx) => {
|
||||
const next = _req.url.searchParams.get('next');
|
||||
if (next === 'slug-2-1') {
|
||||
return res(
|
||||
ctx.json({
|
||||
data: [{ title: 'app21', slug: 'slug-2-1' }],
|
||||
}),
|
||||
);
|
||||
}
|
||||
return res(
|
||||
ctx.json({
|
||||
data: [
|
||||
{ title: 'app11', slug: 'slug-1-1' },
|
||||
{ title: 'app12', slug: 'slug-1-2' },
|
||||
],
|
||||
paging: {
|
||||
next: 'slug-2-1',
|
||||
page_item_limit: 0,
|
||||
total_item_count: 0,
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
const apps = await client.getApps();
|
||||
|
||||
expect(apps).toBeDefined();
|
||||
expect(apps.length).toBe(3);
|
||||
});
|
||||
|
||||
it('should get the app', async () => {
|
||||
server.use(
|
||||
rest.get(`${mockBaseUrl}/*`, (_req, res, ctx) => {
|
||||
|
||||
@@ -61,15 +61,25 @@ export class BitriseClientApi implements BitriseApi {
|
||||
return data.data;
|
||||
}
|
||||
|
||||
async getApps(): Promise<BitriseApp[]> {
|
||||
async getAppsPaginated(from: string): Promise<BitriseApp[]> {
|
||||
const baseUrl = await this.discoveryApi.getBaseUrl('proxy');
|
||||
const appsResponse = await fetch(`${baseUrl}/bitrise/apps`);
|
||||
const appsResponse = await fetch(`${baseUrl}/bitrise/apps?next=${from}`);
|
||||
|
||||
const appsData = await appsResponse.json();
|
||||
|
||||
if (appsData.paging?.next) {
|
||||
return appsData.data.concat(
|
||||
await this.getAppsPaginated(appsData.paging.next),
|
||||
);
|
||||
}
|
||||
|
||||
return appsData.data;
|
||||
}
|
||||
|
||||
async getApps(): Promise<BitriseApp[]> {
|
||||
return await this.getAppsPaginated('');
|
||||
}
|
||||
|
||||
async getApp(appName: string): Promise<BitriseApp | undefined> {
|
||||
const apps = await this.getApps();
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@ export type Props = {
|
||||
|
||||
export const BITRISE_APP_ANNOTATION = 'bitrise.io/app';
|
||||
|
||||
export const isBitriseAvailable = (entity: Entity) =>
|
||||
Boolean(entity.metadata.annotations?.[BITRISE_APP_ANNOTATION]);
|
||||
|
||||
export const BitriseBuildsComponent = () => {
|
||||
const { entity } = useEntity();
|
||||
const appName = entity.metadata.annotations?.[
|
||||
|
||||
@@ -16,5 +16,6 @@
|
||||
|
||||
export {
|
||||
BitriseBuildsComponent,
|
||||
isBitriseAvailable,
|
||||
BITRISE_APP_ANNOTATION,
|
||||
} from './BitriseBuildsComponent';
|
||||
|
||||
@@ -16,3 +16,4 @@
|
||||
|
||||
export { bitrisePlugin } from './plugin';
|
||||
export { EntityBitriseContent } from './extensions';
|
||||
export { isBitriseAvailable } from './components/BitriseBuildsComponent';
|
||||
|
||||
Reference in New Issue
Block a user