Skip to content

Commit 8f59fb6

Browse files
AlexTugarevroboquat
authored andcommitted
Fix deletion of old webhook events
1 parent 2d0b1a1 commit 8f59fb6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

components/gitpod-db/src/typeorm/webhook-event-db-impl.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export class WebhookEventDBImpl implements WebhookEventDB {
5858
d.setDate(d.getDate() - ageInDays);
5959
const expirationDate = d.toISOString();
6060
const query = repo
61-
.createQueryBuilder("event")
61+
.createQueryBuilder()
6262
.update()
6363
.set({ deleted: true })
64-
.where("event.creationTime < :expirationDate", { expirationDate });
64+
.where("creationTime <= :expirationDate", { expirationDate });
6565
if (typeof limit === "number") {
6666
query.limit(limit);
6767
}

components/gitpod-db/src/webhook-event-db.spec.db.ts

+16
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ export class WebhookEventDBSpec {
5252
expect(updated.type, "type should not be updated").to.equal("push");
5353
expect(updated.rawEvent, "rawEvent should not be updated").to.equal("payload as string");
5454
}
55+
56+
@test public async testDeleteOldEvents() {
57+
const cloneUrl = "http://gitlab.local/project/repo";
58+
await this.db.createEvent({
59+
rawEvent: "payload as string",
60+
status: "received",
61+
type: "push",
62+
cloneUrl,
63+
});
64+
65+
await this.db.deleteOldEvents(0, 1);
66+
67+
const event = (await this.db.findByCloneUrl(cloneUrl))[0];
68+
expect(event, "should be found").to.be.not.undefined;
69+
expect((event as DBWebhookEvent).deleted, "should be marked as deleted").to.be.true;
70+
}
5571
}
5672

5773
module.exports = WebhookEventDBSpec;

0 commit comments

Comments
 (0)