From 4c4eab81b099f3091f5c40f8bcb5d90ef7e19b7f Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 28 Oct 2020 14:25:48 +0100 Subject: [PATCH] catalob-backend: make CodeOwnersProcessor handle url locations --- .changeset/old-jeans-dance.md | 5 +++++ .../processors/CodeOwnersProcessor.test.ts | 17 +++++++++++------ .../ingestion/processors/CodeOwnersProcessor.ts | 14 +++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 .changeset/old-jeans-dance.md diff --git a/.changeset/old-jeans-dance.md b/.changeset/old-jeans-dance.md new file mode 100644 index 0000000000..1bd4a3136a --- /dev/null +++ b/.changeset/old-jeans-dance.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +The CodeOwnersProcessor now handles 'url' locations diff --git a/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.test.ts index e65714bcfd..b0e857b2bb 100644 --- a/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.test.ts @@ -180,10 +180,12 @@ describe('CodeOwnersProcessor', () => { const result = await findRawCodeOwners(mockLocation(), reader); - expect(read.mock.calls.length).toBe(3); - expect(read.mock.calls[0]).toEqual([mockReadUrl('.github/')]); - expect(read.mock.calls[1]).toEqual([mockReadUrl('')]); - expect(read.mock.calls[2]).toEqual([mockReadUrl('docs/')]); + expect(read.mock.calls.length).toBe(5); + expect(read.mock.calls[0]).toEqual([mockReadUrl('')]); + expect(read.mock.calls[1]).toEqual([mockReadUrl('docs/')]); + expect(read.mock.calls[2]).toEqual([mockReadUrl('.bitbucket/')]); + expect(read.mock.calls[3]).toEqual([mockReadUrl('.github/')]); + expect(read.mock.calls[4]).toEqual([mockReadUrl('.gitlab/')]); expect(result).toEqual(ownersText); }); }); @@ -236,7 +238,7 @@ describe('CodeOwnersProcessor', () => { expect(result).toEqual(entity); }); - it('should ignore url locations', async () => { + it('should handle url locations', async () => { const { entity, processor } = setupTest(); const result = await processor.preProcessEntity( @@ -244,7 +246,10 @@ describe('CodeOwnersProcessor', () => { mockLocation({ type: 'url' }), ); - expect(result).toEqual(entity); + expect(result).toEqual({ + ...entity, + spec: { owner: 'backstage-core' }, + }); }); it('should ignore invalid kinds', async () => { diff --git a/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.ts index f186a9425c..8a10c4169b 100644 --- a/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.ts @@ -25,6 +25,7 @@ import { filter, get, head, pipe, reverse } from 'lodash/fp'; import { CatalogProcessor } from './types'; const ALLOWED_LOCATION_TYPES = [ + 'url', 'azure/api', 'bitbucket/api', 'github', @@ -33,6 +34,11 @@ const ALLOWED_LOCATION_TYPES = [ 'gitlab/api', ]; +// TODO(Rugvip): We want to properly detect out repo provider, but for now it's +// best to wait for GitHub Apps to be properly introduced and see +// what kind of APIs that integrations will expose. +const KNOWN_LOCATIONS = ['', '/docs', '/.bitbucket', '/.github', '/.gitlab']; + type Options = { reader: UrlReader; }; @@ -91,13 +97,7 @@ export async function findRawCodeOwners( return data.toString(); }; - const gitProvider = location.type.split('/')[0]; - - return Promise.any([ - readOwnerLocation(`/.${gitProvider}`), - readOwnerLocation(''), - readOwnerLocation('/docs'), - ]); + return Promise.any(KNOWN_LOCATIONS.map(readOwnerLocation)); } export function buildCodeOwnerUrl(