diff --git a/docs/docs/configuration/auth/overview.mdx b/docs/docs/configuration/auth/overview.mdx index 2544c013..725252be 100644 --- a/docs/docs/configuration/auth/overview.mdx +++ b/docs/docs/configuration/auth/overview.mdx @@ -10,7 +10,7 @@ Sourcebot's built-in authentication system gates your deployment, and allows adm Configure additional authentication providers for your deployment. - + Learn how to configure how members join your deployment. diff --git a/docs/snippets/schemas/v3/index.schema.mdx b/docs/snippets/schemas/v3/index.schema.mdx index 9df06a9f..c79cd2b3 100644 --- a/docs/snippets/schemas/v3/index.schema.mdx +++ b/docs/snippets/schemas/v3/index.schema.mdx @@ -4273,6 +4273,89 @@ } ] } + }, + "apps": { + "type": "array", + "description": "Defines a collection of apps that are available to Sourcebot.", + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AppConfig", + "oneOf": [ + { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "GithubAppConfig", + "properties": { + "type": { + "const": "githubApp", + "description": "GitHub App Configuration" + }, + "deploymentHostname": { + "type": "string", + "format": "hostname", + "default": "github.com", + "description": "The hostname of the GitHub App deployment.", + "examples": [ + "github.com", + "github.example.com" + ] + }, + "id": { + "type": "string", + "description": "The ID of the GitHub App." + }, + "privateKey": { + "anyOf": [ + { + "type": "object", + "properties": { + "secret": { + "type": "string", + "description": "The name of the secret that contains the token." + } + }, + "required": [ + "secret" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token. Only supported in declarative connection configs." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + } + ], + "description": "The private key of the GitHub App." + } + }, + "required": [ + "type", + "id" + ], + "oneOf": [ + { + "required": [ + "privateKey" + ] + }, + { + "required": [ + "privateKeyPath" + ] + } + ], + "additionalProperties": false + } + ] + } } }, "additionalProperties": false diff --git a/packages/backend/src/utils.ts b/packages/backend/src/utils.ts index e75ee2ae..01b44f54 100644 --- a/packages/backend/src/utils.ts +++ b/packages/backend/src/utils.ts @@ -130,13 +130,13 @@ export const fetchWithRetry = async ( export const getAuthCredentialsForRepo = async (repo: RepoWithConnections, db: PrismaClient, logger?: Logger): Promise => { // If we have github apps configured we assume that we must use them for github service auth if (repo.external_codeHostType === 'github' && hasEntitlement('github-app') && GithubAppManager.getInstance().appsConfigured()) { - const org = repo.displayName?.split('/')[0]; + const owner = repo.displayName?.split('/')[0]; const deploymentHostname = new URL(repo.external_codeHostUrl).hostname; - if (!org || !deploymentHostname) { + if (!owner || !deploymentHostname) { throw new Error(`Failed to fetch GitHub App for repo ${repo.displayName}:Invalid repo displayName (${repo.displayName}) or deployment hostname (${deploymentHostname})`); } - const token = await GithubAppManager.getInstance().getInstallationToken(org, deploymentHostname); + const token = await GithubAppManager.getInstance().getInstallationToken(owner, deploymentHostname); return { hostUrl: repo.external_codeHostUrl, token, diff --git a/packages/schemas/src/v3/index.schema.ts b/packages/schemas/src/v3/index.schema.ts index 38ec2f0a..c326e7b6 100644 --- a/packages/schemas/src/v3/index.schema.ts +++ b/packages/schemas/src/v3/index.schema.ts @@ -4272,6 +4272,89 @@ const schema = { } ] } + }, + "apps": { + "type": "array", + "description": "Defines a collection of apps that are available to Sourcebot.", + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AppConfig", + "oneOf": [ + { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "GithubAppConfig", + "properties": { + "type": { + "const": "githubApp", + "description": "GitHub App Configuration" + }, + "deploymentHostname": { + "type": "string", + "format": "hostname", + "default": "github.com", + "description": "The hostname of the GitHub App deployment.", + "examples": [ + "github.com", + "github.example.com" + ] + }, + "id": { + "type": "string", + "description": "The ID of the GitHub App." + }, + "privateKey": { + "anyOf": [ + { + "type": "object", + "properties": { + "secret": { + "type": "string", + "description": "The name of the secret that contains the token." + } + }, + "required": [ + "secret" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token. Only supported in declarative connection configs." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + } + ], + "description": "The private key of the GitHub App." + } + }, + "required": [ + "type", + "id" + ], + "oneOf": [ + { + "required": [ + "privateKey" + ] + }, + { + "required": [ + "privateKeyPath" + ] + } + ], + "additionalProperties": false + } + ] + } } }, "additionalProperties": false diff --git a/packages/schemas/src/v3/index.type.ts b/packages/schemas/src/v3/index.type.ts index 4e8982dc..3d0b1947 100644 --- a/packages/schemas/src/v3/index.type.ts +++ b/packages/schemas/src/v3/index.type.ts @@ -25,6 +25,10 @@ export type LanguageModel = | OpenAICompatibleLanguageModel | OpenRouterLanguageModel | XaiLanguageModel; +export type AppConfig = GithubAppConfig; +export type GithubAppConfig = { + [k: string]: unknown; +}; export interface SourcebotConfig { $schema?: string; @@ -45,6 +49,10 @@ export interface SourcebotConfig { * Defines a collection of language models that are available to Sourcebot. */ models?: LanguageModel[]; + /** + * Defines a collection of apps that are available to Sourcebot. + */ + apps?: AppConfig[]; } /** * Defines the global settings for Sourcebot. diff --git a/schemas/v3/index.json b/schemas/v3/index.json index b697e619..3bb129b1 100644 --- a/schemas/v3/index.json +++ b/schemas/v3/index.json @@ -118,6 +118,13 @@ "items": { "$ref": "./languageModel.json" } + }, + "apps": { + "type": "array", + "description": "Defines a collection of apps that are available to Sourcebot.", + "items": { + "$ref": "./app.json" + } } }, "additionalProperties": false