-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathroute.ts
More file actions
60 lines (55 loc) · 1.7 KB
/
Copy pathroute.ts
File metadata and controls
60 lines (55 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { type NextRequest, NextResponse } from "next/server"
import { getSessionUser } from "@/lib/auth"
import { scheduleSignerPrSyncAfterSign } from "@/lib/cla/signer-pr-sync-scheduler"
import { SignClaError, resolveRequestEvidenceFromHeaders, signClaForUser } from "@/lib/cla/signing"
export async function POST(request: NextRequest) {
const body = await request.json()
const { orgSlug, repoName, prNumber, acceptedSha256, assented, consentTextVersion } = body as {
orgSlug?: string
repoName?: string
prNumber?: number | string
acceptedSha256?: string
assented?: boolean
consentTextVersion?: string
}
const user = await getSessionUser()
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
try {
const result = await signClaForUser({
orgSlug: orgSlug ?? "",
user,
repoName,
prNumber,
acceptedSha256,
assented,
consentTextVersion,
requestEvidence: resolveRequestEvidenceFromHeaders(request.headers),
})
const scheduleResult = await scheduleSignerPrSyncAfterSign({
signResult: result,
actor: {
userId: user.id,
githubId: user.githubId ?? null,
githubUsername: user.githubUsername ?? null,
},
})
return NextResponse.json({
signature: result.signature,
...scheduleResult,
})
} catch (error) {
if (error instanceof SignClaError) {
return NextResponse.json(
{
error: error.message,
...(error.details ?? {}),
},
{ status: error.status }
)
}
console.error("Failed to sign CLA:", error)
return NextResponse.json({ error: "Unexpected server error" }, { status: 500 })
}
}