Skip to content

Commit 966b891

Browse files
er0kclaudebrendan-kellam
authored
feat: add option to exclude private repos from indexing (#1632)
* feat: add option to exclude private GitHub repos from indexing fixes #1631 * Use repo.private with internal exemption for exclude.private Address cubic review: visibility can be null on GitHub AE and older GHES. Use repo.private as the primary filter and exempt internal repos via repo.visibility !== 'internal'. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add regression test for missing visibility field Address coderabbit review: cover the case where a private repo has no visibility field. The repo must still be excluded when exclude.private is true. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Use second-person wording in exclude.private description Address coderabbit review: change description to "You can exclude private repositories from syncing." Regenerate all derived schema and documentation files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * nit * changelog --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Brendan Kellam <brendan@sourcebot.dev>
1 parent 72bf159 commit 966b891

13 files changed

Lines changed: 90 additions & 0 deletions

File tree

‎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.private` option to github connection config. [#1632](https://github.com/sourcebot-dev/sourcebot/pull/1632)
12+
1013
### Fixed
1114
- Silenced a false-positive `MaxListenersExceededWarning` logged on every request proxied through an external rewrite. [#1697](https://github.com/sourcebot-dev/sourcebot/pull/1697)
1215
- Upgraded `brace-expansion` to `^1.1.21`, `^2.1.7`, and `^5.0.12`. [#1700](https://github.com/sourcebot-dev/sourcebot/pull/1700)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@
125125
"default": false,
126126
"description": "Exclude archived repositories from syncing."
127127
},
128+
"private": {
129+
"type": "boolean",
130+
"default": false,
131+
"description": "Exclude private repositories from syncing. Internal repositories are not affected."
132+
},
128133
"repos": {
129134
"type": "array",
130135
"items": {

‎docs/snippets/schemas/v3/github.schema.mdx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@
121121
"default": false,
122122
"description": "Exclude archived repositories from syncing."
123123
},
124+
"private": {
125+
"type": "boolean",
126+
"default": false,
127+
"description": "Exclude private repositories from syncing. Internal repositories are not affected."
128+
},
124129
"repos": {
125130
"type": "array",
126131
"items": {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,11 @@
622622
"default": false,
623623
"description": "Exclude archived repositories from syncing."
624624
},
625+
"private": {
626+
"type": "boolean",
627+
"default": false,
628+
"description": "Exclude private repositories from syncing. Internal repositories are not affected."
629+
},
625630
"repos": {
626631
"type": "array",
627632
"items": {

‎packages/backend/src/github.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,40 @@ test('shouldExcludeRepo handles archived repos correctly', () => {
214214
expect(shouldExcludeRepo({ repo, exclude: { archived: false } })).toBe(false);
215215
});
216216

217+
test('shouldExcludeRepo handles private repos correctly', () => {
218+
const privateRepo = {
219+
full_name: 'test/private-repo',
220+
clone_url: 'https://github.com/test/private-repo.git',
221+
private: true,
222+
visibility: 'private',
223+
} as OctokitRepository;
224+
225+
expect(shouldExcludeRepo({ repo: privateRepo })).toBe(false);
226+
expect(shouldExcludeRepo({ repo: privateRepo, exclude: { private: true } })).toBe(true);
227+
expect(shouldExcludeRepo({ repo: privateRepo, exclude: { private: false } })).toBe(false);
228+
});
229+
230+
test('shouldExcludeRepo does not exclude internal repos when exclude.private is true', () => {
231+
const internalRepo = {
232+
full_name: 'test/internal-repo',
233+
clone_url: 'https://github.com/test/internal-repo.git',
234+
private: true,
235+
visibility: 'internal',
236+
} as OctokitRepository;
237+
238+
expect(shouldExcludeRepo({ repo: internalRepo, exclude: { private: true } })).toBe(false);
239+
});
240+
241+
test('shouldExcludeRepo excludes private repos with missing visibility when exclude.private is true', () => {
242+
const repo = {
243+
full_name: 'test/private-no-visibility',
244+
clone_url: 'https://github.com/test/private-no-visibility.git',
245+
private: true,
246+
} as OctokitRepository;
247+
248+
expect(shouldExcludeRepo({ repo, exclude: { private: true } })).toBe(true);
249+
});
250+
217251
test('shouldExcludeRepo handles include.topics correctly', () => {
218252
const repo = {
219253
full_name: 'test/repo',

‎packages/backend/src/github.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export type OctokitRepository = {
7777
full_name: string,
7878
fork: boolean,
7979
private: boolean,
80+
visibility?: string,
8081
html_url: string,
8182
clone_url?: string,
8283
stargazers_count?: number,
@@ -507,6 +508,11 @@ export const shouldExcludeRepo = ({
507508
return true;
508509
}
509510

511+
if (!!exclude?.private && repo.private && repo.visibility !== 'internal') {
512+
reason = `\`exclude.private\` is true`;
513+
return true;
514+
}
515+
510516
if (exclude?.repos) {
511517
if (micromatch.isMatch(repoName, exclude.repos)) {
512518
reason = `\`exclude.repos\` contains ${repoName}`;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ const schema = {
124124
"default": false,
125125
"description": "Exclude archived repositories from syncing."
126126
},
127+
"private": {
128+
"type": "boolean",
129+
"default": false,
130+
"description": "Exclude private repositories from syncing. Internal repositories are not affected."
131+
},
127132
"repos": {
128133
"type": "array",
129134
"items": {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export interface GithubConnectionConfig {
6161
* Exclude archived repositories from syncing.
6262
*/
6363
archived?: boolean;
64+
/**
65+
* Exclude private repositories from syncing. Internal repositories are not affected.
66+
*/
67+
private?: boolean;
6468
/**
6569
* List of individual repositories to exclude from syncing. Glob patterns are supported.
6670
*/

‎packages/schemas/src/v3/github.schema.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ const schema = {
120120
"default": false,
121121
"description": "Exclude archived repositories from syncing."
122122
},
123+
"private": {
124+
"type": "boolean",
125+
"default": false,
126+
"description": "Exclude private repositories from syncing. Internal repositories are not affected."
127+
},
123128
"repos": {
124129
"type": "array",
125130
"items": {

‎packages/schemas/src/v3/github.type.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export interface GithubConnectionConfig {
5252
* Exclude archived repositories from syncing.
5353
*/
5454
archived?: boolean;
55+
/**
56+
* Exclude private repositories from syncing. Internal repositories are not affected.
57+
*/
58+
private?: boolean;
5559
/**
5660
* List of individual repositories to exclude from syncing. Glob patterns are supported.
5761
*/

0 commit comments

Comments
 (0)