Skip to content

Commit ebf351e

Browse files
AlexTugarevroboquat
authored andcommitted
[github-app] change findInstallation semantics
to return any non-uninstalled record which may now be used to identify the installer of an GitHub App installation.
1 parent 6f11cbb commit ebf351e

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

components/gitpod-db/src/typeorm/app-installation-db-impl.ts

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,15 @@ export class TypeORMAppInstallationDBImpl implements AppInstallationDB {
3939
await repo.insert(obj);
4040
}
4141

42-
protected async findAndFinishInstallation(platform: AppInstallationPlatform, installationID: string): Promise<AppInstallation | undefined> {
43-
// check if we find the complementary installation entries. If so, finish the installation
42+
public async findInstallation(platform: AppInstallationPlatform, installationID: string): Promise<AppInstallation | undefined> {
4443
const repo = await this.getRepo();
45-
const installationRecords = await repo.find({ where: { platform, installationID } });
46-
47-
// maybe we're already done and have a finished installation
48-
const finishedInstallation = installationRecords.find(r => r.state == 'installed');
49-
if (!!finishedInstallation) {
50-
return finishedInstallation;
51-
}
52-
53-
// maybe we need to finish an existing/ongoing installation
54-
const platformClaim = installationRecords.find(r => r.state == 'claimed.platform');
55-
const userClaim = installationRecords.find(r => r.state == 'claimed.user');
56-
if (!!platformClaim && !!userClaim) {
57-
const obj = new DBAppInstallation();
58-
obj.platform = platform;
59-
obj.installationID = installationID;
60-
obj.state = 'installed';
61-
obj.ownerUserID = userClaim.ownerUserID || platformClaim.ownerUserID || undefined;
62-
obj.platformUserID = platformClaim.platformUserID;
63-
obj.creationTime = new Date().toISOString();
64-
return await repo.save(obj);
65-
}
66-
67-
// we do not have a finished installation here
68-
return undefined;
69-
}
44+
const qb = repo.createQueryBuilder('installation')
45+
.where("installation.installationID = :installationID", { installationID })
46+
.andWhere('installation.state != "uninstalled"')
47+
.orderBy("installation.lastUpdateTime", "DESC")
48+
.limit(1);
7049

71-
public async findInstallation(platform: AppInstallationPlatform, installationID: string): Promise<AppInstallation | undefined> {
72-
return this.findAndFinishInstallation(platform, installationID);
50+
return (await qb.getMany())[0];
7351
}
7452

7553
public async recordUninstallation(platform: AppInstallationPlatform, source: 'user' | 'platform', installationID: string) {

0 commit comments

Comments
 (0)