fix(github app): Generate installation tokens each time (#583)

* generate installation tokens each time

* changelog
This commit is contained in:
Michael Sukkarieh 2025-10-29 18:05:18 -07:00 committed by GitHub
parent d09d65dce7
commit bbb197a9bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 25 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- [ask sb] Fixed issue where reasoning tokens would appear in `text` content for openai compatible models. [#582](https://github.com/sourcebot-dev/sourcebot/pull/582) - [ask sb] Fixed issue where reasoning tokens would appear in `text` content for openai compatible models. [#582](https://github.com/sourcebot-dev/sourcebot/pull/582)
- Fixed issue with GitHub app token tracking and refreshing. [#583](https://github.com/sourcebot-dev/sourcebot/pull/583)
## [4.8.1] - 2025-10-29 ## [4.8.1] - 2025-10-29

View file

@ -16,9 +16,6 @@ type Installation = {
login: string; login: string;
type: 'organization' | 'user'; type: 'organization' | 'user';
}; };
createdAt: string;
expiresAt: string;
token: string;
}; };
export class GithubAppManager { export class GithubAppManager {
@ -83,9 +80,6 @@ export class GithubAppManager {
const owner = installationData.account.login; const owner = installationData.account.login;
const accountType = installationData.account.type.toLowerCase() as 'organization' | 'user'; const accountType = installationData.account.type.toLowerCase() as 'organization' | 'user';
const installationOctokit = await octokitApp.getInstallationOctokit(installationData.id);
const auth = await installationOctokit.auth({ type: "installation" }) as { expires_at: string, token: string };
const installation: Installation = { const installation: Installation = {
id: installationData.id, id: installationData.id,
appId: Number(app.id), appId: Number(app.id),
@ -93,9 +87,6 @@ export class GithubAppManager {
login: owner, login: owner,
type: accountType, type: accountType,
}, },
createdAt: installationData.created_at,
expiresAt: auth.expires_at,
token: auth.token
}; };
this.installationMap.set(this.generateMapKey(owner, deploymentHostname), installation); this.installationMap.set(this.generateMapKey(owner, deploymentHostname), installation);
} }
@ -113,22 +104,10 @@ export class GithubAppManager {
throw new Error(`GitHub App Installation not found for ${key}`); throw new Error(`GitHub App Installation not found for ${key}`);
} }
if (installation.expiresAt < new Date().toISOString()) { const octokitApp = this.octokitApps.get(installation.appId) as App;
const octokitApp = this.octokitApps.get(installation.appId) as App; const installationOctokit = await octokitApp.getInstallationOctokit(installation.id);
const installationOctokit = await octokitApp.getInstallationOctokit(installation.id); const auth = await installationOctokit.auth({ type: "installation" }) as { expires_at: string, token: string };
const auth = await installationOctokit.auth({ type: "installation" }) as { expires_at: string, token: string }; return auth.token;
const newInstallation: Installation = {
...installation,
expiresAt: auth.expires_at,
token: auth.token
};
this.installationMap.set(key, newInstallation);
return newInstallation.token;
} else {
return installation.token;
}
} }
public appsConfigured() { public appsConfigured() {