From 3c013ef0650cd3b8c67091d8f58195b9116c11d1 Mon Sep 17 00:00:00 2001 From: Zach Hammer Date: Tue, 28 Dec 2021 18:53:54 -0500 Subject: [PATCH 1/7] add failing test for empty default_branch Signed-off-by: Zach Hammer --- .../ingestion/processors/GitLabDiscoveryProcessor.test.ts | 7 +++++++ .../src/ingestion/processors/gitlab/types.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.test.ts index 311de05673..8d85d7375f 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.test.ts @@ -184,6 +184,13 @@ describe('GitlabDiscoveryProcessor', () => { last_activity_at: '2021-08-05T11:03:05.774Z', web_url: 'https://gitlab.fake/3', }, + { + id: 4, + archived: false, + default_branch: undefined, // MISSING DEFAULT BRANCH + last_activity_at: '2021-08-05T11:03:05.774Z', + web_url: 'https://gitlab.fake/4', + }, ], }; default: diff --git a/plugins/catalog-backend/src/ingestion/processors/gitlab/types.ts b/plugins/catalog-backend/src/ingestion/processors/gitlab/types.ts index a66411ddc8..d41ed73aac 100644 --- a/plugins/catalog-backend/src/ingestion/processors/gitlab/types.ts +++ b/plugins/catalog-backend/src/ingestion/processors/gitlab/types.ts @@ -16,7 +16,7 @@ export type GitLabProject = { id: number; - default_branch: string; + default_branch?: string; archived: boolean; last_activity_at: string; web_url: string; From deb6d781f65d4661a00e9fdfcd8fb0986321f20c Mon Sep 17 00:00:00 2001 From: Zach Hammer Date: Tue, 28 Dec 2021 19:03:24 -0500 Subject: [PATCH 2/7] filter out projects with missing default branch Signed-off-by: Zach Hammer --- .../src/ingestion/processors/GitLabDiscoveryProcessor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts index 70ccd44793..d4fa2b7cce 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts @@ -94,7 +94,7 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { }; for await (const project of projects) { result.scanned++; - if (!project.archived) { + if (!(project.archived || project.default_branch === undefined)) { result.matches.push(project); } } From 3a63491c5fca52e05e3616fac1f4471f43ac0684 Mon Sep 17 00:00:00 2001 From: Zach Hammer Date: Tue, 28 Dec 2021 19:07:22 -0500 Subject: [PATCH 3/7] add changeset Signed-off-by: Zach Hammer --- .changeset/strong-insects-provide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strong-insects-provide.md diff --git a/.changeset/strong-insects-provide.md b/.changeset/strong-insects-provide.md new file mode 100644 index 0000000000..432c4eaa76 --- /dev/null +++ b/.changeset/strong-insects-provide.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Filter out projects with missing `default_branch` from gitlab discovery. From a74b842d15195646138711db5b196e709dc9c8db Mon Sep 17 00:00:00 2001 From: Zach Hammer Date: Wed, 29 Dec 2021 06:50:48 -0500 Subject: [PATCH 4/7] only filter when discovering default branch Signed-off-by: Zach Hammer --- .../src/ingestion/processors/GitLabDiscoveryProcessor.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts index d4fa2b7cce..2c95385eae 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts @@ -94,7 +94,12 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { }; for await (const project of projects) { result.scanned++; - if (!(project.archived || project.default_branch === undefined)) { + if ( + !( + project.archived || + (branch === '*' && project.default_branch === undefined) + ) + ) { result.matches.push(project); } } From 33e5814c9f30b893f49335e2388632e99afc49f0 Mon Sep 17 00:00:00 2001 From: Zach Hammer Date: Wed, 29 Dec 2021 09:02:24 -0500 Subject: [PATCH 5/7] fix changeset spelling check error from CI Signed-off-by: Zach Hammer --- .changeset/strong-insects-provide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/strong-insects-provide.md b/.changeset/strong-insects-provide.md index 432c4eaa76..0c7aff6b2a 100644 --- a/.changeset/strong-insects-provide.md +++ b/.changeset/strong-insects-provide.md @@ -2,4 +2,4 @@ '@backstage/plugin-catalog-backend': patch --- -Filter out projects with missing `default_branch` from gitlab discovery. +Filter out projects with missing `default_branch` from Gitlab Discovery. From f8259f7ceca294a83a1698450fa680363cc21c5f Mon Sep 17 00:00:00 2001 From: Zach Hammer Date: Wed, 29 Dec 2021 14:05:13 -0500 Subject: [PATCH 6/7] use GitLab casing as found in vocab.txt Signed-off-by: Zach Hammer --- .changeset/strong-insects-provide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/strong-insects-provide.md b/.changeset/strong-insects-provide.md index 0c7aff6b2a..1a271b220b 100644 --- a/.changeset/strong-insects-provide.md +++ b/.changeset/strong-insects-provide.md @@ -2,4 +2,4 @@ '@backstage/plugin-catalog-backend': patch --- -Filter out projects with missing `default_branch` from Gitlab Discovery. +Filter out projects with missing `default_branch` from GitLab Discovery. From d573aa8e308cfb275c169c8139f66fab1acfdc92 Mon Sep 17 00:00:00 2001 From: Zach Hammer Date: Wed, 29 Dec 2021 14:06:50 -0500 Subject: [PATCH 7/7] separate filter statements Signed-off-by: Zach Hammer --- .../processors/GitLabDiscoveryProcessor.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts index 2c95385eae..fabf3a1136 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts @@ -94,14 +94,16 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { }; for await (const project of projects) { result.scanned++; - if ( - !( - project.archived || - (branch === '*' && project.default_branch === undefined) - ) - ) { - result.matches.push(project); + + if (project.archived) { + continue; } + + if (branch === '*' && project.default_branch === undefined) { + continue; + } + + result.matches.push(project); } for (const project of result.matches) {