From 7d0c6588e14869a302d5dae7dcc84fb39539195a Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Mon, 8 Sep 2025 22:38:18 -0400 Subject: [PATCH] feat(gitlab): Add exclude.userOwnedProjects config setting (#498) --- CHANGELOG.md | 3 +++ docs/docs/connections/gitlab.mdx | 2 ++ .../snippets/schemas/v3/connection.schema.mdx | 5 ++++ docs/snippets/schemas/v3/gitlab.schema.mdx | 5 ++++ docs/snippets/schemas/v3/index.schema.mdx | 5 ++++ packages/backend/src/gitlab.test.ts | 27 +++++++++++++++++++ packages/backend/src/gitlab.ts | 5 ++++ packages/schemas/src/v3/connection.schema.ts | 5 ++++ packages/schemas/src/v3/connection.type.ts | 4 +++ packages/schemas/src/v3/gitlab.schema.ts | 5 ++++ packages/schemas/src/v3/gitlab.type.ts | 4 +++ packages/schemas/src/v3/index.schema.ts | 5 ++++ packages/schemas/src/v3/index.type.ts | 4 +++ schemas/v3/gitlab.json | 5 ++++ 14 files changed, 84 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84829632..e1b21112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Added `exclude.userOwnedProjects` setting to GitLab configs. [#498](https://github.com/sourcebot-dev/sourcebot/pull/498) + ### Fixed - Fixed "couldn't find remote ref HEAD" errors when re-indexing certain repositories. [#497](https://github.com/sourcebot-dev/sourcebot/pull/497) diff --git a/docs/docs/connections/gitlab.mdx b/docs/docs/connections/gitlab.mdx index 87c9bd03..173c05f8 100644 --- a/docs/docs/connections/gitlab.mdx +++ b/docs/docs/connections/gitlab.mdx @@ -90,6 +90,8 @@ If you're not familiar with Sourcebot [connections](/docs/connections/overview), "archived": true, // projects that are forks "forks": true, + // projects that are owned by users (not groups) + "userOwnedProjects": true, // projects that match these glob patterns "projects": [ "my-group/foo/**", diff --git a/docs/snippets/schemas/v3/connection.schema.mdx b/docs/snippets/schemas/v3/connection.schema.mdx index 8ff91976..631fc17f 100644 --- a/docs/snippets/schemas/v3/connection.schema.mdx +++ b/docs/snippets/schemas/v3/connection.schema.mdx @@ -343,6 +343,11 @@ "default": false, "description": "Exclude archived projects from syncing." }, + "userOwnedProjects": { + "type": "boolean", + "default": false, + "description": "Exclude user-owned projects from syncing." + }, "projects": { "type": "array", "items": { diff --git a/docs/snippets/schemas/v3/gitlab.schema.mdx b/docs/snippets/schemas/v3/gitlab.schema.mdx index feadeaac..1d322f44 100644 --- a/docs/snippets/schemas/v3/gitlab.schema.mdx +++ b/docs/snippets/schemas/v3/gitlab.schema.mdx @@ -126,6 +126,11 @@ "default": false, "description": "Exclude archived projects from syncing." }, + "userOwnedProjects": { + "type": "boolean", + "default": false, + "description": "Exclude user-owned projects from syncing." + }, "projects": { "type": "array", "items": { diff --git a/docs/snippets/schemas/v3/index.schema.mdx b/docs/snippets/schemas/v3/index.schema.mdx index d9914254..1a513eba 100644 --- a/docs/snippets/schemas/v3/index.schema.mdx +++ b/docs/snippets/schemas/v3/index.schema.mdx @@ -606,6 +606,11 @@ "default": false, "description": "Exclude archived projects from syncing." }, + "userOwnedProjects": { + "type": "boolean", + "default": false, + "description": "Exclude user-owned projects from syncing." + }, "projects": { "type": "array", "items": { diff --git a/packages/backend/src/gitlab.test.ts b/packages/backend/src/gitlab.test.ts index 49ffe433..4d9190e0 100644 --- a/packages/backend/src/gitlab.test.ts +++ b/packages/backend/src/gitlab.test.ts @@ -41,3 +41,30 @@ test('shouldExcludeProject returns true when the project is excluded by exclude. })).toBe(true) }); +test('shouldExcludeProject returns true when the project is excluded by exclude.userOwnedProjects.', () => { + const project = { + path_with_namespace: 'test/project', + namespace: { + kind: 'user', + } + } as unknown as ProjectSchema; + + expect(shouldExcludeProject({ + project, + exclude: { + userOwnedProjects: true, + } + })).toBe(true) +}); + +test('shouldExcludeProject returns false when exclude.userOwnedProjects is true but project is group-owned.', () => { + const project = { + path_with_namespace: 'test/project', + namespace: { kind: 'group' }, + } as unknown as ProjectSchema; + + expect(shouldExcludeProject({ + project, + exclude: { userOwnedProjects: true }, + })).toBe(false); +}); diff --git a/packages/backend/src/gitlab.ts b/packages/backend/src/gitlab.ts index 79ab643b..d13692d3 100644 --- a/packages/backend/src/gitlab.ts +++ b/packages/backend/src/gitlab.ts @@ -222,6 +222,11 @@ export const shouldExcludeProject = ({ return true; } + if (exclude?.userOwnedProjects && project.namespace.kind === 'user') { + reason = `\`exclude.userOwnedProjects\` is true`; + return true; + } + if (exclude?.projects) { if (micromatch.isMatch(projectName, exclude.projects)) { reason = `\`exclude.projects\` contains ${projectName}`; diff --git a/packages/schemas/src/v3/connection.schema.ts b/packages/schemas/src/v3/connection.schema.ts index b1be9675..63357752 100644 --- a/packages/schemas/src/v3/connection.schema.ts +++ b/packages/schemas/src/v3/connection.schema.ts @@ -342,6 +342,11 @@ const schema = { "default": false, "description": "Exclude archived projects from syncing." }, + "userOwnedProjects": { + "type": "boolean", + "default": false, + "description": "Exclude user-owned projects from syncing." + }, "projects": { "type": "array", "items": { diff --git a/packages/schemas/src/v3/connection.type.ts b/packages/schemas/src/v3/connection.type.ts index ccc71af8..cba5800e 100644 --- a/packages/schemas/src/v3/connection.type.ts +++ b/packages/schemas/src/v3/connection.type.ts @@ -153,6 +153,10 @@ export interface GitlabConnectionConfig { * Exclude archived projects from syncing. */ archived?: boolean; + /** + * Exclude user-owned projects from syncing. + */ + userOwnedProjects?: boolean; /** * List of projects to exclude from syncing. Glob patterns are supported. The project's namespace must be specified, see: https://docs.gitlab.com/ee/user/namespace/ */ diff --git a/packages/schemas/src/v3/gitlab.schema.ts b/packages/schemas/src/v3/gitlab.schema.ts index 891ca4eb..72d367e1 100644 --- a/packages/schemas/src/v3/gitlab.schema.ts +++ b/packages/schemas/src/v3/gitlab.schema.ts @@ -125,6 +125,11 @@ const schema = { "default": false, "description": "Exclude archived projects from syncing." }, + "userOwnedProjects": { + "type": "boolean", + "default": false, + "description": "Exclude user-owned projects from syncing." + }, "projects": { "type": "array", "items": { diff --git a/packages/schemas/src/v3/gitlab.type.ts b/packages/schemas/src/v3/gitlab.type.ts index f5a293ce..f25193b8 100644 --- a/packages/schemas/src/v3/gitlab.type.ts +++ b/packages/schemas/src/v3/gitlab.type.ts @@ -56,6 +56,10 @@ export interface GitlabConnectionConfig { * Exclude archived projects from syncing. */ archived?: boolean; + /** + * Exclude user-owned projects from syncing. + */ + userOwnedProjects?: boolean; /** * List of projects to exclude from syncing. Glob patterns are supported. The project's namespace must be specified, see: https://docs.gitlab.com/ee/user/namespace/ */ diff --git a/packages/schemas/src/v3/index.schema.ts b/packages/schemas/src/v3/index.schema.ts index 9b912121..eb97e78d 100644 --- a/packages/schemas/src/v3/index.schema.ts +++ b/packages/schemas/src/v3/index.schema.ts @@ -605,6 +605,11 @@ const schema = { "default": false, "description": "Exclude archived projects from syncing." }, + "userOwnedProjects": { + "type": "boolean", + "default": false, + "description": "Exclude user-owned projects from syncing." + }, "projects": { "type": "array", "items": { diff --git a/packages/schemas/src/v3/index.type.ts b/packages/schemas/src/v3/index.type.ts index f3ee3d2f..8f346bfa 100644 --- a/packages/schemas/src/v3/index.type.ts +++ b/packages/schemas/src/v3/index.type.ts @@ -278,6 +278,10 @@ export interface GitlabConnectionConfig { * Exclude archived projects from syncing. */ archived?: boolean; + /** + * Exclude user-owned projects from syncing. + */ + userOwnedProjects?: boolean; /** * List of projects to exclude from syncing. Glob patterns are supported. The project's namespace must be specified, see: https://docs.gitlab.com/ee/user/namespace/ */ diff --git a/schemas/v3/gitlab.json b/schemas/v3/gitlab.json index aea661c0..ab5b4e62 100644 --- a/schemas/v3/gitlab.json +++ b/schemas/v3/gitlab.json @@ -97,6 +97,11 @@ "default": false, "description": "Exclude archived projects from syncing." }, + "userOwnedProjects": { + "type": "boolean", + "default": false, + "description": "Exclude user-owned projects from syncing." + }, "projects": { "type": "array", "items": {