Skip to content

Commit 4af3b53

Browse files
committed
coderabbit suggestions
1 parent 1cd9007 commit 4af3b53

File tree

8 files changed

+35
-179
lines changed

8 files changed

+35
-179
lines changed

docs/docs/configuration/environment-variables.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ The following environment variables allow you to configure your Sourcebot deploy
6363
| Variable | Default | Description |
6464
| :------- | :------ | :---------- |
6565
| `GITHUB_REVIEW_AGENT_APP_ID` | `-` | <p>The GitHub App ID used for review agent authentication.</p> |
66-
| `GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET` | `-` | <p>The container relative path to the private key file for the GitHub App used by the review agent.</p> |
67-
| `GITHUB_REVIEW_AGENT_APP_PRIVATE_KEY_PATH` | `-` | <p>The webhook secret for the GitHub App used by the review agent.</p> |
66+
| `GITHUB_REVIEW_AGENT_APP_PRIVATE_KEY_PATH` | `-` | <p>The container relative path to the private key file for the GitHub App used by the review agent.</p> |
67+
| `GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET` | `-` | <p>The webhook secret for the GitHub App used by the review agent.</p> |
6868
| `OPENAI_API_KEY` | `-` | <p>The OpenAI API key used by the review agent.</p> |
6969
| `REVIEW_AGENT_API_KEY` | `-` | <p>The Sourcebot API key used by the review agent.</p> |
7070
| `REVIEW_AGENT_AUTO_REVIEW_ENABLED` | `false` | <p>Enables/disables automatic code reviews by the review agent.</p> |

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
},
1616
"deploymentHostname": {
1717
"type": "string",
18-
"format": "url",
18+
"format": "hostname",
1919
"default": "github.com",
2020
"description": "The hostname of the GitHub App deployment.",
2121
"examples": [
2222
"github.com",
2323
"github.example.com"
24-
],
25-
"pattern": "^[^\\s/$.?#].[^\\s]*$"
24+
]
2625
},
2726
"id": {
2827
"type": "string",
@@ -58,37 +57,6 @@
5857
"additionalProperties": false
5958
}
6059
]
61-
},
62-
"privateKeyPath": {
63-
"description": "The path to the private key of the GitHub App.",
64-
"anyOf": [
65-
{
66-
"type": "object",
67-
"properties": {
68-
"secret": {
69-
"type": "string",
70-
"description": "The name of the secret that contains the token."
71-
}
72-
},
73-
"required": [
74-
"secret"
75-
],
76-
"additionalProperties": false
77-
},
78-
{
79-
"type": "object",
80-
"properties": {
81-
"env": {
82-
"type": "string",
83-
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
84-
}
85-
},
86-
"required": [
87-
"env"
88-
],
89-
"additionalProperties": false
90-
}
91-
]
9260
}
9361
},
9462
"required": [

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
},
1212
"deploymentHostname": {
1313
"type": "string",
14-
"format": "url",
14+
"format": "hostname",
1515
"default": "github.com",
1616
"description": "The hostname of the GitHub App deployment.",
1717
"examples": [
1818
"github.com",
1919
"github.example.com"
20-
],
21-
"pattern": "^[^\\s/$.?#].[^\\s]*$"
20+
]
2221
},
2322
"id": {
2423
"type": "string",
@@ -54,37 +53,6 @@
5453
"additionalProperties": false
5554
}
5655
]
57-
},
58-
"privateKeyPath": {
59-
"description": "The path to the private key of the GitHub App.",
60-
"anyOf": [
61-
{
62-
"type": "object",
63-
"properties": {
64-
"secret": {
65-
"type": "string",
66-
"description": "The name of the secret that contains the token."
67-
}
68-
},
69-
"required": [
70-
"secret"
71-
],
72-
"additionalProperties": false
73-
},
74-
{
75-
"type": "object",
76-
"properties": {
77-
"env": {
78-
"type": "string",
79-
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
80-
}
81-
},
82-
"required": [
83-
"env"
84-
],
85-
"additionalProperties": false
86-
}
87-
]
8856
}
8957
},
9058
"required": [

packages/backend/src/ee/githubAppManager.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,30 @@ export class GithubAppManager {
7171
logger.info(`Found ${installations.data.length} GitHub App installations for ${deploymentHostname}/${app.id}:`);
7272

7373
for (const installationData of installations.data) {
74-
logger.info(`\tInstallation ID: ${installationData.id}, Account: ${installationData.account?.login}, Type: ${installationData.account?.type}`);
74+
if (!installationData.account || !installationData.account.login || !installationData.account.type) {
75+
logger.warn(`Skipping installation ${installationData.id}: missing account data (${installationData.account})`);
76+
continue;
77+
}
78+
79+
logger.info(`\tInstallation ID: ${installationData.id}, Account: ${installationData.account.login}, Type: ${installationData.account.type}`);
80+
81+
const owner = installationData.account.login;
82+
const accountType = installationData.account.type.toLowerCase() as 'organization' | 'user';
83+
const installationOctokit = await octokitApp.getInstallationOctokit(installationData.id);
84+
const auth = await installationOctokit.auth({ type: "installation" }) as { expires_at: string, token: string };
7585

76-
const owner = installationData.account?.login!;
77-
const accountType = installationData.account?.type!.toLowerCase() as 'organization' | 'user';
78-
const installationOctokit = await octokitApp.getInstallationOctokit(installationData.id);
79-
const auth = await installationOctokit.auth({ type: "installation" }) as { expires_at: string, token: string };
80-
81-
const installation: Installation = {
82-
id: installationData.id,
83-
appId: Number(app.id),
84-
account: {
85-
login: owner,
86-
type: accountType,
87-
},
88-
createdAt: installationData.created_at,
89-
expiresAt: auth.expires_at,
90-
token: auth.token
91-
};
92-
this.installationMap.set(this.generateMapKey(owner, deploymentHostname), installation);
86+
const installation: Installation = {
87+
id: installationData.id,
88+
appId: Number(app.id),
89+
account: {
90+
login: owner,
91+
type: accountType,
92+
},
93+
createdAt: installationData.created_at,
94+
expiresAt: auth.expires_at,
95+
token: auth.token
96+
};
97+
this.installationMap.set(this.generateMapKey(owner, deploymentHostname), installation);
9398
}
9499
}
95100

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ const schema = {
1414
},
1515
"deploymentHostname": {
1616
"type": "string",
17-
"format": "url",
17+
"format": "hostname",
1818
"default": "github.com",
1919
"description": "The hostname of the GitHub App deployment.",
2020
"examples": [
2121
"github.com",
2222
"github.example.com"
23-
],
24-
"pattern": "^[^\\s/$.?#].[^\\s]*$"
23+
]
2524
},
2625
"id": {
2726
"type": "string",
@@ -57,37 +56,6 @@ const schema = {
5756
"additionalProperties": false
5857
}
5958
]
60-
},
61-
"privateKeyPath": {
62-
"description": "The path to the private key of the GitHub App.",
63-
"anyOf": [
64-
{
65-
"type": "object",
66-
"properties": {
67-
"secret": {
68-
"type": "string",
69-
"description": "The name of the secret that contains the token."
70-
}
71-
},
72-
"required": [
73-
"secret"
74-
],
75-
"additionalProperties": false
76-
},
77-
{
78-
"type": "object",
79-
"properties": {
80-
"env": {
81-
"type": "string",
82-
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
83-
}
84-
},
85-
"required": [
86-
"env"
87-
],
88-
"additionalProperties": false
89-
}
90-
]
9159
}
9260
},
9361
"required": [

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ const schema = {
1010
},
1111
"deploymentHostname": {
1212
"type": "string",
13-
"format": "url",
13+
"format": "hostname",
1414
"default": "github.com",
1515
"description": "The hostname of the GitHub App deployment.",
1616
"examples": [
1717
"github.com",
1818
"github.example.com"
19-
],
20-
"pattern": "^[^\\s/$.?#].[^\\s]*$"
19+
]
2120
},
2221
"id": {
2322
"type": "string",
@@ -53,37 +52,6 @@ const schema = {
5352
"additionalProperties": false
5453
}
5554
]
56-
},
57-
"privateKeyPath": {
58-
"description": "The path to the private key of the GitHub App.",
59-
"anyOf": [
60-
{
61-
"type": "object",
62-
"properties": {
63-
"secret": {
64-
"type": "string",
65-
"description": "The name of the secret that contains the token."
66-
}
67-
},
68-
"required": [
69-
"secret"
70-
],
71-
"additionalProperties": false
72-
},
73-
{
74-
"type": "object",
75-
"properties": {
76-
"env": {
77-
"type": "string",
78-
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
79-
}
80-
},
81-
"required": [
82-
"env"
83-
],
84-
"additionalProperties": false
85-
}
86-
]
8755
}
8856
},
8957
"required": [

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@ export type GithubAppConfig = {
2929
*/
3030
env: string;
3131
};
32-
/**
33-
* The path to the private key of the GitHub App.
34-
*/
35-
privateKeyPath?:
36-
| {
37-
/**
38-
* The name of the secret that contains the token.
39-
*/
40-
secret: string;
41-
}
42-
| {
43-
/**
44-
* The name of the environment variable that contains the token. Only supported in declarative connection configs.
45-
*/
46-
env: string;
47-
};
4832
} & {
4933
[k: string]: unknown;
5034
};

schemas/v3/githubApp.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
},
1010
"deploymentHostname": {
1111
"type": "string",
12-
"format": "url",
12+
"format": "hostname",
1313
"default": "github.com",
1414
"description": "The hostname of the GitHub App deployment.",
1515
"examples": [
1616
"github.com",
1717
"github.example.com"
18-
],
19-
"pattern": "^[^\\s/$.?#].[^\\s]*$"
18+
]
2019
},
2120
"id": {
2221
"type": "string",
@@ -25,10 +24,6 @@
2524
"privateKey": {
2625
"$ref": "./shared.json#/definitions/Token",
2726
"description": "The private key of the GitHub App."
28-
},
29-
"privateKeyPath": {
30-
"$ref": "./shared.json#/definitions/Token",
31-
"description": "The path to the private key of the GitHub App."
3227
}
3328
},
3429
"required": [

0 commit comments

Comments
 (0)