@vercel/factory 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,6 +44,24 @@ interface GitHubPullRequestHead {
44
44
  sha: string;
45
45
  repository: string;
46
46
  }
47
+ type PullRequestReviewEvent = "APPROVE" | "REQUEST_CHANGES" | "COMMENT";
48
+ interface PullRequestReviewComment {
49
+ path: string;
50
+ line: number;
51
+ body: string;
52
+ }
53
+ interface SubmitPullRequestReviewInput extends GitHubRepositoryRequest {
54
+ pullRequestNumber: number;
55
+ commitId: string;
56
+ event: PullRequestReviewEvent;
57
+ body: string;
58
+ comments?: readonly PullRequestReviewComment[];
59
+ }
60
+ interface SubmittedPullRequestReview {
61
+ id: number;
62
+ url: string;
63
+ state: string;
64
+ }
47
65
  interface PullRequestLabelInput extends GitHubRepositoryRequest {
48
66
  pullRequestNumber: number;
49
67
  label: string;
@@ -57,16 +75,78 @@ interface ConflictedPullRequest {
57
75
  baseSha: string;
58
76
  }
59
77
  type ListConflictedPullRequestsInput = GitHubRepositoryRequest;
78
+ type CheckRunStatus = "queued" | "in_progress" | "completed";
79
+ type GitHubCheckRunStatus = CheckRunStatus | "waiting" | "requested" | "pending";
80
+ type CheckRunConclusion = "action_required" | "cancelled" | "failure" | "neutral" | "skipped" | "success" | "timed_out";
81
+ type CheckRunAnnotationLevel = "notice" | "warning" | "failure";
82
+ interface CheckRunAnnotation {
83
+ path: string;
84
+ startLine: number;
85
+ endLine?: number;
86
+ startColumn?: number;
87
+ endColumn?: number;
88
+ annotationLevel: CheckRunAnnotationLevel;
89
+ message: string;
90
+ title?: string;
91
+ rawDetails?: string;
92
+ }
93
+ interface CheckRunOutput {
94
+ title: string;
95
+ summary: string;
96
+ text?: string;
97
+ annotations?: readonly CheckRunAnnotation[];
98
+ }
99
+ interface CheckRunFields {
100
+ status?: CheckRunStatus;
101
+ conclusion?: CheckRunConclusion;
102
+ detailsUrl?: string;
103
+ externalId?: string;
104
+ startedAt?: string;
105
+ completedAt?: string;
106
+ output?: CheckRunOutput;
107
+ }
108
+ interface CreateCheckRunInput extends GitHubRepositoryRequest, CheckRunFields {
109
+ name: string;
110
+ headSha: string;
111
+ }
112
+ interface UpdateCheckRunInput extends GitHubRepositoryRequest, CheckRunFields {
113
+ checkRunId: number;
114
+ name?: string;
115
+ }
116
+ interface ListCheckRunsForRefInput extends GitHubRepositoryRequest {
117
+ ref: string;
118
+ checkName?: string;
119
+ }
120
+ interface GitHubCheckRun {
121
+ id: number;
122
+ name: string;
123
+ headSha: string;
124
+ status: GitHubCheckRunStatus;
125
+ conclusion: CheckRunConclusion | "stale" | "startup_failure" | null;
126
+ url: string | null;
127
+ detailsUrl: string | null;
128
+ externalId: string | null;
129
+ startedAt: string | null;
130
+ completedAt: string | null;
131
+ }
60
132
  declare class GitHubReviewCommentAuthorError extends Error {
61
133
  readonly author: string;
62
134
  constructor(author: string);
63
135
  }
64
136
  /** Create a pull request from an existing head branch. */
65
137
  declare function createPullRequest(input: CreatePullRequestInput): Promise<CreatedPullRequest>;
138
+ /** Create a check run for one commit. Requires a GitHub App token with checks:write. */
139
+ declare function createCheckRun(input: CreateCheckRunInput): Promise<GitHubCheckRun>;
140
+ /** Update a check run previously created by the authenticated GitHub App. */
141
+ declare function updateCheckRun(input: UpdateCheckRunInput): Promise<GitHubCheckRun>;
142
+ /** List check runs reported for a commit, branch, or tag. */
143
+ declare function listCheckRunsForRef(input: ListCheckRunsForRefInput): Promise<GitHubCheckRun[]>;
66
144
  /** Read one inline review comment after applying the author policy, which requires write access by default. */
67
145
  declare function readReviewComment(input: ReadReviewCommentInput): Promise<GitHubReviewComment>;
68
146
  /** Reply to an inline review comment after applying the author policy, which requires write access by default. */
69
147
  declare function answerReviewComment(input: AnswerReviewCommentInput): Promise<GitHubReviewComment>;
148
+ /** Submit a summary and optional inline comments against a reviewed pull request commit. */
149
+ declare function submitPullRequestReview(input: SubmitPullRequestReviewInput): Promise<SubmittedPullRequestReview>;
70
150
  /** Read the current head branch and commit of a pull request. */
71
151
  declare function readPullRequestHead(input: ReadPullRequestHeadInput): Promise<GitHubPullRequestHead>;
72
152
  /** List open, same-repository pull requests by one author that GitHub reports as conflicting. */
@@ -97,6 +177,23 @@ declare function normalizeGitHubDefaultBranchPush(options: {
97
177
  event: string;
98
178
  payload: unknown;
99
179
  }): GitHubDefaultBranchPush | null;
180
+ interface GitHubPullRequestSignal extends NormalizedSignal<"github_pr"> {
181
+ repositorySlug: string;
182
+ pullRequest: {
183
+ number: number;
184
+ url: string;
185
+ author: string;
186
+ draft: boolean;
187
+ headSha: string;
188
+ headBranch: string;
189
+ headRepositorySlug: string;
190
+ baseSha: string;
191
+ baseBranch: string;
192
+ sender: string;
193
+ };
194
+ }
195
+ /** Normalize a newly reviewable or updated pull request into a factory signal. */
196
+ declare function normalizeGitHubPullRequest(options: WebhookEvent): GitHubPullRequestSignal | null;
100
197
  interface GitHubIssueSignal extends NormalizedSignal<"github_issue"> {
101
198
  repositorySlug: string;
102
199
  issue: {
@@ -147,5 +244,5 @@ declare function normalizeGitHubPullRequestClosed(options: WebhookEvent): GitHub
147
244
  /** Normalize a completed, unsuccessful GitHub Actions run into a CI failure signal. */
148
245
  declare function normalizeGitHubWorkflowRunFailure(options: WebhookEvent): GitHubCIFailureSignal | null;
149
246
  //#endregion
150
- export { normalizeGitHubIssueOpened as C, readReviewComment as D, readPullRequestHead as E, removeLabel as O, normalizeGitHubDefaultBranchPush as S, normalizeGitHubWorkflowRunFailure as T, ReviewCommentAuthorPolicy as _, GitHubCIFailureSignal as a, createPullRequest as b, GitHubPullRequestClosed as c, GitHubReviewComment as d, GitHubReviewCommentAuthorError as f, ReadReviewCommentInput as g, ReadPullRequestHeadInput as h, CreatedPullRequest as i, verifyGitHubSignature as k, GitHubPullRequestHead as l, PullRequestLabelInput as m, ConflictedPullRequest as n, GitHubDefaultBranchPush as o, ListConflictedPullRequestsInput as p, CreatePullRequestInput as r, GitHubIssueSignal as s, AnswerReviewCommentInput as t, GitHubRepositoryRequest as u, addLabel as v, normalizeGitHubPullRequestClosed as w, listConflictedPullRequests as x, answerReviewComment as y };
151
- //# sourceMappingURL=github-DMOypeIu.d.mts.map
247
+ export { SubmitPullRequestReviewInput as A, normalizeGitHubIssueOpened as B, ListConflictedPullRequestsInput as C, ReadPullRequestHeadInput as D, PullRequestReviewEvent as E, createCheckRun as F, readReviewComment as G, normalizeGitHubPullRequestClosed as H, createPullRequest as I, updateCheckRun as J, removeLabel as K, listCheckRunsForRef as L, UpdateCheckRunInput as M, addLabel as N, ReadReviewCommentInput as O, answerReviewComment as P, listConflictedPullRequests as R, ListCheckRunsForRefInput as S, PullRequestReviewComment as T, normalizeGitHubWorkflowRunFailure as U, normalizeGitHubPullRequest as V, readPullRequestHead as W, verifyGitHubSignature as Y, GitHubPullRequestHead as _, CheckRunOutput as a, GitHubReviewComment as b, CreateCheckRunInput as c, GitHubCIFailureSignal as d, GitHubCheckRun as f, GitHubPullRequestClosed as g, GitHubIssueSignal as h, CheckRunConclusion as i, SubmittedPullRequestReview as j, ReviewCommentAuthorPolicy as k, CreatePullRequestInput as l, GitHubDefaultBranchPush as m, CheckRunAnnotation as n, CheckRunStatus as o, GitHubCheckRunStatus as p, submitPullRequestReview as q, CheckRunAnnotationLevel as r, ConflictedPullRequest as s, AnswerReviewCommentInput as t, CreatedPullRequest as u, GitHubPullRequestSignal as v, PullRequestLabelInput as w, GitHubReviewCommentAuthorError as x, GitHubRepositoryRequest as y, normalizeGitHubDefaultBranchPush as z };
248
+ //# sourceMappingURL=github-wThBfbm-.d.mts.map
package/dist/github.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as normalizeGitHubIssueOpened, D as readReviewComment, E as readPullRequestHead, O as removeLabel, S as normalizeGitHubDefaultBranchPush, T as normalizeGitHubWorkflowRunFailure, _ as ReviewCommentAuthorPolicy, a as GitHubCIFailureSignal, b as createPullRequest, c as GitHubPullRequestClosed, d as GitHubReviewComment, f as GitHubReviewCommentAuthorError, g as ReadReviewCommentInput, h as ReadPullRequestHeadInput, i as CreatedPullRequest, k as verifyGitHubSignature, l as GitHubPullRequestHead, m as PullRequestLabelInput, n as ConflictedPullRequest, o as GitHubDefaultBranchPush, p as ListConflictedPullRequestsInput, r as CreatePullRequestInput, s as GitHubIssueSignal, t as AnswerReviewCommentInput, u as GitHubRepositoryRequest, v as addLabel, w as normalizeGitHubPullRequestClosed, x as listConflictedPullRequests, y as answerReviewComment } from "./github-DMOypeIu.mjs";
2
- export { AnswerReviewCommentInput, ConflictedPullRequest, CreatePullRequestInput, CreatedPullRequest, GitHubCIFailureSignal, GitHubDefaultBranchPush, GitHubIssueSignal, GitHubPullRequestClosed, GitHubPullRequestHead, GitHubRepositoryRequest, GitHubReviewComment, GitHubReviewCommentAuthorError, ListConflictedPullRequestsInput, PullRequestLabelInput, ReadPullRequestHeadInput, ReadReviewCommentInput, ReviewCommentAuthorPolicy, addLabel, answerReviewComment, createPullRequest, listConflictedPullRequests, normalizeGitHubDefaultBranchPush, normalizeGitHubIssueOpened, normalizeGitHubPullRequestClosed, normalizeGitHubWorkflowRunFailure, readPullRequestHead, readReviewComment, removeLabel, verifyGitHubSignature };
1
+ import { A as SubmitPullRequestReviewInput, B as normalizeGitHubIssueOpened, C as ListConflictedPullRequestsInput, D as ReadPullRequestHeadInput, E as PullRequestReviewEvent, F as createCheckRun, G as readReviewComment, H as normalizeGitHubPullRequestClosed, I as createPullRequest, J as updateCheckRun, K as removeLabel, L as listCheckRunsForRef, M as UpdateCheckRunInput, N as addLabel, O as ReadReviewCommentInput, P as answerReviewComment, R as listConflictedPullRequests, S as ListCheckRunsForRefInput, T as PullRequestReviewComment, U as normalizeGitHubWorkflowRunFailure, V as normalizeGitHubPullRequest, W as readPullRequestHead, Y as verifyGitHubSignature, _ as GitHubPullRequestHead, a as CheckRunOutput, b as GitHubReviewComment, c as CreateCheckRunInput, d as GitHubCIFailureSignal, f as GitHubCheckRun, g as GitHubPullRequestClosed, h as GitHubIssueSignal, i as CheckRunConclusion, j as SubmittedPullRequestReview, k as ReviewCommentAuthorPolicy, l as CreatePullRequestInput, m as GitHubDefaultBranchPush, n as CheckRunAnnotation, o as CheckRunStatus, p as GitHubCheckRunStatus, q as submitPullRequestReview, r as CheckRunAnnotationLevel, s as ConflictedPullRequest, t as AnswerReviewCommentInput, u as CreatedPullRequest, v as GitHubPullRequestSignal, w as PullRequestLabelInput, x as GitHubReviewCommentAuthorError, y as GitHubRepositoryRequest, z as normalizeGitHubDefaultBranchPush } from "./github-wThBfbm-.mjs";
2
+ export { AnswerReviewCommentInput, CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, ConflictedPullRequest, CreateCheckRunInput, CreatePullRequestInput, CreatedPullRequest, GitHubCIFailureSignal, GitHubCheckRun, GitHubCheckRunStatus, GitHubDefaultBranchPush, GitHubIssueSignal, GitHubPullRequestClosed, GitHubPullRequestHead, GitHubPullRequestSignal, GitHubRepositoryRequest, GitHubReviewComment, GitHubReviewCommentAuthorError, ListCheckRunsForRefInput, ListConflictedPullRequestsInput, PullRequestLabelInput, PullRequestReviewComment, PullRequestReviewEvent, ReadPullRequestHeadInput, ReadReviewCommentInput, ReviewCommentAuthorPolicy, SubmitPullRequestReviewInput, SubmittedPullRequestReview, UpdateCheckRunInput, addLabel, answerReviewComment, createCheckRun, createPullRequest, listCheckRunsForRef, listConflictedPullRequests, normalizeGitHubDefaultBranchPush, normalizeGitHubIssueOpened, normalizeGitHubPullRequest, normalizeGitHubPullRequestClosed, normalizeGitHubWorkflowRunFailure, readPullRequestHead, readReviewComment, removeLabel, submitPullRequestReview, updateCheckRun, verifyGitHubSignature };
package/dist/github.mjs CHANGED
@@ -19,6 +19,41 @@ const reviewCommentSchema = z.object({
19
19
  user: z.object({ login: z.string().min(1) }),
20
20
  in_reply_to_id: z.number().int().positive().nullish()
21
21
  });
22
+ const submittedReviewSchema = z.object({
23
+ id: z.number().int().positive(),
24
+ html_url: z.url(),
25
+ state: z.string().min(1)
26
+ });
27
+ const checkRunSchema = z.object({
28
+ id: z.number().int().positive(),
29
+ name: z.string().min(1),
30
+ head_sha: z.string().regex(/^[0-9a-f]{40}$/),
31
+ status: z.enum([
32
+ "queued",
33
+ "in_progress",
34
+ "completed",
35
+ "waiting",
36
+ "requested",
37
+ "pending"
38
+ ]),
39
+ conclusion: z.enum([
40
+ "action_required",
41
+ "cancelled",
42
+ "failure",
43
+ "neutral",
44
+ "skipped",
45
+ "success",
46
+ "timed_out",
47
+ "stale",
48
+ "startup_failure"
49
+ ]).nullable(),
50
+ html_url: z.url().nullable(),
51
+ details_url: z.url().nullable(),
52
+ external_id: z.string().nullable(),
53
+ started_at: z.string().nullable(),
54
+ completed_at: z.string().nullable()
55
+ });
56
+ const checkRunsSchema = z.object({ check_runs: z.array(checkRunSchema) });
22
57
  const labelsSchema = z.array(z.object({ name: z.string().min(1) }));
23
58
  const pullRequestCandidateSchema = z.object({
24
59
  number: z.number().int().positive(),
@@ -77,6 +112,36 @@ async function createPullRequest(input) {
77
112
  prUrl: pull.html_url
78
113
  };
79
114
  }
115
+ /** Create a check run for one commit. Requires a GitHub App token with checks:write. */
116
+ async function createCheckRun(input) {
117
+ if (input.status === "completed" && input.conclusion === void 0) throw new Error("completed check runs require a conclusion");
118
+ if (input.status !== "completed" && input.conclusion !== void 0) throw new Error("creating a check run with a conclusion requires completed status");
119
+ return parseCheckRun(await gitHubRequest(input, "/check-runs", {
120
+ method: "POST",
121
+ body: JSON.stringify({
122
+ name: input.name,
123
+ head_sha: commitSha(input.headSha),
124
+ ...checkRunFields(input)
125
+ })
126
+ }));
127
+ }
128
+ /** Update a check run previously created by the authenticated GitHub App. */
129
+ async function updateCheckRun(input) {
130
+ if (input.status !== void 0 && input.status !== "completed" && input.conclusion !== void 0) throw new Error("a check run conclusion conflicts with an incomplete status");
131
+ return parseCheckRun(await gitHubRequest(input, `/check-runs/${positiveInteger(input.checkRunId, "checkRunId")}`, {
132
+ method: "PATCH",
133
+ body: JSON.stringify({
134
+ ...input.name === void 0 ? {} : { name: input.name },
135
+ ...checkRunFields(input)
136
+ })
137
+ }));
138
+ }
139
+ /** List check runs reported for a commit, branch, or tag. */
140
+ async function listCheckRunsForRef(input) {
141
+ const query = new URLSearchParams({ per_page: "100" });
142
+ if (input.checkName !== void 0) query.set("check_name", input.checkName);
143
+ return checkRunsSchema.parse(await gitHubRequest(input, `/commits/${encodeURIComponent(input.ref)}/check-runs?${query.toString()}`)).check_runs.map(parseCheckRun);
144
+ }
80
145
  /** Read one inline review comment after applying the author policy, which requires write access by default. */
81
146
  async function readReviewComment(input) {
82
147
  const comment = parseReviewComment(await gitHubRequest(input, `/pulls/comments/${positiveInteger(input.commentId, "commentId")}`));
@@ -91,6 +156,31 @@ async function answerReviewComment(input) {
91
156
  body: JSON.stringify({ body: input.body })
92
157
  }));
93
158
  }
159
+ /** Submit a summary and optional inline comments against a reviewed pull request commit. */
160
+ async function submitPullRequestReview(input) {
161
+ const commitId = z.string().regex(/^[0-9a-f]{40}$/).parse(input.commitId);
162
+ const head = await readPullRequestHead(input);
163
+ if (head.sha !== commitId) throw new Error(`pull request changed after review: expected ${commitId}, found ${head.sha}`);
164
+ const review = submittedReviewSchema.parse(await gitHubRequest(input, `/pulls/${positiveInteger(input.pullRequestNumber, "pullRequestNumber")}/reviews`, {
165
+ method: "POST",
166
+ body: JSON.stringify({
167
+ commit_id: commitId,
168
+ event: input.event,
169
+ body: input.body,
170
+ comments: (input.comments ?? []).map((comment) => ({
171
+ path: comment.path,
172
+ line: positiveInteger(comment.line, "comment line"),
173
+ side: "RIGHT",
174
+ body: comment.body
175
+ }))
176
+ })
177
+ }));
178
+ return {
179
+ id: review.id,
180
+ url: review.html_url,
181
+ state: review.state
182
+ };
183
+ }
94
184
  /** Read the current head branch and commit of a pull request. */
95
185
  async function readPullRequestHead(input) {
96
186
  const pull = pullRequestHeadSchema.parse(await gitHubRequest(input, `/pulls/${positiveInteger(input.pullRequestNumber, "pullRequestNumber")}`));
@@ -160,6 +250,50 @@ function parseReviewComment(value) {
160
250
  function parseLabels(value) {
161
251
  return labelsSchema.parse(value).map(({ name }) => name);
162
252
  }
253
+ function parseCheckRun(value) {
254
+ const checkRun = checkRunSchema.parse(value);
255
+ return {
256
+ id: checkRun.id,
257
+ name: checkRun.name,
258
+ headSha: checkRun.head_sha,
259
+ status: checkRun.status,
260
+ conclusion: checkRun.conclusion,
261
+ url: checkRun.html_url,
262
+ detailsUrl: checkRun.details_url,
263
+ externalId: checkRun.external_id,
264
+ startedAt: checkRun.started_at,
265
+ completedAt: checkRun.completed_at
266
+ };
267
+ }
268
+ function checkRunFields(input) {
269
+ return {
270
+ ...input.status === void 0 ? {} : { status: input.status },
271
+ ...input.conclusion === void 0 ? {} : { conclusion: input.conclusion },
272
+ ...input.detailsUrl === void 0 ? {} : { details_url: input.detailsUrl },
273
+ ...input.externalId === void 0 ? {} : { external_id: input.externalId },
274
+ ...input.startedAt === void 0 ? {} : { started_at: input.startedAt },
275
+ ...input.completedAt === void 0 ? {} : { completed_at: input.completedAt },
276
+ ...input.output === void 0 ? {} : { output: checkRunOutput(input.output) }
277
+ };
278
+ }
279
+ function checkRunOutput(output) {
280
+ return {
281
+ title: output.title,
282
+ summary: output.summary,
283
+ ...output.text === void 0 ? {} : { text: output.text },
284
+ ...output.annotations === void 0 ? {} : { annotations: output.annotations.map((annotation) => ({
285
+ path: annotation.path,
286
+ start_line: positiveInteger(annotation.startLine, "annotation startLine"),
287
+ end_line: positiveInteger(annotation.endLine ?? annotation.startLine, "annotation endLine"),
288
+ ...annotation.startColumn === void 0 ? {} : { start_column: positiveInteger(annotation.startColumn, "annotation startColumn") },
289
+ ...annotation.endColumn === void 0 ? {} : { end_column: positiveInteger(annotation.endColumn, "annotation endColumn") },
290
+ annotation_level: annotation.annotationLevel,
291
+ message: annotation.message,
292
+ ...annotation.title === void 0 ? {} : { title: annotation.title },
293
+ ...annotation.rawDetails === void 0 ? {} : { raw_details: annotation.rawDetails }
294
+ })) }
295
+ };
296
+ }
163
297
  async function assertReviewCommentAuthor(input, author) {
164
298
  if (input.authorPolicy === "any") return;
165
299
  const { permission } = collaboratorPermissionSchema.parse(await gitHubRequest(input, `/collaborators/${encodeURIComponent(author)}/permission`));
@@ -169,6 +303,9 @@ function positiveInteger(value, name) {
169
303
  if (!Number.isInteger(value) || value < 1) throw new Error(`${name} must be a positive integer`);
170
304
  return value;
171
305
  }
306
+ function commitSha(value) {
307
+ return z.string().regex(/^[0-9a-f]{40}$/).parse(value);
308
+ }
172
309
  /**
173
310
  * Verify a GitHub webhook HMAC signature (the x-hub-signature-256 header)
174
311
  * against the raw request body. Returns false for missing or malformed
@@ -201,6 +338,63 @@ function normalizeGitHubDefaultBranchPush(options) {
201
338
  defaultBranch: parsed.data.repository.default_branch
202
339
  };
203
340
  }
341
+ const pullRequestEventSchema = z.looseObject({
342
+ action: z.string(),
343
+ number: z.number().int().positive(),
344
+ pull_request: z.looseObject({
345
+ html_url: z.url(),
346
+ draft: z.boolean(),
347
+ user: z.looseObject({ login: z.string().min(1) }),
348
+ head: z.looseObject({
349
+ sha: z.string().regex(/^[0-9a-f]{40}$/),
350
+ ref: z.string().min(1),
351
+ repo: z.looseObject({ full_name: z.string().min(1) })
352
+ }),
353
+ base: z.looseObject({
354
+ sha: z.string().regex(/^[0-9a-f]{40}$/),
355
+ ref: z.string().min(1)
356
+ })
357
+ }),
358
+ repository: z.looseObject({ full_name: z.string().min(1) }),
359
+ sender: z.looseObject({ login: z.string().min(1) })
360
+ });
361
+ const reviewablePullRequestActions = /* @__PURE__ */ new Set([
362
+ "opened",
363
+ "reopened",
364
+ "ready_for_review",
365
+ "synchronize"
366
+ ]);
367
+ /** Normalize a newly reviewable or updated pull request into a factory signal. */
368
+ function normalizeGitHubPullRequest(options) {
369
+ if (options.event !== "pull_request") return null;
370
+ const parsed = pullRequestEventSchema.safeParse(options.payload);
371
+ if (!parsed.success || !reviewablePullRequestActions.has(parsed.data.action)) return null;
372
+ if (parsed.data.pull_request.draft && parsed.data.action !== "ready_for_review") return null;
373
+ const slug = parsed.data.repository.full_name.toLowerCase();
374
+ const pull = parsed.data.pull_request;
375
+ return {
376
+ source: "github_pr",
377
+ deliveryId: options.deliveryId,
378
+ repositorySlug: slug,
379
+ replyTo: {
380
+ channel: "github",
381
+ address: `${slug}/pull/${parsed.data.number}`
382
+ },
383
+ pullRequest: {
384
+ number: parsed.data.number,
385
+ url: pull.html_url,
386
+ author: pull.user.login,
387
+ draft: pull.draft,
388
+ headSha: pull.head.sha,
389
+ headBranch: pull.head.ref,
390
+ headRepositorySlug: pull.head.repo.full_name.toLowerCase(),
391
+ baseSha: pull.base.sha,
392
+ baseBranch: pull.base.ref,
393
+ sender: parsed.data.sender.login
394
+ },
395
+ payload: options.payload
396
+ };
397
+ }
204
398
  const issueEventSchema = z.looseObject({
205
399
  action: z.string(),
206
400
  issue: z.looseObject({
@@ -329,6 +523,6 @@ function normalizeGitHubWorkflowRunFailure(options) {
329
523
  };
330
524
  }
331
525
  //#endregion
332
- export { GitHubReviewCommentAuthorError, addLabel, answerReviewComment, createPullRequest, listConflictedPullRequests, normalizeGitHubDefaultBranchPush, normalizeGitHubIssueOpened, normalizeGitHubPullRequestClosed, normalizeGitHubWorkflowRunFailure, readPullRequestHead, readReviewComment, removeLabel, verifyGitHubSignature };
526
+ export { GitHubReviewCommentAuthorError, addLabel, answerReviewComment, createCheckRun, createPullRequest, listCheckRunsForRef, listConflictedPullRequests, normalizeGitHubDefaultBranchPush, normalizeGitHubIssueOpened, normalizeGitHubPullRequest, normalizeGitHubPullRequestClosed, normalizeGitHubWorkflowRunFailure, readPullRequestHead, readReviewComment, removeLabel, submitPullRequestReview, updateCheckRun, verifyGitHubSignature };
333
527
 
334
528
  //# sourceMappingURL=github.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"github.mjs","names":[],"sources":["../src/github.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport { z } from \"zod\";\nimport type { NormalizedSignal, WebhookEvent } from \"./connectors/index\";\n\nconst gitHubApiUrl = \"https://api.github.com\";\nconst repositorySlugPattern = /^[^/\\s]+\\/[^/\\s]+$/;\n\nexport interface GitHubRepositoryRequest {\n repository: string;\n token: string;\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface CreatePullRequestInput extends GitHubRepositoryRequest {\n title: string;\n head: string;\n base: string;\n body?: string;\n draft?: boolean;\n}\n\nexport interface CreatedPullRequest {\n prNumber: number;\n prUrl: string;\n}\n\nexport type ReviewCommentAuthorPolicy = \"write\" | \"any\";\n\ninterface ReviewCommentTrustInput {\n /** Defaults to `write`. Use `any` only when untrusted review text is handled as data. */\n authorPolicy?: ReviewCommentAuthorPolicy;\n}\n\nexport interface ReadReviewCommentInput extends GitHubRepositoryRequest, ReviewCommentTrustInput {\n commentId: number;\n}\n\nexport interface GitHubReviewComment {\n id: number;\n body: string;\n url: string;\n author: string;\n inReplyToId: number | null;\n}\n\nexport interface AnswerReviewCommentInput\n extends GitHubRepositoryRequest,\n ReviewCommentTrustInput {\n pullRequestNumber: number;\n commentId: number;\n body: string;\n}\n\nexport interface ReadPullRequestHeadInput extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n}\n\nexport interface GitHubPullRequestHead {\n branch: string;\n sha: string;\n repository: string;\n}\n\nexport interface PullRequestLabelInput extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n label: string;\n}\n\nexport interface ConflictedPullRequest {\n prNumber: number;\n prUrl: string;\n headBranch: string;\n headSha: string;\n baseBranch: string;\n baseSha: string;\n}\n\nexport type ListConflictedPullRequestsInput = GitHubRepositoryRequest;\n\nconst pullRequestSchema = z.object({\n number: z.number().int().positive(),\n html_url: z.url(),\n});\n\nconst pullRequestHeadSchema = z.object({\n head: z.object({\n ref: z\n .string()\n .regex(/^[A-Za-z0-9][A-Za-z0-9._/-]*$/)\n .refine((value) => !value.includes(\"..\")),\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n repo: z.object({ full_name: z.string().min(1) }),\n }),\n});\n\nconst reviewCommentSchema = z.object({\n id: z.number().int().positive(),\n body: z.string(),\n html_url: z.url(),\n user: z.object({ login: z.string().min(1) }),\n in_reply_to_id: z.number().int().positive().nullish(),\n});\n\nconst labelsSchema = z.array(z.object({ name: z.string().min(1) }));\nconst pullRequestCandidateSchema = z.object({\n number: z.number().int().positive(),\n user: z.object({ type: z.string().min(1) }),\n head: z.object({ ref: z.string().min(1), repo: z.object({ full_name: z.string().min(1) }) }),\n});\nconst openPullRequestsSchema = z.array(pullRequestCandidateSchema);\nconst pullRequestDetailSchema = pullRequestCandidateSchema.extend({\n html_url: z.url(),\n mergeable: z.boolean().nullable(),\n mergeable_state: z.string().min(1),\n head: pullRequestCandidateSchema.shape.head.extend({ sha: z.string().min(1) }),\n base: z.object({ ref: z.string().min(1), sha: z.string().min(1) }),\n});\nconst collaboratorPermissionSchema = z.object({\n permission: z.enum([\"admin\", \"maintain\", \"write\", \"triage\", \"read\", \"none\"]),\n});\nconst writePermissions = new Set([\"admin\", \"maintain\", \"write\"]);\n\nexport class GitHubReviewCommentAuthorError extends Error {\n readonly author: string;\n\n constructor(author: string) {\n super(`GitHub user ${author} does not have write access to the repository`);\n this.name = \"GitHubReviewCommentAuthorError\";\n this.author = author;\n }\n}\n\n/** Create a pull request from an existing head branch. */\nexport async function createPullRequest(input: CreatePullRequestInput): Promise<CreatedPullRequest> {\n const pull = pullRequestSchema.parse(\n await gitHubRequest(input, \"/pulls\", {\n method: \"POST\",\n body: JSON.stringify({\n title: input.title,\n head: input.head,\n base: input.base,\n ...(input.body === undefined ? {} : { body: input.body }),\n ...(input.draft === undefined ? {} : { draft: input.draft }),\n }),\n }),\n );\n return { prNumber: pull.number, prUrl: pull.html_url };\n}\n\n/** Read one inline review comment after applying the author policy, which requires write access by default. */\nexport async function readReviewComment(\n input: ReadReviewCommentInput,\n): Promise<GitHubReviewComment> {\n const comment = parseReviewComment(\n await gitHubRequest(input, `/pulls/comments/${positiveInteger(input.commentId, \"commentId\")}`),\n );\n await assertReviewCommentAuthor(input, comment.author);\n return comment;\n}\n\n/** Reply to an inline review comment after applying the author policy, which requires write access by default. */\nexport async function answerReviewComment(\n input: AnswerReviewCommentInput,\n): Promise<GitHubReviewComment> {\n await readReviewComment(input);\n return parseReviewComment(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/comments/${positiveInteger(input.commentId, \"commentId\")}/replies`,\n { method: \"POST\", body: JSON.stringify({ body: input.body }) },\n ),\n );\n}\n\n/** Read the current head branch and commit of a pull request. */\nexport async function readPullRequestHead(\n input: ReadPullRequestHeadInput,\n): Promise<GitHubPullRequestHead> {\n const pull = pullRequestHeadSchema.parse(\n await gitHubRequest(input, `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}`),\n );\n return {\n branch: pull.head.ref,\n sha: pull.head.sha,\n repository: pull.head.repo.full_name.toLowerCase(),\n };\n}\n\n/** List open, same-repository pull requests by one author that GitHub reports as conflicting. */\nexport async function listConflictedPullRequests(\n input: ListConflictedPullRequestsInput,\n): Promise<ConflictedPullRequest[]> {\n const pulls = openPullRequestsSchema.parse(\n await gitHubRequest(input, `/pulls?state=open&per_page=100`),\n );\n const candidates = pulls.filter(\n (pull) =>\n pull.user.type === \"Bot\" &&\n pull.head.ref.startsWith(\"factory/\") &&\n pull.head.repo.full_name.toLowerCase() === input.repository.toLowerCase(),\n );\n const conflicted: ConflictedPullRequest[] = [];\n for (const candidate of candidates) {\n const pull = pullRequestDetailSchema.parse(\n await gitHubRequest(input, `/pulls/${candidate.number}`),\n );\n if (pull.mergeable === false || pull.mergeable_state === \"dirty\") {\n conflicted.push({\n prNumber: pull.number,\n prUrl: pull.html_url,\n headBranch: pull.head.ref,\n headSha: pull.head.sha,\n baseBranch: pull.base.ref,\n baseSha: pull.base.sha,\n });\n }\n }\n return conflicted;\n}\n\n/** Add one label to a pull request. */\nexport async function addLabel(input: PullRequestLabelInput): Promise<string[]> {\n return parseLabels(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/labels`,\n { method: \"POST\", body: JSON.stringify({ labels: [input.label] }) },\n ),\n );\n}\n\n/** Remove one label from a pull request. */\nexport async function removeLabel(input: PullRequestLabelInput): Promise<string[]> {\n return parseLabels(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/labels/${encodeURIComponent(input.label)}`,\n { method: \"DELETE\" },\n ),\n );\n}\n\nasync function gitHubRequest(\n input: GitHubRepositoryRequest,\n path: string,\n init: RequestInit = {},\n): Promise<unknown> {\n if (!repositorySlugPattern.test(input.repository)) {\n throw new Error(`invalid GitHub repository slug: ${input.repository}`);\n }\n const response = await (input.fetch ?? globalThis.fetch)(\n `${gitHubApiUrl}/repos/${input.repository}${path}`,\n {\n ...init,\n headers: {\n Accept: \"application/vnd.github+json\",\n Authorization: `Bearer ${input.token}`,\n \"Content-Type\": \"application/json\",\n \"X-GitHub-Api-Version\": \"2022-11-28\",\n ...init.headers,\n },\n },\n );\n const body: unknown = await response.json();\n if (!response.ok) {\n const message = z.object({ message: z.string() }).safeParse(body);\n throw new Error(\n `GitHub API request failed (${response.status}): ${message.success ? message.data.message : response.statusText}`,\n );\n }\n return body;\n}\n\nfunction parseReviewComment(value: unknown): GitHubReviewComment {\n const comment = reviewCommentSchema.parse(value);\n return {\n id: comment.id,\n body: comment.body,\n url: comment.html_url,\n author: comment.user.login,\n inReplyToId: comment.in_reply_to_id ?? null,\n };\n}\n\nfunction parseLabels(value: unknown): string[] {\n return labelsSchema.parse(value).map(({ name }) => name);\n}\n\nasync function assertReviewCommentAuthor(\n input: GitHubRepositoryRequest & ReviewCommentTrustInput,\n author: string,\n): Promise<void> {\n if (input.authorPolicy === \"any\") {\n return;\n }\n const { permission } = collaboratorPermissionSchema.parse(\n await gitHubRequest(input, `/collaborators/${encodeURIComponent(author)}/permission`),\n );\n if (!writePermissions.has(permission)) {\n throw new GitHubReviewCommentAuthorError(author);\n }\n}\n\nfunction positiveInteger(value: number, name: string): number {\n if (!Number.isInteger(value) || value < 1) {\n throw new Error(`${name} must be a positive integer`);\n }\n return value;\n}\n\n/**\n * Verify a GitHub webhook HMAC signature (the x-hub-signature-256 header)\n * against the raw request body. Returns false for missing or malformed\n * signatures instead of throwing.\n */\nexport function verifyGitHubSignature(options: {\n secret: string;\n payload: string;\n signature: string | null;\n}): boolean {\n const { secret, payload, signature } = options;\n if (signature === null || !signature.startsWith(\"sha256=\")) {\n return false;\n }\n const expected = createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n const provided = signature.slice(\"sha256=\".length);\n if (provided.length !== expected.length) {\n return false;\n }\n return timingSafeEqual(Buffer.from(provided, \"hex\"), Buffer.from(expected, \"hex\"));\n}\n\nconst pushEventSchema = z.looseObject({\n ref: z.string().min(1),\n repository: z.looseObject({\n default_branch: z.string().min(1),\n full_name: z.string().min(1),\n }),\n});\n\nexport interface GitHubDefaultBranchPush {\n source: \"github_default_branch_push\";\n deliveryId: string;\n repositorySlug: string;\n defaultBranch: string;\n}\n\n/** Normalize a push to a repository's default branch for deterministic reconciliation. */\nexport function normalizeGitHubDefaultBranchPush(options: {\n deliveryId: string;\n event: string;\n payload: unknown;\n}): GitHubDefaultBranchPush | null {\n if (options.event !== \"push\") return null;\n const parsed = pushEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.ref !== `refs/heads/${parsed.data.repository.default_branch}`) {\n return null;\n }\n return {\n source: \"github_default_branch_push\",\n deliveryId: options.deliveryId,\n repositorySlug: parsed.data.repository.full_name.toLowerCase(),\n defaultBranch: parsed.data.repository.default_branch,\n };\n}\n\nconst issueEventSchema = z.looseObject({\n action: z.string(),\n issue: z.looseObject({\n number: z.number().int().min(1),\n title: z.string(),\n body: z.string().nullable(),\n }),\n repository: z.looseObject({\n full_name: z.string().min(1),\n }),\n});\n\nexport interface GitHubIssueSignal extends NormalizedSignal<\"github_issue\"> {\n repositorySlug: string;\n issue: { number: number; title: string; body: string | null };\n}\n\nconst failedWorkflowConclusions = new Set([\n \"action_required\",\n \"failure\",\n \"stale\",\n \"startup_failure\",\n \"timed_out\",\n]);\n\nconst workflowRunEventSchema = z.looseObject({\n action: z.string(),\n repository: z.looseObject({\n default_branch: z.string().min(1),\n full_name: z.string().min(1),\n }),\n workflow_run: z.looseObject({\n id: z.number().int().min(1),\n name: z.string().min(1),\n event: z.string().min(1),\n head_branch: z.string().min(1).nullable(),\n head_repository: z\n .looseObject({\n full_name: z.string().min(1),\n })\n .nullable(),\n head_sha: z.string().min(1),\n html_url: z.url(),\n conclusion: z.string().nullable(),\n run_attempt: z.number().int().min(1),\n }),\n});\n\nexport interface GitHubCIFailureSignal extends NormalizedSignal<\"github_ci_failure\"> {\n repositoryDefaultBranch: string;\n repositorySlug: string;\n workflowRun: {\n id: number;\n name: string;\n trigger: string;\n branch: string | null;\n headRepositorySlug: string | null;\n headSha: string;\n url: string;\n conclusion: string;\n attempt: number;\n };\n}\n\n/**\n * Normalize a GitHub issues webhook into the factory's signal shape. Returns\n * null for payloads that are not an opened issue. The caller supplies the\n * repository id; the payload stays untrusted data.\n */\nexport function normalizeGitHubIssueOpened(options: WebhookEvent): GitHubIssueSignal | null {\n if (options.event !== \"issues\") {\n return null;\n }\n const parsed = issueEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"opened\") {\n return null;\n }\n const slug = parsed.data.repository.full_name.toLowerCase();\n const { number, title, body } = parsed.data.issue;\n return {\n source: \"github_issue\",\n deliveryId: options.deliveryId,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}#${number}` },\n issue: { number, title, body },\n payload: options.payload,\n };\n}\n\nconst pullRequestClosedSchema = z.looseObject({\n action: z.string(),\n pull_request: z.looseObject({\n number: z.number().int().min(1),\n html_url: z.url(),\n merged: z.boolean(),\n merged_by: z.looseObject({ login: z.string().min(1) }).nullable().optional(),\n merge_commit_sha: z\n .string()\n .regex(/^[0-9a-f]{40}$/)\n .nullable()\n .optional(),\n }),\n repository: z.looseObject({\n full_name: z.string().min(1),\n }),\n sender: z.looseObject({ login: z.string().min(1) }),\n});\n\nexport interface GitHubPullRequestClosed {\n source: \"github_pull_request_closed\";\n deliveryId: string;\n repositorySlug: string;\n prNumber: number;\n prUrl: string;\n merged: boolean;\n /** The merge commit on the base branch; null when closed without merging. */\n mergeCommitSha: string | null;\n /** The GitHub login that merged the pull request, or closed it without merging. */\n decidedBy: string;\n}\n\n/**\n * Normalize a closed pull_request webhook so the factory can observe what\n * happened to its change: merged records merged_by (the sender when GitHub\n * omits it), a close without merge records the sender.\n */\nexport function normalizeGitHubPullRequestClosed(\n options: WebhookEvent,\n): GitHubPullRequestClosed | null {\n if (options.event !== \"pull_request\") {\n return null;\n }\n const parsed = pullRequestClosedSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"closed\") {\n return null;\n }\n const pr = parsed.data.pull_request;\n const sender = parsed.data.sender.login;\n return {\n source: \"github_pull_request_closed\",\n deliveryId: options.deliveryId,\n repositorySlug: parsed.data.repository.full_name.toLowerCase(),\n prNumber: pr.number,\n prUrl: pr.html_url,\n merged: pr.merged,\n mergeCommitSha: pr.merged ? (pr.merge_commit_sha ?? null) : null,\n decidedBy: pr.merged ? (pr.merged_by?.login ?? sender) : sender,\n };\n}\n\n/** Normalize a completed, unsuccessful GitHub Actions run into a CI failure signal. */\nexport function normalizeGitHubWorkflowRunFailure(\n options: WebhookEvent,\n): GitHubCIFailureSignal | null {\n if (options.event !== \"workflow_run\") {\n return null;\n }\n const parsed = workflowRunEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"completed\") {\n return null;\n }\n\n const run = parsed.data.workflow_run;\n const conclusion = run.conclusion;\n if (conclusion === null || !failedWorkflowConclusions.has(conclusion)) {\n return null;\n }\n const slug = parsed.data.repository.full_name.toLowerCase();\n return {\n source: \"github_ci_failure\",\n deliveryId: options.deliveryId,\n repositoryDefaultBranch: parsed.data.repository.default_branch,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}/actions/runs/${run.id}` },\n workflowRun: {\n id: run.id,\n name: run.name,\n trigger: run.event,\n branch: run.head_branch,\n headRepositorySlug: run.head_repository?.full_name.toLowerCase() ?? null,\n headSha: run.head_sha,\n url: run.html_url,\n conclusion,\n attempt: run.run_attempt,\n },\n payload: options.payload,\n };\n}\n"],"mappings":";;;AAIA,MAAM,eAAe;AACrB,MAAM,wBAAwB;AA0E9B,MAAM,oBAAoB,EAAE,OAAO;CACjC,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;CAClC,UAAU,EAAE,IAAI;AAClB,CAAC;AAED,MAAM,wBAAwB,EAAE,OAAO,EACrC,MAAM,EAAE,OAAO;CACb,KAAK,EACF,OAAO,CAAC,CACR,MAAM,+BAA+B,CAAC,CACtC,QAAQ,UAAU,CAAC,MAAM,SAAS,IAAI,CAAC;CAC1C,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,gBAAgB;CACtC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AACjD,CAAC,EACH,CAAC;AAED,MAAM,sBAAsB,EAAE,OAAO;CACnC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;CAC9B,MAAM,EAAE,OAAO;CACf,UAAU,EAAE,IAAI;CAChB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;CAC3C,gBAAgB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ;AACtD,CAAC;AAED,MAAM,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAClE,MAAM,6BAA6B,EAAE,OAAO;CAC1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IAAI;GACR,MAAM,IAAI;GACV,SAAS,IAAI;GACb,QAAQ,IAAI;GACZ,oBAAoB,IAAI,iBAAiB,UAAU,YAAY,KAAK;GACpE,SAAS,IAAI;GACb,KAAK,IAAI;GACT;GACA,SAAS,IAAI;EACf;EACA,SAAS,QAAQ;CACnB;AACF"}
1
+ {"version":3,"file":"github.mjs","names":[],"sources":["../src/github.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport { z } from \"zod\";\nimport type { NormalizedSignal, WebhookEvent } from \"./connectors/index\";\n\nconst gitHubApiUrl = \"https://api.github.com\";\nconst repositorySlugPattern = /^[^/\\s]+\\/[^/\\s]+$/;\n\nexport interface GitHubRepositoryRequest {\n repository: string;\n token: string;\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface CreatePullRequestInput extends GitHubRepositoryRequest {\n title: string;\n head: string;\n base: string;\n body?: string;\n draft?: boolean;\n}\n\nexport interface CreatedPullRequest {\n prNumber: number;\n prUrl: string;\n}\n\nexport type ReviewCommentAuthorPolicy = \"write\" | \"any\";\n\ninterface ReviewCommentTrustInput {\n /** Defaults to `write`. Use `any` only when untrusted review text is handled as data. */\n authorPolicy?: ReviewCommentAuthorPolicy;\n}\n\nexport interface ReadReviewCommentInput extends GitHubRepositoryRequest, ReviewCommentTrustInput {\n commentId: number;\n}\n\nexport interface GitHubReviewComment {\n id: number;\n body: string;\n url: string;\n author: string;\n inReplyToId: number | null;\n}\n\nexport interface AnswerReviewCommentInput\n extends GitHubRepositoryRequest,\n ReviewCommentTrustInput {\n pullRequestNumber: number;\n commentId: number;\n body: string;\n}\n\nexport interface ReadPullRequestHeadInput extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n}\n\nexport interface GitHubPullRequestHead {\n branch: string;\n sha: string;\n repository: string;\n}\n\nexport type PullRequestReviewEvent = \"APPROVE\" | \"REQUEST_CHANGES\" | \"COMMENT\";\n\nexport interface PullRequestReviewComment {\n path: string;\n line: number;\n body: string;\n}\n\nexport interface SubmitPullRequestReviewInput extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n commitId: string;\n event: PullRequestReviewEvent;\n body: string;\n comments?: readonly PullRequestReviewComment[];\n}\n\nexport interface SubmittedPullRequestReview {\n id: number;\n url: string;\n state: string;\n}\n\nexport interface PullRequestLabelInput extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n label: string;\n}\n\nexport interface ConflictedPullRequest {\n prNumber: number;\n prUrl: string;\n headBranch: string;\n headSha: string;\n baseBranch: string;\n baseSha: string;\n}\n\nexport type ListConflictedPullRequestsInput = GitHubRepositoryRequest;\n\nexport type CheckRunStatus = \"queued\" | \"in_progress\" | \"completed\";\nexport type GitHubCheckRunStatus = CheckRunStatus | \"waiting\" | \"requested\" | \"pending\";\nexport type CheckRunConclusion =\n | \"action_required\"\n | \"cancelled\"\n | \"failure\"\n | \"neutral\"\n | \"skipped\"\n | \"success\"\n | \"timed_out\";\nexport type CheckRunAnnotationLevel = \"notice\" | \"warning\" | \"failure\";\n\nexport interface CheckRunAnnotation {\n path: string;\n startLine: number;\n endLine?: number;\n startColumn?: number;\n endColumn?: number;\n annotationLevel: CheckRunAnnotationLevel;\n message: string;\n title?: string;\n rawDetails?: string;\n}\n\nexport interface CheckRunOutput {\n title: string;\n summary: string;\n text?: string;\n annotations?: readonly CheckRunAnnotation[];\n}\n\ninterface CheckRunFields {\n status?: CheckRunStatus;\n conclusion?: CheckRunConclusion;\n detailsUrl?: string;\n externalId?: string;\n startedAt?: string;\n completedAt?: string;\n output?: CheckRunOutput;\n}\n\nexport interface CreateCheckRunInput extends GitHubRepositoryRequest, CheckRunFields {\n name: string;\n headSha: string;\n}\n\nexport interface UpdateCheckRunInput extends GitHubRepositoryRequest, CheckRunFields {\n checkRunId: number;\n name?: string;\n}\n\nexport interface ListCheckRunsForRefInput extends GitHubRepositoryRequest {\n ref: string;\n checkName?: string;\n}\n\nexport interface GitHubCheckRun {\n id: number;\n name: string;\n headSha: string;\n status: GitHubCheckRunStatus;\n conclusion: CheckRunConclusion | \"stale\" | \"startup_failure\" | null;\n url: string | null;\n detailsUrl: string | null;\n externalId: string | null;\n startedAt: string | null;\n completedAt: string | null;\n}\n\nconst pullRequestSchema = z.object({\n number: z.number().int().positive(),\n html_url: z.url(),\n});\n\nconst pullRequestHeadSchema = z.object({\n head: z.object({\n ref: z\n .string()\n .regex(/^[A-Za-z0-9][A-Za-z0-9._/-]*$/)\n .refine((value) => !value.includes(\"..\")),\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n repo: z.object({ full_name: z.string().min(1) }),\n }),\n});\n\nconst reviewCommentSchema = z.object({\n id: z.number().int().positive(),\n body: z.string(),\n html_url: z.url(),\n user: z.object({ login: z.string().min(1) }),\n in_reply_to_id: z.number().int().positive().nullish(),\n});\n\nconst submittedReviewSchema = z.object({\n id: z.number().int().positive(),\n html_url: z.url(),\n state: z.string().min(1),\n});\n\nconst checkRunSchema = z.object({\n id: z.number().int().positive(),\n name: z.string().min(1),\n head_sha: z.string().regex(/^[0-9a-f]{40}$/),\n status: z.enum([\"queued\", \"in_progress\", \"completed\", \"waiting\", \"requested\", \"pending\"]),\n conclusion: z\n .enum([\n \"action_required\",\n \"cancelled\",\n \"failure\",\n \"neutral\",\n \"skipped\",\n \"success\",\n \"timed_out\",\n \"stale\",\n \"startup_failure\",\n ])\n .nullable(),\n html_url: z.url().nullable(),\n details_url: z.url().nullable(),\n external_id: z.string().nullable(),\n started_at: z.string().nullable(),\n completed_at: z.string().nullable(),\n});\n\nconst checkRunsSchema = z.object({ check_runs: z.array(checkRunSchema) });\nconst labelsSchema = z.array(z.object({ name: z.string().min(1) }));\nconst pullRequestCandidateSchema = z.object({\n number: z.number().int().positive(),\n user: z.object({ type: z.string().min(1) }),\n head: z.object({ ref: z.string().min(1), repo: z.object({ full_name: z.string().min(1) }) }),\n});\nconst openPullRequestsSchema = z.array(pullRequestCandidateSchema);\nconst pullRequestDetailSchema = pullRequestCandidateSchema.extend({\n html_url: z.url(),\n mergeable: z.boolean().nullable(),\n mergeable_state: z.string().min(1),\n head: pullRequestCandidateSchema.shape.head.extend({ sha: z.string().min(1) }),\n base: z.object({ ref: z.string().min(1), sha: z.string().min(1) }),\n});\nconst collaboratorPermissionSchema = z.object({\n permission: z.enum([\"admin\", \"maintain\", \"write\", \"triage\", \"read\", \"none\"]),\n});\nconst writePermissions = new Set([\"admin\", \"maintain\", \"write\"]);\n\nexport class GitHubReviewCommentAuthorError extends Error {\n readonly author: string;\n\n constructor(author: string) {\n super(`GitHub user ${author} does not have write access to the repository`);\n this.name = \"GitHubReviewCommentAuthorError\";\n this.author = author;\n }\n}\n\n/** Create a pull request from an existing head branch. */\nexport async function createPullRequest(input: CreatePullRequestInput): Promise<CreatedPullRequest> {\n const pull = pullRequestSchema.parse(\n await gitHubRequest(input, \"/pulls\", {\n method: \"POST\",\n body: JSON.stringify({\n title: input.title,\n head: input.head,\n base: input.base,\n ...(input.body === undefined ? {} : { body: input.body }),\n ...(input.draft === undefined ? {} : { draft: input.draft }),\n }),\n }),\n );\n return { prNumber: pull.number, prUrl: pull.html_url };\n}\n\n/** Create a check run for one commit. Requires a GitHub App token with checks:write. */\nexport async function createCheckRun(input: CreateCheckRunInput): Promise<GitHubCheckRun> {\n if (input.status === \"completed\" && input.conclusion === undefined) {\n throw new Error(\"completed check runs require a conclusion\");\n }\n if (input.status !== \"completed\" && input.conclusion !== undefined) {\n throw new Error(\"creating a check run with a conclusion requires completed status\");\n }\n return parseCheckRun(\n await gitHubRequest(input, \"/check-runs\", {\n method: \"POST\",\n body: JSON.stringify({\n name: input.name,\n head_sha: commitSha(input.headSha),\n ...checkRunFields(input),\n }),\n }),\n );\n}\n\n/** Update a check run previously created by the authenticated GitHub App. */\nexport async function updateCheckRun(input: UpdateCheckRunInput): Promise<GitHubCheckRun> {\n if (input.status !== undefined && input.status !== \"completed\" && input.conclusion !== undefined) {\n throw new Error(\"a check run conclusion conflicts with an incomplete status\");\n }\n return parseCheckRun(\n await gitHubRequest(input, `/check-runs/${positiveInteger(input.checkRunId, \"checkRunId\")}`, {\n method: \"PATCH\",\n body: JSON.stringify({\n ...(input.name === undefined ? {} : { name: input.name }),\n ...checkRunFields(input),\n }),\n }),\n );\n}\n\n/** List check runs reported for a commit, branch, or tag. */\nexport async function listCheckRunsForRef(input: ListCheckRunsForRefInput): Promise<GitHubCheckRun[]> {\n const query = new URLSearchParams({ per_page: \"100\" });\n if (input.checkName !== undefined) query.set(\"check_name\", input.checkName);\n const response = checkRunsSchema.parse(\n await gitHubRequest(input, `/commits/${encodeURIComponent(input.ref)}/check-runs?${query.toString()}`),\n );\n return response.check_runs.map(parseCheckRun);\n}\n\n/** Read one inline review comment after applying the author policy, which requires write access by default. */\nexport async function readReviewComment(\n input: ReadReviewCommentInput,\n): Promise<GitHubReviewComment> {\n const comment = parseReviewComment(\n await gitHubRequest(input, `/pulls/comments/${positiveInteger(input.commentId, \"commentId\")}`),\n );\n await assertReviewCommentAuthor(input, comment.author);\n return comment;\n}\n\n/** Reply to an inline review comment after applying the author policy, which requires write access by default. */\nexport async function answerReviewComment(\n input: AnswerReviewCommentInput,\n): Promise<GitHubReviewComment> {\n await readReviewComment(input);\n return parseReviewComment(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/comments/${positiveInteger(input.commentId, \"commentId\")}/replies`,\n { method: \"POST\", body: JSON.stringify({ body: input.body }) },\n ),\n );\n}\n\n/** Submit a summary and optional inline comments against a reviewed pull request commit. */\nexport async function submitPullRequestReview(\n input: SubmitPullRequestReviewInput,\n): Promise<SubmittedPullRequestReview> {\n const commitId = z.string().regex(/^[0-9a-f]{40}$/).parse(input.commitId);\n const head = await readPullRequestHead(input);\n if (head.sha !== commitId) {\n throw new Error(`pull request changed after review: expected ${commitId}, found ${head.sha}`);\n }\n const review = submittedReviewSchema.parse(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/reviews`,\n {\n method: \"POST\",\n body: JSON.stringify({\n commit_id: commitId,\n event: input.event,\n body: input.body,\n comments: (input.comments ?? []).map((comment) => ({\n path: comment.path,\n line: positiveInteger(comment.line, \"comment line\"),\n side: \"RIGHT\",\n body: comment.body,\n })),\n }),\n },\n ),\n );\n return { id: review.id, url: review.html_url, state: review.state };\n}\n\n/** Read the current head branch and commit of a pull request. */\nexport async function readPullRequestHead(\n input: ReadPullRequestHeadInput,\n): Promise<GitHubPullRequestHead> {\n const pull = pullRequestHeadSchema.parse(\n await gitHubRequest(input, `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}`),\n );\n return {\n branch: pull.head.ref,\n sha: pull.head.sha,\n repository: pull.head.repo.full_name.toLowerCase(),\n };\n}\n\n/** List open, same-repository pull requests by one author that GitHub reports as conflicting. */\nexport async function listConflictedPullRequests(\n input: ListConflictedPullRequestsInput,\n): Promise<ConflictedPullRequest[]> {\n const pulls = openPullRequestsSchema.parse(\n await gitHubRequest(input, `/pulls?state=open&per_page=100`),\n );\n const candidates = pulls.filter(\n (pull) =>\n pull.user.type === \"Bot\" &&\n pull.head.ref.startsWith(\"factory/\") &&\n pull.head.repo.full_name.toLowerCase() === input.repository.toLowerCase(),\n );\n const conflicted: ConflictedPullRequest[] = [];\n for (const candidate of candidates) {\n const pull = pullRequestDetailSchema.parse(\n await gitHubRequest(input, `/pulls/${candidate.number}`),\n );\n if (pull.mergeable === false || pull.mergeable_state === \"dirty\") {\n conflicted.push({\n prNumber: pull.number,\n prUrl: pull.html_url,\n headBranch: pull.head.ref,\n headSha: pull.head.sha,\n baseBranch: pull.base.ref,\n baseSha: pull.base.sha,\n });\n }\n }\n return conflicted;\n}\n\n/** Add one label to a pull request. */\nexport async function addLabel(input: PullRequestLabelInput): Promise<string[]> {\n return parseLabels(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/labels`,\n { method: \"POST\", body: JSON.stringify({ labels: [input.label] }) },\n ),\n );\n}\n\n/** Remove one label from a pull request. */\nexport async function removeLabel(input: PullRequestLabelInput): Promise<string[]> {\n return parseLabels(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/labels/${encodeURIComponent(input.label)}`,\n { method: \"DELETE\" },\n ),\n );\n}\n\nasync function gitHubRequest(\n input: GitHubRepositoryRequest,\n path: string,\n init: RequestInit = {},\n): Promise<unknown> {\n if (!repositorySlugPattern.test(input.repository)) {\n throw new Error(`invalid GitHub repository slug: ${input.repository}`);\n }\n const response = await (input.fetch ?? globalThis.fetch)(\n `${gitHubApiUrl}/repos/${input.repository}${path}`,\n {\n ...init,\n headers: {\n Accept: \"application/vnd.github+json\",\n Authorization: `Bearer ${input.token}`,\n \"Content-Type\": \"application/json\",\n \"X-GitHub-Api-Version\": \"2022-11-28\",\n ...init.headers,\n },\n },\n );\n const body: unknown = await response.json();\n if (!response.ok) {\n const message = z.object({ message: z.string() }).safeParse(body);\n throw new Error(\n `GitHub API request failed (${response.status}): ${message.success ? message.data.message : response.statusText}`,\n );\n }\n return body;\n}\n\nfunction parseReviewComment(value: unknown): GitHubReviewComment {\n const comment = reviewCommentSchema.parse(value);\n return {\n id: comment.id,\n body: comment.body,\n url: comment.html_url,\n author: comment.user.login,\n inReplyToId: comment.in_reply_to_id ?? null,\n };\n}\n\nfunction parseLabels(value: unknown): string[] {\n return labelsSchema.parse(value).map(({ name }) => name);\n}\n\nfunction parseCheckRun(value: unknown): GitHubCheckRun {\n const checkRun = checkRunSchema.parse(value);\n return {\n id: checkRun.id,\n name: checkRun.name,\n headSha: checkRun.head_sha,\n status: checkRun.status,\n conclusion: checkRun.conclusion,\n url: checkRun.html_url,\n detailsUrl: checkRun.details_url,\n externalId: checkRun.external_id,\n startedAt: checkRun.started_at,\n completedAt: checkRun.completed_at,\n };\n}\n\nfunction checkRunFields(input: CheckRunFields): Record<string, unknown> {\n return {\n ...(input.status === undefined ? {} : { status: input.status }),\n ...(input.conclusion === undefined ? {} : { conclusion: input.conclusion }),\n ...(input.detailsUrl === undefined ? {} : { details_url: input.detailsUrl }),\n ...(input.externalId === undefined ? {} : { external_id: input.externalId }),\n ...(input.startedAt === undefined ? {} : { started_at: input.startedAt }),\n ...(input.completedAt === undefined ? {} : { completed_at: input.completedAt }),\n ...(input.output === undefined ? {} : { output: checkRunOutput(input.output) }),\n };\n}\n\nfunction checkRunOutput(output: CheckRunOutput): Record<string, unknown> {\n return {\n title: output.title,\n summary: output.summary,\n ...(output.text === undefined ? {} : { text: output.text }),\n ...(output.annotations === undefined\n ? {}\n : {\n annotations: output.annotations.map((annotation) => ({\n path: annotation.path,\n start_line: positiveInteger(annotation.startLine, \"annotation startLine\"),\n end_line: positiveInteger(annotation.endLine ?? annotation.startLine, \"annotation endLine\"),\n ...(annotation.startColumn === undefined\n ? {}\n : { start_column: positiveInteger(annotation.startColumn, \"annotation startColumn\") }),\n ...(annotation.endColumn === undefined\n ? {}\n : { end_column: positiveInteger(annotation.endColumn, \"annotation endColumn\") }),\n annotation_level: annotation.annotationLevel,\n message: annotation.message,\n ...(annotation.title === undefined ? {} : { title: annotation.title }),\n ...(annotation.rawDetails === undefined ? {} : { raw_details: annotation.rawDetails }),\n })),\n }),\n };\n}\n\nasync function assertReviewCommentAuthor(\n input: GitHubRepositoryRequest & ReviewCommentTrustInput,\n author: string,\n): Promise<void> {\n if (input.authorPolicy === \"any\") {\n return;\n }\n const { permission } = collaboratorPermissionSchema.parse(\n await gitHubRequest(input, `/collaborators/${encodeURIComponent(author)}/permission`),\n );\n if (!writePermissions.has(permission)) {\n throw new GitHubReviewCommentAuthorError(author);\n }\n}\n\nfunction positiveInteger(value: number, name: string): number {\n if (!Number.isInteger(value) || value < 1) {\n throw new Error(`${name} must be a positive integer`);\n }\n return value;\n}\n\nfunction commitSha(value: string): string {\n return z.string().regex(/^[0-9a-f]{40}$/).parse(value);\n}\n\n/**\n * Verify a GitHub webhook HMAC signature (the x-hub-signature-256 header)\n * against the raw request body. Returns false for missing or malformed\n * signatures instead of throwing.\n */\nexport function verifyGitHubSignature(options: {\n secret: string;\n payload: string;\n signature: string | null;\n}): boolean {\n const { secret, payload, signature } = options;\n if (signature === null || !signature.startsWith(\"sha256=\")) {\n return false;\n }\n const expected = createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n const provided = signature.slice(\"sha256=\".length);\n if (provided.length !== expected.length) {\n return false;\n }\n return timingSafeEqual(Buffer.from(provided, \"hex\"), Buffer.from(expected, \"hex\"));\n}\n\nconst pushEventSchema = z.looseObject({\n ref: z.string().min(1),\n repository: z.looseObject({\n default_branch: z.string().min(1),\n full_name: z.string().min(1),\n }),\n});\n\nexport interface GitHubDefaultBranchPush {\n source: \"github_default_branch_push\";\n deliveryId: string;\n repositorySlug: string;\n defaultBranch: string;\n}\n\n/** Normalize a push to a repository's default branch for deterministic reconciliation. */\nexport function normalizeGitHubDefaultBranchPush(options: {\n deliveryId: string;\n event: string;\n payload: unknown;\n}): GitHubDefaultBranchPush | null {\n if (options.event !== \"push\") return null;\n const parsed = pushEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.ref !== `refs/heads/${parsed.data.repository.default_branch}`) {\n return null;\n }\n return {\n source: \"github_default_branch_push\",\n deliveryId: options.deliveryId,\n repositorySlug: parsed.data.repository.full_name.toLowerCase(),\n defaultBranch: parsed.data.repository.default_branch,\n };\n}\n\nconst pullRequestEventSchema = z.looseObject({\n action: z.string(),\n number: z.number().int().positive(),\n pull_request: z.looseObject({\n html_url: z.url(),\n draft: z.boolean(),\n user: z.looseObject({ login: z.string().min(1) }),\n head: z.looseObject({\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n ref: z.string().min(1),\n repo: z.looseObject({ full_name: z.string().min(1) }),\n }),\n base: z.looseObject({\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n ref: z.string().min(1),\n }),\n }),\n repository: z.looseObject({ full_name: z.string().min(1) }),\n sender: z.looseObject({ login: z.string().min(1) }),\n});\n\nconst reviewablePullRequestActions = new Set([\"opened\", \"reopened\", \"ready_for_review\", \"synchronize\"]);\n\nexport interface GitHubPullRequestSignal extends NormalizedSignal<\"github_pr\"> {\n repositorySlug: string;\n pullRequest: {\n number: number;\n url: string;\n author: string;\n draft: boolean;\n headSha: string;\n headBranch: string;\n headRepositorySlug: string;\n baseSha: string;\n baseBranch: string;\n sender: string;\n };\n}\n\n/** Normalize a newly reviewable or updated pull request into a factory signal. */\nexport function normalizeGitHubPullRequest(options: WebhookEvent): GitHubPullRequestSignal | null {\n if (options.event !== \"pull_request\") return null;\n const parsed = pullRequestEventSchema.safeParse(options.payload);\n if (!parsed.success || !reviewablePullRequestActions.has(parsed.data.action)) return null;\n if (parsed.data.pull_request.draft && parsed.data.action !== \"ready_for_review\") return null;\n\n const slug = parsed.data.repository.full_name.toLowerCase();\n const pull = parsed.data.pull_request;\n return {\n source: \"github_pr\",\n deliveryId: options.deliveryId,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}/pull/${parsed.data.number}` },\n pullRequest: {\n number: parsed.data.number,\n url: pull.html_url,\n author: pull.user.login,\n draft: pull.draft,\n headSha: pull.head.sha,\n headBranch: pull.head.ref,\n headRepositorySlug: pull.head.repo.full_name.toLowerCase(),\n baseSha: pull.base.sha,\n baseBranch: pull.base.ref,\n sender: parsed.data.sender.login,\n },\n payload: options.payload,\n };\n}\n\nconst issueEventSchema = z.looseObject({\n action: z.string(),\n issue: z.looseObject({\n number: z.number().int().min(1),\n title: z.string(),\n body: z.string().nullable(),\n }),\n repository: z.looseObject({\n full_name: z.string().min(1),\n }),\n});\n\nexport interface GitHubIssueSignal extends NormalizedSignal<\"github_issue\"> {\n repositorySlug: string;\n issue: { number: number; title: string; body: string | null };\n}\n\nconst failedWorkflowConclusions = new Set([\n \"action_required\",\n \"failure\",\n \"stale\",\n \"startup_failure\",\n \"timed_out\",\n]);\n\nconst workflowRunEventSchema = z.looseObject({\n action: z.string(),\n repository: z.looseObject({\n default_branch: z.string().min(1),\n full_name: z.string().min(1),\n }),\n workflow_run: z.looseObject({\n id: z.number().int().min(1),\n name: z.string().min(1),\n event: z.string().min(1),\n head_branch: z.string().min(1).nullable(),\n head_repository: z\n .looseObject({\n full_name: z.string().min(1),\n })\n .nullable(),\n head_sha: z.string().min(1),\n html_url: z.url(),\n conclusion: z.string().nullable(),\n run_attempt: z.number().int().min(1),\n }),\n});\n\nexport interface GitHubCIFailureSignal extends NormalizedSignal<\"github_ci_failure\"> {\n repositoryDefaultBranch: string;\n repositorySlug: string;\n workflowRun: {\n id: number;\n name: string;\n trigger: string;\n branch: string | null;\n headRepositorySlug: string | null;\n headSha: string;\n url: string;\n conclusion: string;\n attempt: number;\n };\n}\n\n/**\n * Normalize a GitHub issues webhook into the factory's signal shape. Returns\n * null for payloads that are not an opened issue. The caller supplies the\n * repository id; the payload stays untrusted data.\n */\nexport function normalizeGitHubIssueOpened(options: WebhookEvent): GitHubIssueSignal | null {\n if (options.event !== \"issues\") {\n return null;\n }\n const parsed = issueEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"opened\") {\n return null;\n }\n const slug = parsed.data.repository.full_name.toLowerCase();\n const { number, title, body } = parsed.data.issue;\n return {\n source: \"github_issue\",\n deliveryId: options.deliveryId,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}#${number}` },\n issue: { number, title, body },\n payload: options.payload,\n };\n}\n\nconst pullRequestClosedSchema = z.looseObject({\n action: z.string(),\n pull_request: z.looseObject({\n number: z.number().int().min(1),\n html_url: z.url(),\n merged: z.boolean(),\n merged_by: z.looseObject({ login: z.string().min(1) }).nullable().optional(),\n merge_commit_sha: z\n .string()\n .regex(/^[0-9a-f]{40}$/)\n .nullable()\n .optional(),\n }),\n repository: z.looseObject({\n full_name: z.string().min(1),\n }),\n sender: z.looseObject({ login: z.string().min(1) }),\n});\n\nexport interface GitHubPullRequestClosed {\n source: \"github_pull_request_closed\";\n deliveryId: string;\n repositorySlug: string;\n prNumber: number;\n prUrl: string;\n merged: boolean;\n /** The merge commit on the base branch; null when closed without merging. */\n mergeCommitSha: string | null;\n /** The GitHub login that merged the pull request, or closed it without merging. */\n decidedBy: string;\n}\n\n/**\n * Normalize a closed pull_request webhook so the factory can observe what\n * happened to its change: merged records merged_by (the sender when GitHub\n * omits it), a close without merge records the sender.\n */\nexport function normalizeGitHubPullRequestClosed(\n options: WebhookEvent,\n): GitHubPullRequestClosed | null {\n if (options.event !== \"pull_request\") {\n return null;\n }\n const parsed = pullRequestClosedSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"closed\") {\n return null;\n }\n const pr = parsed.data.pull_request;\n const sender = parsed.data.sender.login;\n return {\n source: \"github_pull_request_closed\",\n deliveryId: options.deliveryId,\n repositorySlug: parsed.data.repository.full_name.toLowerCase(),\n prNumber: pr.number,\n prUrl: pr.html_url,\n merged: pr.merged,\n mergeCommitSha: pr.merged ? (pr.merge_commit_sha ?? null) : null,\n decidedBy: pr.merged ? (pr.merged_by?.login ?? sender) : sender,\n };\n}\n\n/** Normalize a completed, unsuccessful GitHub Actions run into a CI failure signal. */\nexport function normalizeGitHubWorkflowRunFailure(\n options: WebhookEvent,\n): GitHubCIFailureSignal | null {\n if (options.event !== \"workflow_run\") {\n return null;\n }\n const parsed = workflowRunEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"completed\") {\n return null;\n }\n\n const run = parsed.data.workflow_run;\n const conclusion = run.conclusion;\n if (conclusion === null || !failedWorkflowConclusions.has(conclusion)) {\n return null;\n }\n const slug = parsed.data.repository.full_name.toLowerCase();\n return {\n source: \"github_ci_failure\",\n deliveryId: options.deliveryId,\n repositoryDefaultBranch: parsed.data.repository.default_branch,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}/actions/runs/${run.id}` },\n workflowRun: {\n id: run.id,\n name: run.name,\n trigger: run.event,\n branch: run.head_branch,\n headRepositorySlug: run.head_repository?.full_name.toLowerCase() ?? null,\n headSha: run.head_sha,\n url: run.html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