Set group as optional parameter. Scan everything if not present
Signed-off-by: ivgo <ivgo@spreadgroup.com>
This commit is contained in:
+28
-47
@@ -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;
|
||||
}
|
||||
>;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user