From 49ff472c0b527bea729ce23de65fb62f26dd20ad Mon Sep 17 00:00:00 2001 From: ivgo Date: Wed, 15 Jun 2022 15:27:30 +0200 Subject: [PATCH] Add possibility to scan all the groups in the project Signed-off-by: ivgo --- .changeset/two-crews-accept.md | 14 ++++ docs/integrations/gitlab/discovery.md | 12 +++ .../catalog-backend-module-gitlab/config.d.ts | 74 ++++++++++++------- .../src/providers/config.test.ts | 17 +++++ .../src/providers/config.ts | 17 ++++- 5 files changed, 105 insertions(+), 29 deletions(-) create mode 100644 .changeset/two-crews-accept.md diff --git a/.changeset/two-crews-accept.md b/.changeset/two-crews-accept.md new file mode 100644 index 0000000000..5885b1346d --- /dev/null +++ b/.changeset/two-crews-accept.md @@ -0,0 +1,14 @@ +--- +'@backstage/plugin-catalog-backend-module-gitlab': minor +--- + +Add the possibility in the `GitlabDiscoveryEntityProvider` to scan the whole project instead of concrete groups. For that, use a configuration like this one: + +```yaml +catalog: + providers: + gitlab: + host: gitlab-host # Identifies one of the hosts set up in the integrations + branch: main # Optional. Uses `master` as default + entityFilename: catalog-info.yaml # Optional. Defaults to `catalog-info.yaml` +``` diff --git a/docs/integrations/gitlab/discovery.md b/docs/integrations/gitlab/discovery.md index ea151e9415..a7dd0a03df 100644 --- a/docs/integrations/gitlab/discovery.md +++ b/docs/integrations/gitlab/discovery.md @@ -26,6 +26,18 @@ catalog: entityFilename: catalog-info.yaml # Optional. Defaults to `catalog-info.yaml` ``` +If you desire so, it's also possible to execute the gitlab discovery in your entire +project. In order to do that, use this catalog configuration instead: + +```yaml +catalog: + providers: + gitlab: + host: gitlab-host # Identifies one of the hosts set up in the integrations + branch: main # Optional. Uses `master` as default + entityFilename: catalog-info.yaml # Optional. Defaults to `catalog-info.yaml` +``` + As this provider is not one of the default providers, you will first need to install the gitlab catalog plugin: diff --git a/plugins/catalog-backend-module-gitlab/config.d.ts b/plugins/catalog-backend-module-gitlab/config.d.ts index 5b0d42c81d..0626cb9488 100644 --- a/plugins/catalog-backend-module-gitlab/config.d.ts +++ b/plugins/catalog-backend-module-gitlab/config.d.ts @@ -23,33 +23,53 @@ export interface Config { /** * GitlabDiscoveryEntityProvider configuration */ - gitlab?: Record< - string, - { - /** - * (Required) Gitlab's host name. - * @visibility backend - */ - host: string; - /** - * (Required) Gitlab's group[/subgroup] where the discovery is done. - * @visibility backend - */ - group: string; - /** - * (Optional) Default branch to read the catalog-info.yaml file. - * If not set, 'master' will be used. - * @visibility backend - */ - branch?: string; - /** - * (Optional) The name used for the catalog file. - * If not set, 'catalog-info.yaml' will be used. - * @visibility backend - */ - entityFilename?: string; - } - >; + gitlab?: + | { + /** + * (Required) Gitlab's host name. + * @visibility backend + */ + host: string; + /** + * (Optional) Default branch to read the catalog-info.yaml file. + * If not set, 'master' will be used. + * @visibility backend + */ + branch?: string; + /** + * (Optional) The name used for the catalog file. + * If not set, 'catalog-info.yaml' will be used. + * @visibility backend + */ + entityFilename?: string; + } + | Record< + string, + { + /** + * (Required) Gitlab's host name. + * @visibility backend + */ + host: string; + /** + * (Required) Gitlab's group[/subgroup] where the discovery is done. + * @visibility backend + */ + group: string; + /** + * (Optional) Default branch to read the catalog-info.yaml file. + * If not set, 'master' will be used. + * @visibility backend + */ + branch?: string; + /** + * (Optional) The name used for the catalog file. + * If not set, 'catalog-info.yaml' will be used. + * @visibility backend + */ + entityFilename?: string; + } + >; }; }; } diff --git a/plugins/catalog-backend-module-gitlab/src/providers/config.test.ts b/plugins/catalog-backend-module-gitlab/src/providers/config.test.ts index d28930b151..429743f4bd 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/config.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/config.test.ts @@ -103,4 +103,21 @@ describe('config', () => { "Missing required config value at 'catalog.providers.gitlab.test.group'", ); }); + + it('read full gitlab project', () => { + const config = new ConfigReader({ + catalog: { + providers: { + gitlab: { + host: 'host', + branch: 'main', + }, + }, + }, + }); + + const result = readGitlabConfigs(config); + expect(result).toHaveLength(1); + expect(result[0].group).toEqual(''); + }); }); diff --git a/plugins/catalog-backend-module-gitlab/src/providers/config.ts b/plugins/catalog-backend-module-gitlab/src/providers/config.ts index f7eb316997..56df8d62f1 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/config.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/config.ts @@ -48,6 +48,7 @@ function readGitlabConfig(id: string, config: Config): GitlabProviderConfig { * @param config - The config object to extract from */ export function readGitlabConfigs(config: Config): GitlabProviderConfig[] { + const reservedParams = ['host', 'group', 'branch', 'catalogFile']; const configs: GitlabProviderConfig[] = []; const providerConfigs = config.getOptionalConfig('catalog.providers.gitlab'); @@ -56,8 +57,20 @@ export function readGitlabConfigs(config: Config): GitlabProviderConfig[] { return configs; } - for (const id of providerConfigs.keys()) { - configs.push(readGitlabConfig(id, providerConfigs.getConfig(id))); + if (providerConfigs.keys().some(r => reservedParams.indexOf(r) >= 0)) { + configs.push({ + id: 'full-check', + group: '', + branch: providerConfigs.getOptionalString('branch') ?? 'master', + host: providerConfigs.getString('host'), + catalogFile: + providerConfigs.getOptionalString('entityFilename') ?? + 'catalog-info.yaml', + }); + } else { + for (const id of providerConfigs.keys()) { + configs.push(readGitlabConfig(id, providerConfigs.getConfig(id))); + } } return configs;