mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
generate installation tokens each time
This commit is contained in:
parent
d09d65dce7
commit
e29d8d42bc
1 changed files with 4 additions and 25 deletions
|
|
@ -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() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue