From 09b5fcf2e4357fba580798e2dfc8f3c1002e7dc6 Mon Sep 17 00:00:00 2001 From: Nir Gazit Date: Tue, 13 Apr 2021 19:44:21 +0300 Subject: [PATCH] Filtered archived repositories when discovering repos Signed-off-by: Nir Gazit --- .changeset/real-apples-visit.md | 5 +++ .../GithubDiscoveryProcessor.test.ts | 35 ++++++++++++++++--- .../processors/GithubDiscoveryProcessor.ts | 4 ++- .../processors/github/github.test.ts | 9 ++++- .../src/ingestion/processors/github/github.ts | 2 ++ 5 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 .changeset/real-apples-visit.md diff --git a/.changeset/real-apples-visit.md b/.changeset/real-apples-visit.md new file mode 100644 index 0000000000..b5165f633b --- /dev/null +++ b/.changeset/real-apples-visit.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +GithubDiscoveryProcessor now excludes archived repositories so they won't be added to Backstage. diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.test.ts index 9c9aa41740..30778fe7fd 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.test.ts @@ -118,8 +118,16 @@ describe('GithubDiscoveryProcessor', () => { }; mockGetOrganizationRepositories.mockResolvedValueOnce({ repositories: [ - { name: 'backstage', url: 'https://github.com/backstage/backstage' }, - { name: 'demo', url: 'https://github.com/backstage/demo' }, + { + name: 'backstage', + url: 'https://github.com/backstage/backstage', + isArchived: false, + }, + { + name: 'demo', + url: 'https://github.com/backstage/demo', + isArchived: false, + }, ], }); const emitter = jest.fn(); @@ -153,14 +161,20 @@ describe('GithubDiscoveryProcessor', () => { }; mockGetOrganizationRepositories.mockResolvedValueOnce({ repositories: [ - { name: 'backstage', url: 'https://github.com/backstage/backstage' }, + { + name: 'backstage', + url: 'https://github.com/backstage/backstage', + isArchived: false, + }, { name: 'techdocs-cli', url: 'https://github.com/backstage/techdocs-cli', + isArchived: false, }, { name: 'techdocs-container', url: 'https://github.com/backstage/techdocs-container', + isArchived: false, }, ], }); @@ -187,21 +201,32 @@ describe('GithubDiscoveryProcessor', () => { optional: true, }); }); - it('filter unrelated repositories', async () => { + it('filter unrelated and archived repositories', async () => { const location: LocationSpec = { type: 'github-discovery', target: 'https://github.com/backstage/test/blob/master/catalog.yaml', }; mockGetOrganizationRepositories.mockResolvedValueOnce({ repositories: [ - { name: 'abstest', url: 'https://github.com/backstage/abctest' }, + { + name: 'abstest', + url: 'https://github.com/backstage/abctest', + isArchived: false, + }, { name: 'test', url: 'https://github.com/backstage/test', + isArchived: false, + }, + { + name: 'test-archived', + url: 'https://github.com/backstage/test', + isArchived: true, }, { name: 'testxyz', url: 'https://github.com/backstage/testxyz', + isArchived: false, }, ], }); diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts index f1818a3ab8..e187c49196 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts @@ -78,7 +78,9 @@ export class GithubDiscoveryProcessor implements CatalogProcessor { this.logger.info(`Reading GitHub repositories from ${location.target}`); const { repositories } = await getOrganizationRepositories(client, org); - const matching = repositories.filter(r => repoSearchPath.test(r.name)); + const matching = repositories.filter( + r => !r.isArchived && repoSearchPath.test(r.name), + ); const duration = ((Date.now() - startTimestamp) / 1000).toFixed(1); this.logger.debug( diff --git a/plugins/catalog-backend/src/ingestion/processors/github/github.test.ts b/plugins/catalog-backend/src/ingestion/processors/github/github.test.ts index 81b44c706d..15280b96b8 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/github.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/github.test.ts @@ -162,10 +162,12 @@ describe('github', () => { { name: 'backstage', url: 'https://github.com/backstage/backstage', + isArchived: false, }, { name: 'demo', url: 'https://github.com/backstage/demo', + isArchived: true, }, ], pageInfo: { @@ -177,10 +179,15 @@ describe('github', () => { const output = { repositories: [ - { name: 'backstage', url: 'https://github.com/backstage/backstage' }, + { + name: 'backstage', + url: 'https://github.com/backstage/backstage', + isArchived: false, + }, { name: 'demo', url: 'https://github.com/backstage/demo', + isArchived: true, }, ], }; diff --git a/plugins/catalog-backend/src/ingestion/processors/github/github.ts b/plugins/catalog-backend/src/ingestion/processors/github/github.ts index d50887c592..e07ea8917b 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/github.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/github.ts @@ -56,6 +56,7 @@ export type Team = { export type Repository = { name: string; url: string; + isArchived: boolean; }; export type Connection = { @@ -234,6 +235,7 @@ export async function getOrganizationRepositories( nodes { name url + isArchived } pageInfo { hasNextPage