diff --git a/plugins/bitrise/src/api/bitriseApi.client.test.ts b/plugins/bitrise/src/api/bitriseApi.client.test.ts index 9e125d8d06..bc62491c34 100644 --- a/plugins/bitrise/src/api/bitriseApi.client.test.ts +++ b/plugins/bitrise/src/api/bitriseApi.client.test.ts @@ -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) => { diff --git a/plugins/bitrise/src/api/bitriseApi.client.ts b/plugins/bitrise/src/api/bitriseApi.client.ts index 4fc66c55a1..e7af5259ab 100644 --- a/plugins/bitrise/src/api/bitriseApi.client.ts +++ b/plugins/bitrise/src/api/bitriseApi.client.ts @@ -61,15 +61,25 @@ export class BitriseClientApi implements BitriseApi { return data.data; } - async getApps(): Promise { + async getAppsPaginated(from: string): Promise { 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 { + return await this.getAppsPaginated(''); + } + async getApp(appName: string): Promise { const apps = await this.getApps(); diff --git a/plugins/bitrise/src/components/BitriseBuildsComponent/BitriseBuildsComponent.tsx b/plugins/bitrise/src/components/BitriseBuildsComponent/BitriseBuildsComponent.tsx index 0e4bd3e5db..eeabaf0b08 100644 --- a/plugins/bitrise/src/components/BitriseBuildsComponent/BitriseBuildsComponent.tsx +++ b/plugins/bitrise/src/components/BitriseBuildsComponent/BitriseBuildsComponent.tsx @@ -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?.[ diff --git a/plugins/bitrise/src/components/BitriseBuildsComponent/index.ts b/plugins/bitrise/src/components/BitriseBuildsComponent/index.ts index 8bb1b7e13f..aaf235251d 100644 --- a/plugins/bitrise/src/components/BitriseBuildsComponent/index.ts +++ b/plugins/bitrise/src/components/BitriseBuildsComponent/index.ts @@ -16,5 +16,6 @@ export { BitriseBuildsComponent, + isBitriseAvailable, BITRISE_APP_ANNOTATION, } from './BitriseBuildsComponent'; diff --git a/plugins/bitrise/src/index.ts b/plugins/bitrise/src/index.ts index 83dad176c7..acec26825a 100644 --- a/plugins/bitrise/src/index.ts +++ b/plugins/bitrise/src/index.ts @@ -16,3 +16,4 @@ export { bitrisePlugin } from './plugin'; export { EntityBitriseContent } from './extensions'; +export { isBitriseAvailable } from './components/BitriseBuildsComponent';