From 49ff472c0b527bea729ce23de65fb62f26dd20ad Mon Sep 17 00:00:00 2001 From: ivgo Date: Wed, 15 Jun 2022 15:27:30 +0200 Subject: [PATCH 1/3] 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; From 1189f00d23d12c4728bfe4eaa39845af14b461cc Mon Sep 17 00:00:00 2001 From: ivgo Date: Mon, 20 Jun 2022 11:48:58 +0200 Subject: [PATCH 2/3] Set group as optional parameter. Scan everything if not present Signed-off-by: ivgo --- .changeset/two-crews-accept.md | 9 ++- docs/integrations/gitlab/discovery.md | 14 +--- .../catalog-backend-module-gitlab/config.d.ts | 75 +++++++------------ .../src/providers/config.test.ts | 8 +- .../src/providers/config.ts | 19 +---- 5 files changed, 42 insertions(+), 83 deletions(-) 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; From 40de38154f267faa4f7f7a5c2eeee22166249de4 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Wed, 22 Jun 2022 11:45:45 +0200 Subject: [PATCH 3/3] chore: convert to patch Signed-off-by: Johan Haals --- .changeset/two-crews-accept.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/two-crews-accept.md b/.changeset/two-crews-accept.md index deacf1559d..9540f97cb5 100644 --- a/.changeset/two-crews-accept.md +++ b/.changeset/two-crews-accept.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-catalog-backend-module-gitlab': minor +'@backstage/plugin-catalog-backend-module-gitlab': patch --- 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):