diff --git a/.changeset/strong-insects-provide.md b/.changeset/strong-insects-provide.md new file mode 100644 index 0000000000..1a271b220b --- /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. 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/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts index 70ccd44793..fabf3a1136 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GitLabDiscoveryProcessor.ts @@ -94,9 +94,16 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { }; for await (const project of projects) { result.scanned++; - if (!project.archived) { - 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) { 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;