Skip to content

Commit 7d0c658

Browse files
feat(gitlab): Add exclude.userOwnedProjects config setting (#498)
1 parent b05fc7a commit 7d0c658

File tree

14 files changed

+84
-0
lines changed

14 files changed

+84
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Added `exclude.userOwnedProjects` setting to GitLab configs. [#498](https://github.com/sourcebot-dev/sourcebot/pull/498)
12+
1013
### Fixed
1114
- Fixed "couldn't find remote ref HEAD" errors when re-indexing certain repositories. [#497](https://github.com/sourcebot-dev/sourcebot/pull/497)
1215

docs/docs/connections/gitlab.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ If you're not familiar with Sourcebot [connections](/docs/connections/overview),
9090
"archived": true,
9191
// projects that are forks
9292
"forks": true,
93+
// projects that are owned by users (not groups)
94+
"userOwnedProjects": true,
9395
// projects that match these glob patterns
9496
"projects": [
9597
"my-group/foo/**",

docs/snippets/schemas/v3/connection.schema.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@
343343
"default": false,
344344
"description": "Exclude archived projects from syncing."
345345
},
346+
"userOwnedProjects": {
347+
"type": "boolean",
348+
"default": false,
349+
"description": "Exclude user-owned projects from syncing."
350+
},
346351
"projects": {
347352
"type": "array",
348353
"items": {

docs/snippets/schemas/v3/gitlab.schema.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@
126126
"default": false,
127127
"description": "Exclude archived projects from syncing."
128128
},
129+
"userOwnedProjects": {
130+
"type": "boolean",
131+
"default": false,
132+
"description": "Exclude user-owned projects from syncing."
133+
},
129134
"projects": {
130135
"type": "array",
131136
"items": {

docs/snippets/schemas/v3/index.schema.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@
606606
"default": false,
607607
"description": "Exclude archived projects from syncing."
608608
},
609+
"userOwnedProjects": {
610+
"type": "boolean",
611+
"default": false,
612+
"description": "Exclude user-owned projects from syncing."
613+
},
609614
"projects": {
610615
"type": "array",
611616
"items": {

packages/backend/src/gitlab.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,30 @@ test('shouldExcludeProject returns true when the project is excluded by exclude.
4141
})).toBe(true)
4242
});
4343

44+
test('shouldExcludeProject returns true when the project is excluded by exclude.userOwnedProjects.', () => {
45+
const project = {
46+
path_with_namespace: 'test/project',
47+
namespace: {
48+
kind: 'user',
49+
}
50+
} as unknown as ProjectSchema;
51+
52+
expect(shouldExcludeProject({
53+
project,
54+
exclude: {
55+
userOwnedProjects: true,
56+
}
57+
})).toBe(true)
58+
});
59+
60+
test('shouldExcludeProject returns false when exclude.userOwnedProjects is true but project is group-owned.', () => {
61+
const project = {
62+
path_with_namespace: 'test/project',
63+
namespace: { kind: 'group' },
64+
} as unknown as ProjectSchema;
65+
66+
expect(shouldExcludeProject({
67+
project,
68+
exclude: { userOwnedProjects: true },
69+
})).toBe(false);
70+
});

packages/backend/src/gitlab.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ export const shouldExcludeProject = ({
222222
return true;
223223
}
224224

225+
if (exclude?.userOwnedProjects && project.namespace.kind === 'user') {
226+
reason = `\`exclude.userOwnedProjects\` is true`;
227+
return true;
228+
}
229+
225230
if (exclude?.projects) {
226231
if (micromatch.isMatch(projectName, exclude.projects)) {
227232
reason = `\`exclude.projects\` contains ${projectName}`;

packages/schemas/src/v3/connection.schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ const schema = {
342342
"default": false,
343343
"description": "Exclude archived projects from syncing."
344344
},
345+
"userOwnedProjects": {
346+
"type": "boolean",
347+
"default": false,
348+
"description": "Exclude user-owned projects from syncing."
349+
},
345350
"projects": {
346351
"type": "array",
347352
"items": {

packages/schemas/src/v3/connection.type.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export interface GitlabConnectionConfig {
153153
* Exclude archived projects from syncing.
154154
*/
155155
archived?: boolean;
156+
/**
157+
* Exclude user-owned projects from syncing.
158+
*/
159+
userOwnedProjects?: boolean;
156160
/**
157161
* 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/
158162
*/

packages/schemas/src/v3/gitlab.schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ const schema = {
125125
"default": false,
126126
"description": "Exclude archived projects from syncing."
127127
},
128+
"userOwnedProjects": {
129+
"type": "boolean",
130+
"default": false,
131+
"description": "Exclude user-owned projects from syncing."
132+
},
128133
"projects": {
129134
"type": "array",
130135
"items": {

0 commit comments

Comments
 (0)