Skip to content

Commit aca8281

Browse files
committed
handle the installation.deleted webhook event
1 parent 6b4a3d6 commit aca8281

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Sources/UnidocServer/Operations/Interactions/Unidoc.WebhookOperation.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,26 @@ extension Unidoc.WebhookOperation
114114
in db:Unidoc.Database,
115115
at time:UnixMillisecond) async throws -> HTTP.ServerResponse
116116
{
117-
guard case .created = event.action
118-
else
119-
{
120-
return .ok("")
121-
}
122-
117+
let session:Mongo.Session = try await .init(from: db.sessions)
123118
let user:Unidoc.User = .init(githubInstallation: event.installation,
124119
initialLimit: db.policy.apiLimitPerReset)
125-
let session:Mongo.Session = try await .init(from: db.sessions)
126-
let _:Unidoc.UserSecrets = try await db.users.update(user: user, with: session)
127-
return .created("")
120+
121+
switch event.action
122+
{
123+
case .created:
124+
let _:Unidoc.UserSecrets = try await db.users.update(user: user, with: session)
125+
return .created("")
126+
127+
case .deleted:
128+
let modified:Unidoc.User? = try await db.users.modify(existing: user.id,
129+
with: session)
130+
{
131+
$0[.unset] { $0[Unidoc.User[.githubInstallation]] = () }
132+
}
133+
return modified == nil
134+
? .notFound("No such user\n")
135+
: .ok("Removed user installation\n")
136+
}
128137
}
129138

130139
private __consuming

0 commit comments

Comments
 (0)