From 82938ef0909b777f79a05d26b505984b82f2c001 Mon Sep 17 00:00:00 2001 From: GregoireW <24318548+GregoireW@users.noreply.github.com> Date: Wed, 10 Mar 2021 15:41:03 +0100 Subject: [PATCH 1/4] Bitrise getter should be paginated Signed-off-by: GregoireW <24318548+GregoireW@users.noreply.github.com> --- .../bitrise/src/api/bitriseApi.client.test.ts | 36 +++++++++++++++++++ plugins/bitrise/src/api/bitriseApi.client.ts | 14 ++++++-- .../BitriseBuildsComponent.tsx | 3 ++ .../BitriseBuildsComponent/index.ts | 1 + plugins/bitrise/src/index.ts | 1 + 5 files changed, 53 insertions(+), 2 deletions(-) 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'; From 68f024fa84bf94ed0c071d93aace2cae460cef69 Mon Sep 17 00:00:00 2001 From: GregoireW <24318548+GregoireW@users.noreply.github.com> Date: Wed, 10 Mar 2021 17:14:13 +0100 Subject: [PATCH 2/4] Add changeset Signed-off-by: GregoireW <24318548+GregoireW@users.noreply.github.com> --- .changeset/heavy-spiders-accept.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/heavy-spiders-accept.md diff --git a/.changeset/heavy-spiders-accept.md b/.changeset/heavy-spiders-accept.md new file mode 100644 index 0000000000..c5527ea06d --- /dev/null +++ b/.changeset/heavy-spiders-accept.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-bitrise': patch +--- + +The apps lookup from bitrise is now getting all apps by fetching every page of the app list From b564b7b38540be389e74315bbd828f267001aaee Mon Sep 17 00:00:00 2001 From: GregoireW <24318548+GregoireW@users.noreply.github.com> Date: Wed, 10 Mar 2021 17:21:15 +0100 Subject: [PATCH 3/4] Add changeset Signed-off-by: GregoireW <24318548+GregoireW@users.noreply.github.com> --- .changeset/heavy-spiders-accept.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/heavy-spiders-accept.md b/.changeset/heavy-spiders-accept.md index c5527ea06d..57080a7ada 100644 --- a/.changeset/heavy-spiders-accept.md +++ b/.changeset/heavy-spiders-accept.md @@ -2,4 +2,4 @@ '@backstage/plugin-bitrise': patch --- -The apps lookup from bitrise is now getting all apps by fetching every page of the app list +The apps lookup from 'bitrise' is now getting all apps by fetching every page of the app list From 9d246a3e89b30c8be9b7f4f3bd0a2678348fa146 Mon Sep 17 00:00:00 2001 From: GregoireW <24318548+GregoireW@users.noreply.github.com> Date: Wed, 10 Mar 2021 17:30:38 +0100 Subject: [PATCH 4/4] Add changeset Signed-off-by: GregoireW <24318548+GregoireW@users.noreply.github.com> --- .changeset/heavy-spiders-accept.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/heavy-spiders-accept.md b/.changeset/heavy-spiders-accept.md index 57080a7ada..5560071e99 100644 --- a/.changeset/heavy-spiders-accept.md +++ b/.changeset/heavy-spiders-accept.md @@ -2,4 +2,4 @@ '@backstage/plugin-bitrise': patch --- -The apps lookup from 'bitrise' is now getting all apps by fetching every page of the app list +The apps lookup is now getting all apps by fetching every page of the app list