diff --git a/CHANGELOG.md b/CHANGELOG.md index 08ed42e2b..f87694ce4 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.private` option to github connection config. [#1632](https://github.com/sourcebot-dev/sourcebot/pull/1632) + ### Fixed - Silenced a false-positive `MaxListenersExceededWarning` logged on every request proxied through an external rewrite. [#1697](https://github.com/sourcebot-dev/sourcebot/pull/1697) - Upgraded `brace-expansion` to `^1.1.21`, `^2.1.7`, and `^5.0.12`. [#1700](https://github.com/sourcebot-dev/sourcebot/pull/1700) diff --git a/docs/snippets/schemas/v3/connection.schema.mdx b/docs/snippets/schemas/v3/connection.schema.mdx index 2d4607b9d..940d0074b 100644 --- a/docs/snippets/schemas/v3/connection.schema.mdx +++ b/docs/snippets/schemas/v3/connection.schema.mdx @@ -125,6 +125,11 @@ "default": false, "description": "Exclude archived repositories from syncing." }, + "private": { + "type": "boolean", + "default": false, + "description": "Exclude private repositories from syncing. Internal repositories are not affected." + }, "repos": { "type": "array", "items": { diff --git a/docs/snippets/schemas/v3/github.schema.mdx b/docs/snippets/schemas/v3/github.schema.mdx index 7d731cdc5..d1891b426 100644 --- a/docs/snippets/schemas/v3/github.schema.mdx +++ b/docs/snippets/schemas/v3/github.schema.mdx @@ -121,6 +121,11 @@ "default": false, "description": "Exclude archived repositories from syncing." }, + "private": { + "type": "boolean", + "default": false, + "description": "Exclude private repositories from syncing. Internal repositories are not affected." + }, "repos": { "type": "array", "items": { diff --git a/docs/snippets/schemas/v3/index.schema.mdx b/docs/snippets/schemas/v3/index.schema.mdx index 60f08e149..0e9437da7 100644 --- a/docs/snippets/schemas/v3/index.schema.mdx +++ b/docs/snippets/schemas/v3/index.schema.mdx @@ -622,6 +622,11 @@ "default": false, "description": "Exclude archived repositories from syncing." }, + "private": { + "type": "boolean", + "default": false, + "description": "Exclude private repositories from syncing. Internal repositories are not affected." + }, "repos": { "type": "array", "items": { diff --git a/packages/backend/src/github.test.ts b/packages/backend/src/github.test.ts index ce6c64077..d6b6afd7b 100644 --- a/packages/backend/src/github.test.ts +++ b/packages/backend/src/github.test.ts @@ -214,6 +214,40 @@ test('shouldExcludeRepo handles archived repos correctly', () => { expect(shouldExcludeRepo({ repo, exclude: { archived: false } })).toBe(false); }); +test('shouldExcludeRepo handles private repos correctly', () => { + const privateRepo = { + full_name: 'test/private-repo', + clone_url: 'https://github.com/test/private-repo.git', + private: true, + visibility: 'private', + } as OctokitRepository; + + expect(shouldExcludeRepo({ repo: privateRepo })).toBe(false); + expect(shouldExcludeRepo({ repo: privateRepo, exclude: { private: true } })).toBe(true); + expect(shouldExcludeRepo({ repo: privateRepo, exclude: { private: false } })).toBe(false); +}); + +test('shouldExcludeRepo does not exclude internal repos when exclude.private is true', () => { + const internalRepo = { + full_name: 'test/internal-repo', + clone_url: 'https://github.com/test/internal-repo.git', + private: true, + visibility: 'internal', + } as OctokitRepository; + + expect(shouldExcludeRepo({ repo: internalRepo, exclude: { private: true } })).toBe(false); +}); + +test('shouldExcludeRepo excludes private repos with missing visibility when exclude.private is true', () => { + const repo = { + full_name: 'test/private-no-visibility', + clone_url: 'https://github.com/test/private-no-visibility.git', + private: true, + } as OctokitRepository; + + expect(shouldExcludeRepo({ repo, exclude: { private: true } })).toBe(true); +}); + test('shouldExcludeRepo handles include.topics correctly', () => { const repo = { full_name: 'test/repo', diff --git a/packages/backend/src/github.ts b/packages/backend/src/github.ts index 969de5438..7593dbc39 100644 --- a/packages/backend/src/github.ts +++ b/packages/backend/src/github.ts @@ -77,6 +77,7 @@ export type OctokitRepository = { full_name: string, fork: boolean, private: boolean, + visibility?: string, html_url: string, clone_url?: string, stargazers_count?: number, @@ -507,6 +508,11 @@ export const shouldExcludeRepo = ({ return true; } + if (!!exclude?.private && repo.private && repo.visibility !== 'internal') { + reason = `\`exclude.private\` is true`; + return true; + } + if (exclude?.repos) { if (micromatch.isMatch(repoName, exclude.repos)) { reason = `\`exclude.repos\` contains ${repoName}`; diff --git a/packages/schemas/src/v3/connection.schema.ts b/packages/schemas/src/v3/connection.schema.ts index 15d80600d..705b12bcb 100644 --- a/packages/schemas/src/v3/connection.schema.ts +++ b/packages/schemas/src/v3/connection.schema.ts @@ -124,6 +124,11 @@ const schema = { "default": false, "description": "Exclude archived repositories from syncing." }, + "private": { + "type": "boolean", + "default": false, + "description": "Exclude private repositories from syncing. Internal repositories are not affected." + }, "repos": { "type": "array", "items": { diff --git a/packages/schemas/src/v3/connection.type.ts b/packages/schemas/src/v3/connection.type.ts index 7d85e86e7..6e47be6cb 100644 --- a/packages/schemas/src/v3/connection.type.ts +++ b/packages/schemas/src/v3/connection.type.ts @@ -61,6 +61,10 @@ export interface GithubConnectionConfig { * Exclude archived repositories from syncing. */ archived?: boolean; + /** + * Exclude private repositories from syncing. Internal repositories are not affected. + */ + private?: boolean; /** * List of individual repositories to exclude from syncing. Glob patterns are supported. */ diff --git a/packages/schemas/src/v3/github.schema.ts b/packages/schemas/src/v3/github.schema.ts index 93c61ba90..7f63d7ccf 100644 --- a/packages/schemas/src/v3/github.schema.ts +++ b/packages/schemas/src/v3/github.schema.ts @@ -120,6 +120,11 @@ const schema = { "default": false, "description": "Exclude archived repositories from syncing." }, + "private": { + "type": "boolean", + "default": false, + "description": "Exclude private repositories from syncing. Internal repositories are not affected." + }, "repos": { "type": "array", "items": { diff --git a/packages/schemas/src/v3/github.type.ts b/packages/schemas/src/v3/github.type.ts index f7cdf4a2d..73195f67e 100644 --- a/packages/schemas/src/v3/github.type.ts +++ b/packages/schemas/src/v3/github.type.ts @@ -52,6 +52,10 @@ export interface GithubConnectionConfig { * Exclude archived repositories from syncing. */ archived?: boolean; + /** + * Exclude private repositories from syncing. Internal repositories are not affected. + */ + private?: boolean; /** * List of individual repositories to exclude from syncing. Glob patterns are supported. */ diff --git a/packages/schemas/src/v3/index.schema.ts b/packages/schemas/src/v3/index.schema.ts index 0d7a76d92..c39337979 100644 --- a/packages/schemas/src/v3/index.schema.ts +++ b/packages/schemas/src/v3/index.schema.ts @@ -621,6 +621,11 @@ const schema = { "default": false, "description": "Exclude archived repositories from syncing." }, + "private": { + "type": "boolean", + "default": false, + "description": "Exclude private repositories from syncing. Internal repositories are not affected." + }, "repos": { "type": "array", "items": { diff --git a/packages/schemas/src/v3/index.type.ts b/packages/schemas/src/v3/index.type.ts index 13027d9ff..f152649e2 100644 --- a/packages/schemas/src/v3/index.type.ts +++ b/packages/schemas/src/v3/index.type.ts @@ -292,6 +292,10 @@ export interface GithubConnectionConfig { * Exclude archived repositories from syncing. */ archived?: boolean; + /** + * Exclude private repositories from syncing. Internal repositories are not affected. + */ + private?: boolean; /** * List of individual repositories to exclude from syncing. Glob patterns are supported. */ diff --git a/schemas/v3/github.json b/schemas/v3/github.json index e431215a1..782498d9a 100644 --- a/schemas/v3/github.json +++ b/schemas/v3/github.json @@ -92,6 +92,11 @@ "default": false, "description": "Exclude archived repositories from syncing." }, + "private": { + "type": "boolean", + "default": false, + "description": "Exclude private repositories from syncing. Internal repositories are not affected." + }, "repos": { "type": "array", "items": {