Add possibility to scan all the groups in the project

Signed-off-by: ivgo <ivgo@spreadgroup.com>
This commit is contained in:
ivgo
2022-06-15 15:27:30 +02:00
parent 43bf3ae171
commit 49ff472c0b
5 changed files with 105 additions and 29 deletions
+14
View File
@@ -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`
```
+12
View File
@@ -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:
+47 -27
View File
@@ -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;
}
>;
};
};
}
@@ -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('');
});
});
@@ -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;