diff --git a/.changeset/two-crews-accept.md b/.changeset/two-crews-accept.md index 5885b1346d..deacf1559d 100644 --- a/.changeset/two-crews-accept.md +++ b/.changeset/two-crews-accept.md @@ -2,13 +2,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: +Add the possibility in the `GitlabDiscoveryEntityProvider` to scan the whole project instead of concrete groups. For that, use a configuration like this one, where the group parameter is omitted (not mandatory anymore): ```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` + yourProviderId: + 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 a7dd0a03df..aad73c8209 100644 --- a/docs/integrations/gitlab/discovery.md +++ b/docs/integrations/gitlab/discovery.md @@ -22,22 +22,10 @@ catalog: yourProviderId: host: gitlab-host # Identifies one of the hosts set up in the integrations branch: main # Optional. Uses `master` as default - group: example-group # Group and subgroup (if needed) to look for repositories + group: example-group # Optional. Group and subgroup (if needed) to look for repositories. If not present the whole project will be scanned 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 0626cb9488..82f1a5db7c 100644 --- a/plugins/catalog-backend-module-gitlab/config.d.ts +++ b/plugins/catalog-backend-module-gitlab/config.d.ts @@ -23,53 +23,34 @@ export interface Config { /** * GitlabDiscoveryEntityProvider configuration */ - 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; - } - >; + gitlab?: Record< + string, + { + /** + * (Required) Gitlab's host name. + * @visibility backend + */ + host: string; + /** + * (Optional) Gitlab's group[/subgroup] where the discovery is done. + * If not defined the whole project will be scanned. + * @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 429743f4bd..892ce5f25c 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/config.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/config.test.ts @@ -100,7 +100,7 @@ describe('config', () => { }); expect(() => readGitlabConfigs(config)).toThrow( - "Missing required config value at 'catalog.providers.gitlab.test.group'", + "Missing required config value at 'catalog.providers.gitlab.test.host'", ); }); @@ -109,8 +109,10 @@ describe('config', () => { catalog: { providers: { gitlab: { - host: 'host', - branch: 'main', + test: { + host: 'host', + branch: 'main', + }, }, }, }, diff --git a/plugins/catalog-backend-module-gitlab/src/providers/config.ts b/plugins/catalog-backend-module-gitlab/src/providers/config.ts index 56df8d62f1..d6ad28b2ca 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/config.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/config.ts @@ -25,7 +25,7 @@ import { GitlabProviderConfig } from '../lib/types'; * @param config - The config object to extract from */ function readGitlabConfig(id: string, config: Config): GitlabProviderConfig { - const group = config.getString('group'); + const group = config.getOptionalString('group') ?? ''; const host = config.getString('host'); const branch = config.getOptionalString('branch') ?? 'master'; const catalogFile = @@ -48,7 +48,6 @@ 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'); @@ -57,20 +56,8 @@ export function readGitlabConfigs(config: Config): GitlabProviderConfig[] { return configs; } - 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))); - } + for (const id of providerConfigs.keys()) { + configs.push(readGitlabConfig(id, providerConfigs.getConfig(id))); } return configs;