From 12f39780630b5d700ee0984166a21f5a32973522 Mon Sep 17 00:00:00 2001 From: bkellam Date: Mon, 8 Sep 2025 22:23:24 -0400 Subject: [PATCH 1/3] feat --- docs/docs/connections/gitlab.mdx | 2 ++ docs/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 | 15 +++++++++++++++ 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 +++++ 13 files changed, 69 insertions(+) diff --git a/docs/docs/connections/gitlab.mdx b/docs/docs/connections/gitlab.mdx index 87c9bd034..173c05f88 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 8ff919762..631fc17f0 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 feadeaacc..1d322f441 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 d99142548..1a513ebab 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 49ffe433f..9900b8aae 100644 --- a/packages/backend/src/gitlab.test.ts +++ b/packages/backend/src/gitlab.test.ts @@ -41,3 +41,18 @@ 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) +}); diff --git a/packages/backend/src/gitlab.ts b/packages/backend/src/gitlab.ts index 79ab643b8..d13692d3d 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 b1be96751..633577529 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 ccc71af81..cba5800e1 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 891ca4ebd..72d367e17 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 f5a293cea..f25193b86 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 9b9121218..eb97e78d5 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 f3ee3d2ff..8f346bfa7 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 aea661c07..ab5b4e621 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": { From e5274ba8f6b6ff0f9c4292fff685cc9b9b04e1a9 Mon Sep 17 00:00:00 2001 From: bkellam Date: Mon, 8 Sep 2025 22:24:58 -0400 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 848296324..e1b211126 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) From d785027730b4851bb270d334de405462a83036f6 Mon Sep 17 00:00:00 2001 From: bkellam Date: Mon, 8 Sep 2025 22:37:53 -0400 Subject: [PATCH 3/3] feedback --- packages/backend/src/gitlab.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/backend/src/gitlab.test.ts b/packages/backend/src/gitlab.test.ts index 9900b8aae..4d9190e08 100644 --- a/packages/backend/src/gitlab.test.ts +++ b/packages/backend/src/gitlab.test.ts @@ -56,3 +56,15 @@ test('shouldExcludeProject returns true when the project is excluded by exclude. } })).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); +});