Skip to content

Commit 18ecd13

Browse files
committed
add logs
1 parent 0f39adc commit 18ecd13

1 file changed

Lines changed: 70 additions & 2 deletions

File tree

app/api/webhook/github/route.ts

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ type PullRequestPayload = {
5252
action?: string
5353
number?: number
5454
installation?: { id?: number }
55+
sender?: {
56+
login?: string
57+
id?: number
58+
type?: string
59+
}
5560
pull_request?: {
56-
user?: { login?: string; id?: number }
57-
head?: { sha?: string }
61+
user?: { login?: string; id?: number; type?: string }
62+
head?: { sha?: string; ref?: string }
63+
base?: { ref?: string }
64+
author_association?: string
5865
}
5966
repository?: {
6067
name?: string
68+
full_name?: string
6169
owner?: { login?: string }
6270
}
6371
}
@@ -163,6 +171,48 @@ export async function POST(request: NextRequest) {
163171
)
164172
}
165173

174+
if (isDependabotLikePullRequest(prPayload)) {
175+
const author = prPayload.pull_request?.user
176+
const sender = prPayload.sender
177+
const headRef = prPayload.pull_request?.head?.ref ?? null
178+
console.info("[webhook][dependabot-like] pull_request event received", {
179+
deliveryId,
180+
action,
181+
installationId: prPayload.installation?.id ?? null,
182+
repository: {
183+
owner: orgSlug,
184+
name: repoName,
185+
fullName: prPayload.repository?.full_name ?? null,
186+
},
187+
prNumber,
188+
author: {
189+
login: author?.login ?? null,
190+
id: author?.id ?? null,
191+
type: author?.type ?? null,
192+
},
193+
sender: {
194+
login: sender?.login ?? null,
195+
id: sender?.id ?? null,
196+
type: sender?.type ?? null,
197+
},
198+
head: {
199+
ref: headRef,
200+
sha: headSha.slice(0, 12),
201+
},
202+
baseRef: prPayload.pull_request?.base?.ref ?? null,
203+
authorAssociation: prPayload.pull_request?.author_association ?? null,
204+
heuristics: {
205+
authorLoginLooksDependabot: (author?.login ?? "").toLowerCase().includes("dependabot"),
206+
senderLoginLooksDependabot: (sender?.login ?? "").toLowerCase().includes("dependabot"),
207+
authorLooksBot:
208+
author?.type === "Bot" || (author?.login ?? "").toLowerCase().endsWith("[bot]"),
209+
senderLooksBot:
210+
sender?.type === "Bot" || (sender?.login ?? "").toLowerCase().endsWith("[bot]"),
211+
headRefLooksDependabot: (headRef ?? "").toLowerCase().startsWith("dependabot/"),
212+
},
213+
})
214+
}
215+
166216
if (process.env.NODE_ENV !== "production") {
167217
upsertMockPullRequest({
168218
owner: orgSlug,
@@ -866,6 +916,24 @@ function getBaseUrl(request: NextRequest): string {
866916
return `${url.protocol}//${url.host}`
867917
}
868918

919+
function isDependabotLikePullRequest(payload: PullRequestPayload) {
920+
const authorLogin = payload.pull_request?.user?.login?.toLowerCase() ?? ""
921+
const senderLogin = payload.sender?.login?.toLowerCase() ?? ""
922+
const headRef = payload.pull_request?.head?.ref?.toLowerCase() ?? ""
923+
const authorType = payload.pull_request?.user?.type ?? ""
924+
const senderType = payload.sender?.type ?? ""
925+
926+
return (
927+
authorLogin.includes("dependabot") ||
928+
senderLogin.includes("dependabot") ||
929+
headRef.startsWith("dependabot/") ||
930+
authorType === "Bot" ||
931+
senderType === "Bot" ||
932+
authorLogin.endsWith("[bot]") ||
933+
senderLogin.endsWith("[bot]")
934+
)
935+
}
936+
869937
function generateUnconfiguredClaComment(params: {
870938
prAuthor: string
871939
orgName: string

0 commit comments

Comments
 (0)