diff --git a/.changeset/silent-garlics-drum.md b/.changeset/silent-garlics-drum.md new file mode 100644 index 0000000000..6515efbd4b --- /dev/null +++ b/.changeset/silent-garlics-drum.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-gitlab': minor +--- + +Added option to skip forked repos diff --git a/docs/integrations/gitlab/discovery.md b/docs/integrations/gitlab/discovery.md index 45991b2cf5..4ddb0413b0 100644 --- a/docs/integrations/gitlab/discovery.md +++ b/docs/integrations/gitlab/discovery.md @@ -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. diff --git a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts index 9f2cd9b17a..1d6ce44176 100644 --- a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts @@ -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); } diff --git a/plugins/catalog-backend-module-gitlab/src/lib/types.ts b/plugins/catalog-backend-module-gitlab/src/lib/types.ts index c27007861b..cc382c9a43 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/types.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/types.ts @@ -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 = {