Remove rules & update some tsc errors
Signed-off-by: ivgo <ivgo@spreadgroup.com>
This commit is contained in:
@@ -43,9 +43,6 @@ catalog:
|
||||
branch: main # Optional. Uses `master` as default
|
||||
group: example-group # Group and subgroup (if needed) to look for repositories
|
||||
entityFilename: catalog-info.yaml # Optional. Defaults to `catalog-info.yaml`
|
||||
rules: # Optional. Uses the default rules if not present
|
||||
- repository: example-repo
|
||||
allow: [Component, System, Location, Template]
|
||||
```
|
||||
|
||||
```ts
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Add support to custom rules for `GitlabDiscoveryEntityProvider`
|
||||
@@ -24,9 +24,6 @@ catalog:
|
||||
branch: main # Optional. Uses `master` as default
|
||||
group: example-group # Group and subgroup (if needed) to look for repositories
|
||||
entityFilename: catalog-info.yaml # Optional. Defaults to `catalog-info.yaml`
|
||||
rules: # Optional. Uses the default rules if not present
|
||||
- repository: example-repo
|
||||
allow: [Component, System, Location, Template]
|
||||
```
|
||||
|
||||
As this provider is not one of the default providers, you will first need to install
|
||||
|
||||
@@ -26,7 +26,7 @@ export type GitLabProject = {
|
||||
archived: boolean;
|
||||
last_activity_at: string;
|
||||
web_url: string;
|
||||
path_with_namespace: string;
|
||||
path_with_namespace?: string;
|
||||
};
|
||||
|
||||
export type GitlabProviderConfig = {
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ export class GitlabDiscoveryEntityProvider implements EntityProvider {
|
||||
const project_branch = project.default_branch ?? this.config.branch;
|
||||
|
||||
const projectHasFile: boolean = await client.hasFile(
|
||||
project.path_with_namespace,
|
||||
project.path_with_namespace ?? '',
|
||||
project_branch,
|
||||
this.config.catalogFile,
|
||||
);
|
||||
|
||||
@@ -18,7 +18,6 @@ import { Config } from '@backstage/config';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import path from 'path';
|
||||
import { LocationSpec } from '../api';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
|
||||
/**
|
||||
* Rules to apply to catalog entities.
|
||||
@@ -120,18 +119,6 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer {
|
||||
rules.push(...locationRules);
|
||||
}
|
||||
|
||||
if (config.has('catalog.providers')) {
|
||||
const providersConf = config.getConfig('catalog.providers');
|
||||
const providerList = providersConf.keys();
|
||||
providerList.forEach(provider => {
|
||||
if (provider === 'gitlab') {
|
||||
rules.push(
|
||||
...getGitlabRules(config, providersConf.getConfig(provider)),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return new DefaultCatalogRulesEnforcer(rules);
|
||||
}
|
||||
|
||||
@@ -200,35 +187,3 @@ function resolveTarget(type: string, target: string): string {
|
||||
|
||||
return path.resolve(target);
|
||||
}
|
||||
|
||||
function getGitlabRules(initialConfig: Config, config: Config): CatalogRule[] {
|
||||
return config.keys().flatMap(id => {
|
||||
const gitlabConf = config.getConfig(id);
|
||||
if (!gitlabConf.has('rules')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(initialConfig).gitlab;
|
||||
const gitlabHost = gitlabConf.getString('host');
|
||||
const integration = integrations.byHost(gitlabHost);
|
||||
if (!integration) {
|
||||
throw new Error(
|
||||
`No gitlab integration found that matches host ${gitlabHost}`,
|
||||
);
|
||||
}
|
||||
|
||||
const type = `url`;
|
||||
const branch = gitlabConf.getOptionalString('branch') ?? 'master';
|
||||
const entityFilename =
|
||||
gitlabConf.getOptionalString('entityFilename') ?? 'catalog-info.yaml';
|
||||
|
||||
return gitlabConf.getConfigArray('rules').map(ruleConf => {
|
||||
const repoName = ruleConf.getString('repository');
|
||||
const target = `${integration.config.baseUrl}/${id}/${repoName}/-/blob/${branch}/${entityFilename}`;
|
||||
return {
|
||||
allow: ruleConf.getStringArray('allow').map(kind => ({ kind })),
|
||||
locations: [{ type, target }],
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user