feat(catalog-backend-module-gitlab): Added option to skip forked repos

Signed-off-by: alessandro <alessandro.manno@facile.it>
This commit is contained in:
alessandro
2023-03-23 16:13:34 +01:00
parent 19919554f2
commit 66261b4ab4
4 changed files with 20 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend-module-gitlab': minor
---
Added option to skip forked repos
+2
View File
@@ -109,3 +109,5 @@ export default async function createPlugin(
```
If you don't want create location object if file with component definition do not exists in project, you can set the `skipReposWithoutExactFileMatch` option. That can reduce count of request to gitlab with 404 status code.
If you don't want to create location object if the project is a fork, you can set the `skipForkedRepos` option.
@@ -42,10 +42,11 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor {
private readonly logger: Logger;
private readonly cache: CacheClient;
private readonly skipReposWithoutExactFileMatch: boolean;
private readonly skipForkedRepos: boolean;
static fromConfig(
config: Config,
options: { logger: Logger; skipReposWithoutExactFileMatch?: boolean },
options: { logger: Logger; skipReposWithoutExactFileMatch?: boolean; skipForkedRepos?: boolean },
): GitLabDiscoveryProcessor {
const integrations = ScmIntegrations.fromConfig(config);
const pluginCache =
@@ -63,12 +64,14 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor {
pluginCache: PluginCacheManager;
logger: Logger;
skipReposWithoutExactFileMatch?: boolean;
skipForkedRepos?: boolean;
}) {
this.integrations = options.integrations;
this.cache = options.pluginCache.getClient();
this.logger = options.logger;
this.skipReposWithoutExactFileMatch =
options.skipReposWithoutExactFileMatch || false;
this.skipForkedRepos = options.skipForkedRepos || false;
}
getProcessorName(): string {
@@ -140,6 +143,10 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor {
}
}
if (this.skipForkedRepos && project.hasOwnProperty('forked_from_project')) {
continue;
}
res.matches.push(project);
}
@@ -22,6 +22,10 @@ export type GitlabGroupDescription = {
projects: GitLabProject[];
};
export type GitlabProjectForkedFrom = {
id: number
}
export type GitLabProject = {
id: number;
default_branch?: string;
@@ -29,6 +33,7 @@ export type GitLabProject = {
last_activity_at: string;
web_url: string;
path_with_namespace?: string;
forked_from_project?: GitlabProjectForkedFrom;
};
export type GitLabUser = {