improve type safety for GitHub app config

This commit is contained in:
bkellam 2025-10-28 17:16:08 -07:00
parent 40adbf856b
commit 7db49f48c5
11 changed files with 346 additions and 210 deletions

View file

@ -3,11 +3,9 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"title": "AppConfig", "title": "AppConfig",
"oneOf": [ "definitions": {
{ "GitHubAppConfig": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object", "type": "object",
"title": "GithubAppConfig",
"properties": { "properties": {
"type": { "type": {
"const": "githubApp", "const": "githubApp",
@ -61,19 +59,70 @@
}, },
"required": [ "required": [
"type", "type",
"id" "id",
"privateKey"
], ],
"oneOf": [ "additionalProperties": false
{ }
"required": [ },
"privateKey" "oneOf": [
{
"type": "object",
"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": {
"required": [ "type": "string",
"privateKeyPath" "description": "The ID of the GitHub App."
},
"privateKey": {
"description": "The private key of the GitHub App.",
"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
}
] ]
} }
},
"required": [
"type",
"id",
"privateKey"
], ],
"additionalProperties": false "additionalProperties": false
} }

View file

@ -4280,11 +4280,9 @@
"items": { "items": {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"title": "AppConfig", "title": "AppConfig",
"oneOf": [ "definitions": {
{ "GitHubAppConfig": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object", "type": "object",
"title": "GithubAppConfig",
"properties": { "properties": {
"type": { "type": {
"const": "githubApp", "const": "githubApp",
@ -4338,19 +4336,70 @@
}, },
"required": [ "required": [
"type", "type",
"id" "id",
"privateKey"
], ],
"oneOf": [ "additionalProperties": false
{ }
"required": [ },
"privateKey" "oneOf": [
{
"type": "object",
"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": {
"required": [ "type": "string",
"privateKeyPath" "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",
"privateKey"
], ],
"additionalProperties": false "additionalProperties": false
} }

View file

@ -5,6 +5,7 @@ import { createLogger } from "@sourcebot/logger";
import { getTokenFromConfig } from "../utils.js"; import { getTokenFromConfig } from "../utils.js";
import { PrismaClient } from "@sourcebot/db"; import { PrismaClient } from "@sourcebot/db";
import { App } from "@octokit/app"; import { App } from "@octokit/app";
import { GitHubAppConfig } from "@sourcebot/schemas/v3/index.type";
const logger = createLogger('githubAppManager'); const logger = createLogger('githubAppManager');
const GITHUB_DEFAULT_DEPLOYMENT_HOSTNAME = 'github.com'; const GITHUB_DEFAULT_DEPLOYMENT_HOSTNAME = 'github.com';

View file

@ -2,11 +2,9 @@
const schema = { const schema = {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"title": "AppConfig", "title": "AppConfig",
"oneOf": [ "definitions": {
{ "GitHubAppConfig": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object", "type": "object",
"title": "GithubAppConfig",
"properties": { "properties": {
"type": { "type": {
"const": "githubApp", "const": "githubApp",
@ -60,19 +58,70 @@ const schema = {
}, },
"required": [ "required": [
"type", "type",
"id" "id",
"privateKey"
], ],
"oneOf": [ "additionalProperties": false
{ }
"required": [ },
"privateKey" "oneOf": [
{
"type": "object",
"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": {
"required": [ "type": "string",
"privateKeyPath" "description": "The ID of the GitHub App."
},
"privateKey": {
"description": "The private key of the GitHub App.",
"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
}
] ]
} }
},
"required": [
"type",
"id",
"privateKey"
], ],
"additionalProperties": false "additionalProperties": false
} }

View file

@ -1,6 +1,34 @@
// THIS IS A AUTO-GENERATED FILE. DO NOT MODIFY MANUALLY! // THIS IS A AUTO-GENERATED FILE. DO NOT MODIFY MANUALLY!
export type AppConfig = GithubAppConfig; export type AppConfig = GitHubAppConfig;
export type GithubAppConfig = {
[k: string]: unknown; export interface GitHubAppConfig {
}; /**
* GitHub App Configuration
*/
type: "githubApp";
/**
* The hostname of the GitHub App deployment.
*/
deploymentHostname?: string;
/**
* The ID of the GitHub App.
*/
id: string;
/**
* The private key of the GitHub App.
*/
privateKey:
| {
/**
* The name of the secret that contains the token.
*/
secret: string;
}
| {
/**
* The name of the environment variable that contains the token. Only supported in declarative connection configs.
*/
env: string;
};
}

View file

@ -1,75 +0,0 @@
// THIS IS A AUTO-GENERATED FILE. DO NOT MODIFY MANUALLY!
const schema = {
"$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": {
"description": "The private key of the GitHub App.",
"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
}
]
}
},
"required": [
"type",
"id"
],
"oneOf": [
{
"required": [
"privateKey"
]
},
{
"required": [
"privateKeyPath"
]
}
],
"additionalProperties": false
} as const;
export { schema as githubAppSchema };

View file

@ -1,34 +0,0 @@
// THIS IS A AUTO-GENERATED FILE. DO NOT MODIFY MANUALLY!
export type GithubAppConfig = {
/**
* GitHub App Configuration
*/
type: "githubApp";
/**
* The hostname of the GitHub App deployment.
*/
deploymentHostname?: string;
/**
* The ID of the GitHub App.
*/
id: string;
/**
* The private key of the GitHub App.
*/
privateKey?:
| {
/**
* The name of the secret that contains the token.
*/
secret: string;
}
| {
/**
* The name of the environment variable that contains the token. Only supported in declarative connection configs.
*/
env: string;
};
} & {
[k: string]: unknown;
};

View file

@ -4279,11 +4279,9 @@ const schema = {
"items": { "items": {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"title": "AppConfig", "title": "AppConfig",
"oneOf": [ "definitions": {
{ "GitHubAppConfig": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object", "type": "object",
"title": "GithubAppConfig",
"properties": { "properties": {
"type": { "type": {
"const": "githubApp", "const": "githubApp",
@ -4337,19 +4335,70 @@ const schema = {
}, },
"required": [ "required": [
"type", "type",
"id" "id",
"privateKey"
], ],
"oneOf": [ "additionalProperties": false
{ }
"required": [ },
"privateKey" "oneOf": [
{
"type": "object",
"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": {
"required": [ "type": "string",
"privateKeyPath" "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",
"privateKey"
], ],
"additionalProperties": false "additionalProperties": false
} }

View file

@ -25,10 +25,7 @@ export type LanguageModel =
| OpenAICompatibleLanguageModel | OpenAICompatibleLanguageModel
| OpenRouterLanguageModel | OpenRouterLanguageModel
| XaiLanguageModel; | XaiLanguageModel;
export type AppConfig = GithubAppConfig; export type AppConfig = GitHubAppConfig;
export type GithubAppConfig = {
[k: string]: unknown;
};
export interface SourcebotConfig { export interface SourcebotConfig {
$schema?: string; $schema?: string;
@ -1073,3 +1070,33 @@ export interface XaiLanguageModel {
baseUrl?: string; baseUrl?: string;
headers?: LanguageModelHeaders; headers?: LanguageModelHeaders;
} }
export interface GitHubAppConfig {
/**
* GitHub App Configuration
*/
type: "githubApp";
/**
* The hostname of the GitHub App deployment.
*/
deploymentHostname?: string;
/**
* The ID of the GitHub App.
*/
id: string;
/**
* The private key of the GitHub App.
*/
privateKey:
| {
/**
* The name of the secret that contains the token.
*/
secret: string;
}
| {
/**
* The name of the environment variable that contains the token. Only supported in declarative connection configs.
*/
env: string;
};
}

View file

@ -1,9 +1,44 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"title": "AppConfig", "title": "AppConfig",
"definitions": {
"GitHubAppConfig": {
"type": "object",
"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": {
"$ref": "./shared.json#/definitions/Token",
"description": "The private key of the GitHub App."
}
},
"required": [
"type",
"id",
"privateKey"
],
"additionalProperties": false
}
},
"oneOf": [ "oneOf": [
{ {
"$ref": "./githubApp.json" "$ref": "#/definitions/GitHubAppConfig"
} }
] ]
} }

View file

@ -1,42 +0,0 @@
{
"$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": {
"$ref": "./shared.json#/definitions/Token",
"description": "The private key of the GitHub App."
}
},
"required": [
"type",
"id"
],
"oneOf": [
{
"required": ["privateKey"]
},
{
"required": ["privateKeyPath"]
}
],
"additionalProperties": false
}