Skip to content

Commit bbb197a

Browse files
authored
fix(github app): Generate installation tokens each time (#583)
* generate installation tokens each time * changelog
1 parent d09d65d commit bbb197a

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- [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)
12+
- Fixed issue with GitHub app token tracking and refreshing. [#583](https://github.com/sourcebot-dev/sourcebot/pull/583)
1213

1314
## [4.8.1] - 2025-10-29
1415

packages/backend/src/ee/githubAppManager.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ type Installation = {
1616
login: string;
1717
type: 'organization' | 'user';
1818
};
19-
createdAt: string;
20-
expiresAt: string;
21-
token: string;
2219
};
2320

2421
export class GithubAppManager {
@@ -83,19 +80,13 @@ export class GithubAppManager {
8380

8481
const owner = installationData.account.login;
8582
const accountType = installationData.account.type.toLowerCase() as 'organization' | 'user';
86-
const installationOctokit = await octokitApp.getInstallationOctokit(installationData.id);
87-
const auth = await installationOctokit.auth({ type: "installation" }) as { expires_at: string, token: string };
88-
8983
const installation: Installation = {
9084
id: installationData.id,
9185
appId: Number(app.id),
9286
account: {
9387
login: owner,
9488
type: accountType,
9589
},
96-
createdAt: installationData.created_at,
97-
expiresAt: auth.expires_at,
98-
token: auth.token
9990
};
10091
this.installationMap.set(this.generateMapKey(owner, deploymentHostname), installation);
10192
}
@@ -113,22 +104,10 @@ export class GithubAppManager {
113104
throw new Error(`GitHub App Installation not found for ${key}`);
114105
}
115106

116-
if (installation.expiresAt < new Date().toISOString()) {
117-
const octokitApp = this.octokitApps.get(installation.appId) as App;
118-
const installationOctokit = await octokitApp.getInstallationOctokit(installation.id);
119-
const auth = await installationOctokit.auth({ type: "installation" }) as { expires_at: string, token: string };
120-
121-
const newInstallation: Installation = {
122-
...installation,
123-
expiresAt: auth.expires_at,
124-
token: auth.token
125-
};
126-
this.installationMap.set(key, newInstallation);
127-
128-
return newInstallation.token;
129-
} else {
130-
return installation.token;
131-
}
107+
const octokitApp = this.octokitApps.get(installation.appId) as App;
108+
const installationOctokit = await octokitApp.getInstallationOctokit(installation.id);
109+
const auth = await installationOctokit.auth({ type: "installation" }) as { expires_at: string, token: string };
110+
return auth.token;
132111
}
133112

134113
public appsConfigured() {

0 commit comments

Comments
 (0)