@sentry/junior-github 0.279.0 → 0.281.0

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.
package/dist/index.js CHANGED
@@ -59,7 +59,77 @@ import {
59
59
  readGrantPermissions,
60
60
  requireEnv,
61
61
  resolveUserAccount
62
- } from "./chunk-IR7D5MR7.js";
62
+ } from "./chunk-NSAVG2P3.js";
63
+
64
+ // src/tool-support/attribution.ts
65
+ import * as z from "zod";
66
+
67
+ // src/tool-support/github-api.ts
68
+ import {
69
+ PluginToolInputError
70
+ } from "@sentry/junior-plugin-api";
71
+ var GITHUB_API_BASE = "https://api.github.com";
72
+ async function githubApi(egress, input) {
73
+ const headers = {
74
+ Accept: "application/vnd.github+json",
75
+ "X-GitHub-Api-Version": input.apiVersion ?? "2022-11-28"
76
+ };
77
+ if (input.body !== void 0) headers["Content-Type"] = "application/json";
78
+ const response = await egress.fetch({
79
+ provider: "github",
80
+ operation: input.operation,
81
+ request: new Request(`${GITHUB_API_BASE}${input.path}`, {
82
+ method: input.method ?? "GET",
83
+ headers,
84
+ signal: input.signal,
85
+ ...input.body !== void 0 ? { body: JSON.stringify(input.body) } : void 0
86
+ })
87
+ });
88
+ return {
89
+ body: await readBody(response),
90
+ ok: response.ok,
91
+ status: response.status
92
+ };
93
+ }
94
+ async function readBody(response) {
95
+ const text2 = await response.text();
96
+ if (!text2) return void 0;
97
+ try {
98
+ return JSON.parse(text2);
99
+ } catch {
100
+ return text2;
101
+ }
102
+ }
103
+ function repoPath(repo) {
104
+ return `/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}`;
105
+ }
106
+ function parseRepo(value) {
107
+ const parts = value.split("/").map((part) => part.trim());
108
+ if (parts.length !== 2 || !parts[0] || !parts[1]) {
109
+ throw new PluginToolInputError('repo must use "owner/name" format');
110
+ }
111
+ return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
112
+ }
113
+ function githubErrorMessage(body) {
114
+ if (typeof body === "string" && body.trim()) return body.trim();
115
+ if (!isRecord2(body)) return "GitHub request failed";
116
+ const errors = Array.isArray(body.errors) ? body.errors.filter(isRecord2) : [];
117
+ if (typeof body.message === "string" && body.message.trim()) {
118
+ const details = errors.map(
119
+ (error) => ["resource", "field", "code", "message"].map((name) => {
120
+ const value = error[name];
121
+ return typeof value === "string" && value.trim() ? `${name}=${value.trim()}` : void 0;
122
+ }).filter(Boolean).join(" ")
123
+ ).filter(Boolean).join("; ");
124
+ const message = body.message.trim();
125
+ return details ? `${message}: ${details}` : message;
126
+ }
127
+ const graphqlMessages = errors.map((error) => error.message).filter((message) => typeof message === "string" && message.trim());
128
+ return graphqlMessages.length ? graphqlMessages.join("; ") : "GitHub request failed";
129
+ }
130
+ function isRecord2(value) {
131
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
132
+ }
63
133
 
64
134
  // src/tool-support/attribution.ts
65
135
  var GITHUB_REQUEST_ATTRIBUTION_START = "<!-- junior-request-attribution:start -->";
@@ -124,17 +194,25 @@ function formatAttributionBlock(labels) {
124
194
  via ${labels.join(", ")}.
125
195
  ${GITHUB_REQUEST_ATTRIBUTION_END}`;
126
196
  }
127
- function applyAttribution(body, label) {
197
+ var ATTRIBUTION_BLOCK = new RegExp(
198
+ `${GITHUB_REQUEST_ATTRIBUTION_START}([\\s\\S]*?)${GITHUB_REQUEST_ATTRIBUTION_END}`
199
+ );
200
+ function blockLabels(body) {
201
+ const contents = body?.match(ATTRIBUTION_BLOCK)?.[1];
202
+ return contents === void 0 ? [] : parseExistingLabels(contents);
203
+ }
204
+ function applyAttribution(body, label, currentBody) {
128
205
  const normalizedBody = body.trimEnd();
129
- const existing = new RegExp(
130
- `${GITHUB_REQUEST_ATTRIBUTION_START}([\\s\\S]*?)${GITHUB_REQUEST_ATTRIBUTION_END}`
131
- );
132
- const existingMatch = normalizedBody.match(existing);
133
- const existingLabels = existingMatch?.[1] !== void 0 ? parseExistingLabels(existingMatch[1]) : [];
134
- const labels = label && !existingLabels.includes(label) ? [...existingLabels, label] : existingLabels;
206
+ const labels = [
207
+ .../* @__PURE__ */ new Set([
208
+ ...blockLabels(currentBody),
209
+ ...blockLabels(normalizedBody),
210
+ ...label ? [label] : []
211
+ ])
212
+ ];
135
213
  const attribution = labels.length ? formatAttributionBlock(labels) : void 0;
136
- if (existingMatch) {
137
- return attribution ? normalizedBody.replace(existing, attribution) : normalizedBody.replace(existing, "").trimEnd();
214
+ if (ATTRIBUTION_BLOCK.test(normalizedBody)) {
215
+ return attribution ? normalizedBody.replace(ATTRIBUTION_BLOCK, attribution) : normalizedBody.replace(ATTRIBUTION_BLOCK, "").trimEnd();
138
216
  }
139
217
  if (!attribution) {
140
218
  return normalizedBody;
@@ -143,6 +221,15 @@ function applyAttribution(body, label) {
143
221
 
144
222
  ${attribution}` : attribution;
145
223
  }
224
+ async function readGitHubBody(egress, input) {
225
+ const response = await githubApi(egress, input);
226
+ if (!response.ok) {
227
+ throw new Error(
228
+ `GitHub read before update failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`
229
+ );
230
+ }
231
+ return z.object({ body: z.string().nullable().optional() }).parse(response.body).body ?? void 0;
232
+ }
146
233
  async function resolveGitHubRequester(ctx) {
147
234
  if (!ctx.actor || ctx.actor.platform === "system") return void 0;
148
235
  try {
@@ -154,7 +241,7 @@ async function resolveGitHubRequester(ctx) {
154
241
  return void 0;
155
242
  }
156
243
  }
157
- function appendGitHubRequesterAttribution(body, ctx, requester) {
244
+ function appendGitHubRequesterAttribution(body, ctx, requester, currentBody) {
158
245
  return applyAttribution(
159
246
  body,
160
247
  requesterLabel({
@@ -163,7 +250,8 @@ function appendGitHubRequesterAttribution(body, ctx, requester) {
163
250
  identity: requester?.identity,
164
251
  source: ctx.source,
165
252
  user: requester?.user
166
- })
253
+ }),
254
+ currentBody
167
255
  );
168
256
  }
169
257
 
@@ -176,10 +264,10 @@ import {
176
264
  // src/tools/clone-repository.ts
177
265
  import {
178
266
  definePluginTool,
179
- PluginToolInputError,
267
+ PluginToolInputError as PluginToolInputError2,
180
268
  pluginToolOutputSchema
181
269
  } from "@sentry/junior-plugin-api";
182
- import { z } from "zod";
270
+ import * as z2 from "zod";
183
271
 
184
272
  // src/sandbox-paths.ts
185
273
  var RESERVED_SANDBOX_DIRECTORIES = /* @__PURE__ */ new Set([
@@ -192,9 +280,9 @@ function isReservedSandboxDirectory(path) {
192
280
  }
193
281
 
194
282
  // src/tools/clone-repository.ts
195
- var inputSchema = z.object({
196
- repo: z.string().describe('Repository in "owner/name" format.'),
197
- directory: z.string().regex(/^(?:[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*)$/).refine(
283
+ var inputSchema = z2.object({
284
+ repo: z2.string().describe('Repository in "owner/name" format.'),
285
+ directory: z2.string().regex(/^(?:[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*)$/).refine(
198
286
  (value) => !value.split("/").some((part) => part === "." || part === ".."),
199
287
  {
200
288
  message: "Directory must be a relative path without . or .. segments."
@@ -202,24 +290,24 @@ var inputSchema = z.object({
202
290
  ).describe(
203
291
  "Optional destination directory under the sandbox root. Defaults to repos/{name}."
204
292
  ).optional(),
205
- allow_ad_hoc: z.boolean().optional().describe(
293
+ allow_ad_hoc: z2.boolean().optional().describe(
206
294
  "Set true in the default Sandbox to keep an intentional ad-hoc checkout when matching Workspaces exist. Prefer switchWorkspace; the checkout is already present after a successful switch."
207
295
  )
208
296
  }).strict();
209
- var cloneSchema = z.object({
210
- path: z.string(),
211
- repo: z.string(),
212
- note: z.string().optional()
297
+ var cloneSchema = z2.object({
298
+ path: z2.string(),
299
+ repo: z2.string(),
300
+ note: z2.string().optional()
213
301
  });
214
302
  var outputSchema = pluginToolOutputSchema.merge(
215
303
  cloneSchema.extend({
216
- target: z.literal("cloneRepository")
304
+ target: z2.literal("cloneRepository")
217
305
  })
218
306
  );
219
- function parseRepo(value) {
307
+ function parseRepo2(value) {
220
308
  const parts = value.split("/").map((part) => part.trim());
221
309
  if (parts.length !== 2 || !parts[0] || !parts[1]) {
222
- throw new PluginToolInputError('repo must use "owner/name" format');
310
+ throw new PluginToolInputError2('repo must use "owner/name" format');
223
311
  }
224
312
  return { owner: parts[0], name: parts[1] };
225
313
  }
@@ -229,11 +317,11 @@ function quotedNames(workspaces) {
229
317
  function workspaceRequiredError(repoId, workspaces) {
230
318
  const names = quotedNames(workspaces);
231
319
  if (workspaces.length === 1) {
232
- return new PluginToolInputError(
320
+ return new PluginToolInputError2(
233
321
  `Repository ${repoId} is part of Workspace ${names}. Call switchWorkspace with that name; the checkout is already present after the switch. Pass allow_ad_hoc=true only for an intentional ad-hoc checkout.`
234
322
  );
235
323
  }
236
- return new PluginToolInputError(
324
+ return new PluginToolInputError2(
237
325
  `Repository ${repoId} is part of Workspaces ${names}. Call switchWorkspace with one of those names; the checkout is already present after the switch. Pass allow_ad_hoc=true only for an intentional ad-hoc checkout.`
238
326
  );
239
327
  }
@@ -291,7 +379,7 @@ function createGitHubCloneRepositoryTool(ctx) {
291
379
  inputSchema,
292
380
  outputSchema,
293
381
  async execute(input, options) {
294
- const repo = parseRepo(input.repo);
382
+ const repo = parseRepo2(input.repo);
295
383
  const repoId = `${repo.owner}/${repo.name}`;
296
384
  let workspaces = [];
297
385
  let active;
@@ -319,7 +407,7 @@ function createGitHubCloneRepositoryTool(ctx) {
319
407
  const directory = input.directory ?? defaultDirectory(repo.name);
320
408
  const rootSegment = directory.split("/")[0] ?? directory;
321
409
  if (isReservedSandboxDirectory(rootSegment)) {
322
- throw new PluginToolInputError(
410
+ throw new PluginToolInputError2(
323
411
  `Directory conflicts with a reserved sandbox path: ${directory}`
324
412
  );
325
413
  }
@@ -333,7 +421,7 @@ function createGitHubCloneRepositoryTool(ctx) {
333
421
  signal: commandSignal(options.signal, 3e4)
334
422
  });
335
423
  if (mkdir.exitCode !== 0) {
336
- throw new PluginToolInputError(
424
+ throw new PluginToolInputError2(
337
425
  `Failed to create clone parent directory: ${parentDirectory}`
338
426
  );
339
427
  }
@@ -345,7 +433,7 @@ function createGitHubCloneRepositoryTool(ctx) {
345
433
  signal: commandSignal(options.signal, 3e4)
346
434
  });
347
435
  if (exists.exitCode === 0) {
348
- throw new PluginToolInputError(`destination already exists: ${path}`);
436
+ throw new PluginToolInputError2(`destination already exists: ${path}`);
349
437
  }
350
438
  let clone;
351
439
  try {
@@ -368,7 +456,7 @@ function createGitHubCloneRepositoryTool(ctx) {
368
456
  }
369
457
  if (clone.exitCode !== 0) {
370
458
  await removePartialClone(ctx, path);
371
- throw new PluginToolInputError(
459
+ throw new PluginToolInputError2(
372
460
  `GitHub repository clone failed: ${clone.stderr.trim() || `exit ${clone.exitCode}`}`
373
461
  );
374
462
  }
@@ -385,48 +473,37 @@ function createGitHubCloneRepositoryTool(ctx) {
385
473
  // src/tools/comment-on-pull-request.ts
386
474
  import {
387
475
  definePluginTool as definePluginTool2,
388
- PluginToolInputError as PluginToolInputError2,
476
+ PluginToolInputError as PluginToolInputError3,
389
477
  pluginToolOutputSchema as pluginToolOutputSchema2
390
478
  } from "@sentry/junior-plugin-api";
391
- import { z as z2 } from "zod";
392
- var inputSchema2 = z2.object({
393
- repo: z2.string().describe('Repository in "owner/name" format.'),
394
- number: z2.number().int().positive().describe("Pull request number."),
395
- body: z2.string().trim().min(1).describe("Comment text."),
396
- in_reply_to: z2.number().int().positive().optional().describe(
479
+ import * as z3 from "zod";
480
+ var inputSchema2 = z3.object({
481
+ repo: z3.string().describe('Repository in "owner/name" format.'),
482
+ number: z3.number().int().positive().describe("Pull request number."),
483
+ body: z3.string().trim().min(1).describe("Comment text."),
484
+ in_reply_to: z3.number().int().positive().optional().describe(
397
485
  "Inline review comment id. Set it to reply in that comment's thread. Omit it to comment on the pull request."
398
486
  )
399
487
  }).strict();
400
488
  var outputSchema2 = pluginToolOutputSchema2.extend({
401
- target: z2.literal("commentOnPullRequest"),
402
- repo: z2.string(),
403
- number: z2.number(),
404
- comment_id: z2.number(),
405
- url: z2.string()
489
+ target: z3.literal("commentOnPullRequest"),
490
+ repo: z3.string(),
491
+ number: z3.number(),
492
+ comment_id: z3.number(),
493
+ url: z3.string()
406
494
  });
407
- function parseRepo2(value) {
408
- const parts = value.split("/").map((part) => part.trim());
409
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
410
- throw new PluginToolInputError2('repo must use "owner/name" format');
411
- }
412
- return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
413
- }
414
- async function readJson(response) {
415
- const text2 = await response.text();
416
- if (!text2) return void 0;
417
- try {
418
- return JSON.parse(text2);
419
- } catch {
420
- return text2;
421
- }
422
- }
423
- function githubError(body) {
424
- if (body && typeof body === "object" && !Array.isArray(body)) {
425
- const message = body.message;
426
- if (typeof message === "string" && message.trim()) return message.trim();
495
+ async function threadRootId(egress, prefix, commentId) {
496
+ const response = await githubApi(egress, {
497
+ operation: "github.pull.comment.get",
498
+ path: `${prefix}/pulls/comments/${commentId}`
499
+ });
500
+ if (!response.ok) {
501
+ const message = `GitHub review comment lookup failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
502
+ if (response.status === 404) throw new PluginToolInputError3(message);
503
+ throw new Error(message);
427
504
  }
428
- if (typeof body === "string" && body.trim()) return body.trim();
429
- return "GitHub request failed";
505
+ const comment = z3.object({ in_reply_to_id: z3.number().nullish() }).parse(response.body);
506
+ return comment.in_reply_to_id ?? commentId;
430
507
  }
431
508
  function createGitHubCommentOnPullRequestTool(egress) {
432
509
  return definePluginTool2({
@@ -441,31 +518,23 @@ function createGitHubCommentOnPullRequestTool(egress) {
441
518
  inputSchema: inputSchema2,
442
519
  outputSchema: outputSchema2,
443
520
  async execute(input) {
444
- const repo = parseRepo2(input.repo);
445
- const repoPath = `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}`;
446
- const url = input.in_reply_to === void 0 ? `${repoPath}/issues/${input.number}/comments` : `${repoPath}/pulls/${input.number}/comments/${input.in_reply_to}/replies`;
447
- const response = await egress.fetch({
448
- provider: "github",
521
+ const repo = parseRepo(input.repo);
522
+ const prefix = repoPath(repo);
523
+ const path = input.in_reply_to === void 0 ? `${prefix}/issues/${input.number}/comments` : `${prefix}/pulls/${input.number}/comments/${await threadRootId(egress, prefix, input.in_reply_to)}/replies`;
524
+ const response = await githubApi(egress, {
449
525
  operation: "github.pull.comment.create",
450
- request: new Request(url, {
451
- method: "POST",
452
- headers: {
453
- Accept: "application/vnd.github+json",
454
- "Content-Type": "application/json",
455
- "X-GitHub-Api-Version": "2022-11-28"
456
- },
457
- body: JSON.stringify({ body: input.body })
458
- })
526
+ method: "POST",
527
+ path,
528
+ body: { body: input.body }
459
529
  });
460
- const parsed = await readJson(response);
461
530
  if (!response.ok) {
462
- const message = `GitHub pull request comment failed with HTTP ${response.status}: ${githubError(parsed)}`;
531
+ const message = `GitHub pull request comment failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
463
532
  if (response.status === 404 || response.status === 422) {
464
- throw new PluginToolInputError2(message);
533
+ throw new PluginToolInputError3(message);
465
534
  }
466
535
  throw new Error(message);
467
536
  }
468
- const comment = z2.object({ id: z2.number(), html_url: z2.string() }).parse(parsed);
537
+ const comment = z3.object({ id: z3.number(), html_url: z3.string() }).parse(response.body);
469
538
  return {
470
539
  target: "commentOnPullRequest",
471
540
  repo: repo.ref,
@@ -478,21 +547,21 @@ function createGitHubCommentOnPullRequestTool(egress) {
478
547
  }
479
548
 
480
549
  // src/object-facts.ts
481
- import { z as z3 } from "zod";
482
- var person = z3.object({ login: z3.string() });
483
- var responseSchema = z3.object({
484
- body: z3.string().nullable().optional(),
550
+ import * as z4 from "zod";
551
+ var person = z4.object({ login: z4.string() });
552
+ var responseSchema = z4.object({
553
+ body: z4.string().nullable().optional(),
485
554
  user: person.nullable().optional(),
486
- requested_reviewers: z3.array(person).optional(),
487
- assignees: z3.array(person).optional(),
488
- labels: z3.array(z3.union([z3.string(), z3.object({ name: z3.string() })])).optional(),
489
- head: z3.object({ ref: z3.string() }).optional(),
490
- base: z3.object({ ref: z3.string() }).optional(),
491
- mergeable: z3.boolean().nullable().optional(),
492
- changed_files: z3.number().int().nonnegative().optional(),
493
- additions: z3.number().int().nonnegative().optional(),
494
- deletions: z3.number().int().nonnegative().optional(),
495
- updated_at: z3.iso.datetime({ offset: true }).optional()
555
+ requested_reviewers: z4.array(person).optional(),
556
+ assignees: z4.array(person).optional(),
557
+ labels: z4.array(z4.union([z4.string(), z4.object({ name: z4.string() })])).optional(),
558
+ head: z4.object({ ref: z4.string() }).optional(),
559
+ base: z4.object({ ref: z4.string() }).optional(),
560
+ mergeable: z4.boolean().nullable().optional(),
561
+ changed_files: z4.number().int().nonnegative().optional(),
562
+ additions: z4.number().int().nonnegative().optional(),
563
+ deletions: z4.number().int().nonnegative().optional(),
564
+ updated_at: z4.iso.datetime({ offset: true }).optional()
496
565
  });
497
566
  var short = (value) => {
498
567
  const text2 = value?.trim();
@@ -617,22 +686,22 @@ import {
617
686
  objectFactsSchema,
618
687
  definePluginTool as definePluginTool3,
619
688
  EgressAuthRequired,
620
- PluginToolInputError as PluginToolInputError4,
689
+ PluginToolInputError as PluginToolInputError5,
621
690
  subscribableResourceSchema,
622
691
  pluginToolOutputSchema as pluginToolOutputSchema3
623
692
  } from "@sentry/junior-plugin-api";
624
693
  import { Type } from "@sinclair/typebox";
625
694
  import { Value } from "@sinclair/typebox/value";
626
- import { z as z4 } from "zod";
695
+ import * as z5 from "zod";
627
696
 
628
697
  // src/tools/footer.ts
629
- import { PluginToolInputError as PluginToolInputError3 } from "@sentry/junior-plugin-api";
698
+ import { PluginToolInputError as PluginToolInputError4 } from "@sentry/junior-plugin-api";
630
699
  var GITHUB_SESSION_FOOTER_START = "<!-- junior-session-footer:start -->";
631
700
  var GITHUB_SESSION_FOOTER_END = "<!-- junior-session-footer:end -->";
632
701
  var GITHUB_CONVERSATION_ID_MARKER = "junior-conversation-id:";
633
702
  function nonEmptyString(value, name) {
634
703
  if (!value?.trim()) {
635
- throw new PluginToolInputError3(`${name} is required`);
704
+ throw new PluginToolInputError4(`${name} is required`);
636
705
  }
637
706
  return value.trim();
638
707
  }
@@ -709,11 +778,11 @@ function githubLinkedIssues(body, repositoryFullName) {
709
778
  if (!body) return [];
710
779
  const references = /* @__PURE__ */ new Map();
711
780
  const add = (linkedRepository, rawNumber) => {
712
- const number = Number.parseInt(rawNumber, 10);
713
- if (!Number.isInteger(number) || number <= 0) return;
781
+ const number22 = Number.parseInt(rawNumber, 10);
782
+ if (!Number.isInteger(number22) || number22 <= 0) return;
714
783
  const normalizedRepository = linkedRepository.toLowerCase();
715
- references.set(`${normalizedRepository}#${number}`, {
716
- number,
784
+ references.set(`${normalizedRepository}#${number22}`, {
785
+ number: number22,
717
786
  repositoryFullName: linkedRepository
718
787
  });
719
788
  };
@@ -776,11 +845,11 @@ var createIssueInputSchema = Type.Object(
776
845
  },
777
846
  { additionalProperties: false }
778
847
  );
779
- var createIssueToolInputSchema = z4.object({
780
- repo: z4.string().describe('Repository in "owner/name" format.'),
781
- title: z4.string().describe("Issue title."),
782
- body: z4.string().describe("Issue body. The runtime appends the conversation footer.").optional(),
783
- labels: z4.array(z4.string()).describe("Labels to apply to the issue.").optional()
848
+ var createIssueToolInputSchema = z5.object({
849
+ repo: z5.string().describe('Repository in "owner/name" format.'),
850
+ title: z5.string().describe("Issue title."),
851
+ body: z5.string().describe("Issue body. The runtime appends the conversation footer.").optional(),
852
+ labels: z5.array(z5.string()).describe("Labels to apply to the issue.").optional()
784
853
  }).strict();
785
854
  var createIssueStateSchema = Type.Union([
786
855
  Type.Object(
@@ -805,18 +874,18 @@ var createIssueStateSchema = Type.Union([
805
874
  { additionalProperties: false }
806
875
  )
807
876
  ]);
808
- var gitHubIssueDataSchema = z4.object({
809
- number: z4.number(),
877
+ var gitHubIssueDataSchema = z5.object({
878
+ number: z5.number(),
810
879
  subscribable: subscribableResourceSchema.optional(),
811
- url: z4.string()
880
+ url: z5.string()
812
881
  });
813
882
  var gitHubIssueOutputSchema = pluginToolOutputSchema3.merge(
814
883
  gitHubIssueDataSchema.extend({
815
- target: z4.literal("createIssue")
884
+ target: z5.literal("createIssue")
816
885
  })
817
886
  );
818
887
  function gitHubIssueToolResult(input, result, canSubscribe) {
819
- const repo = parseRepo3(input.repo);
888
+ const repo = parseRepo(input.repo);
820
889
  const subscribable = gitHubIssueSubscribable({
821
890
  canSubscribe,
822
891
  number: result.number,
@@ -849,51 +918,17 @@ function parseCreateIssueInput(input) {
849
918
  try {
850
919
  return Value.Parse(createIssueInputSchema, input);
851
920
  } catch (error) {
852
- throw new PluginToolInputError4("Invalid GitHub createIssue input.", {
921
+ throw new PluginToolInputError5("Invalid GitHub createIssue input.", {
853
922
  cause: error
854
923
  });
855
924
  }
856
925
  }
857
926
  function nonEmptyString2(value, name) {
858
927
  if (!value?.trim()) {
859
- throw new PluginToolInputError4(`${name} is required`);
928
+ throw new PluginToolInputError5(`${name} is required`);
860
929
  }
861
930
  return value.trim();
862
931
  }
863
- function parseRepo3(value) {
864
- const repo = nonEmptyString2(value, "repo");
865
- const parts = repo.split("/");
866
- if (parts.length !== 2 || !parts[0]?.trim() || !parts[1]?.trim()) {
867
- throw new PluginToolInputError4('repo must use "owner/name" format');
868
- }
869
- return {
870
- owner: parts[0].trim(),
871
- name: parts[1].trim()
872
- };
873
- }
874
- async function readJsonResponse(response) {
875
- const text2 = await response.text();
876
- if (!text2) {
877
- return void 0;
878
- }
879
- try {
880
- return JSON.parse(text2);
881
- } catch {
882
- return text2;
883
- }
884
- }
885
- function githubApiErrorMessage(payload) {
886
- if (payload && typeof payload === "object" && !Array.isArray(payload)) {
887
- const message = payload.message;
888
- if (typeof message === "string") {
889
- return message;
890
- }
891
- }
892
- if (typeof payload === "string" && payload.trim()) {
893
- return payload.trim();
894
- }
895
- return "GitHub request failed";
896
- }
897
932
  function createIssueState(value) {
898
933
  if (value === void 0) {
899
934
  return void 0;
@@ -916,7 +951,7 @@ function isDefinitiveGitHubIssueCreateRejection(error) {
916
951
  return [400, 401, 404, 410, 422].includes(error.status);
917
952
  }
918
953
  async function createGitHubIssueRequest(conversationId, input, ctx, dashboardUrl) {
919
- const repo = parseRepo3(input.repo);
954
+ const repo = parseRepo(input.repo);
920
955
  const labels = input.labels?.map(
921
956
  (label) => nonEmptyString2(label, "labels entry")
922
957
  );
@@ -933,31 +968,18 @@ async function createGitHubIssueRequest(conversationId, input, ctx, dashboardUrl
933
968
  ),
934
969
  ...labels?.length ? { labels } : void 0
935
970
  };
936
- return new Request(
937
- `https://api.github.com/repos/${encodeURIComponent(
938
- repo.owner
939
- )}/${encodeURIComponent(repo.name)}/issues`,
940
- {
941
- method: "POST",
942
- headers: {
943
- Accept: "application/vnd.github+json",
944
- "Content-Type": "application/json",
945
- "X-GitHub-Api-Version": "2022-11-28"
946
- },
947
- body: JSON.stringify(payload)
948
- }
949
- );
971
+ return { path: `${repoPath(repo)}/issues`, body: payload };
950
972
  }
951
973
  async function createGitHubIssue(ctx, request) {
952
- const response = await ctx.egress.fetch({
953
- provider: "github",
974
+ const response = await githubApi(ctx.egress, {
954
975
  operation: "github.issue.create",
955
- request
976
+ method: "POST",
977
+ ...request
956
978
  });
957
- const parsed = await readJsonResponse(response);
979
+ const parsed = response.body;
958
980
  if (!response.ok) {
959
981
  throw new GitHubIssueCreateRejectedError(
960
- `GitHub issue creation failed with HTTP ${response.status}: ${githubApiErrorMessage(
982
+ `GitHub issue creation failed with HTTP ${response.status}: ${githubErrorMessage(
961
983
  parsed
962
984
  )}`,
963
985
  response.status
@@ -1071,101 +1093,82 @@ function createGitHubIssueTool(ctx) {
1071
1093
  // src/tools/get-deployment.ts
1072
1094
  import {
1073
1095
  definePluginTool as definePluginTool4,
1074
- PluginToolInputError as PluginToolInputError5,
1096
+ PluginToolInputError as PluginToolInputError6,
1075
1097
  pluginToolOutputSchema as pluginToolOutputSchema4,
1076
1098
  subscribableResourceSchema as subscribableResourceSchema2
1077
1099
  } from "@sentry/junior-plugin-api";
1078
- import { z as z5 } from "zod";
1079
- var commitShaSchema = z5.string().regex(/^[0-9a-f]{40}$/i);
1080
- var inputSchema3 = z5.object({
1081
- repo: z5.string().describe('Repository in "owner/name" format.'),
1100
+ import * as z6 from "zod";
1101
+ var commitShaSchema = z6.string().regex(/^[0-9a-f]{40}$/i);
1102
+ var inputSchema3 = z6.object({
1103
+ repo: z6.string().describe('Repository in "owner/name" format.'),
1082
1104
  commit_sha: commitShaSchema.describe(
1083
1105
  "Full 40-character Git commit SHA recorded by the deployment."
1084
1106
  ),
1085
- environment: z5.string().trim().min(1).describe(
1107
+ environment: z6.string().trim().min(1).describe(
1086
1108
  'Optional GitHub deployment environment, such as "Production". Omit to inspect and watch deployments for the commit across environments.'
1087
1109
  ).optional()
1088
1110
  }).strict();
1089
- var statusSchema = z5.object({
1090
- created_at: z5.string(),
1091
- creator: z5.string().nullable(),
1092
- description: z5.string().nullable(),
1093
- environment_url: z5.string().nullable(),
1094
- id: z5.number(),
1095
- log_url: z5.string().nullable(),
1096
- state: z5.string()
1111
+ var statusSchema = z6.object({
1112
+ created_at: z6.string(),
1113
+ creator: z6.string().nullable(),
1114
+ description: z6.string().nullable(),
1115
+ environment_url: z6.string().nullable(),
1116
+ id: z6.number(),
1117
+ log_url: z6.string().nullable(),
1118
+ state: z6.string()
1097
1119
  }).strict();
1098
- var deploymentSchema = z5.object({
1099
- created_at: z5.string(),
1100
- creator: z5.string().nullable(),
1101
- description: z5.string().nullable(),
1102
- environment: z5.string(),
1103
- id: z5.number(),
1120
+ var deploymentSchema = z6.object({
1121
+ created_at: z6.string(),
1122
+ creator: z6.string().nullable(),
1123
+ description: z6.string().nullable(),
1124
+ environment: z6.string(),
1125
+ id: z6.number(),
1104
1126
  latest_status: statusSchema.nullable(),
1105
- ref: z5.string(),
1127
+ ref: z6.string(),
1106
1128
  sha: commitShaSchema,
1107
- updated_at: z5.string(),
1108
- url: z5.string()
1129
+ updated_at: z6.string(),
1130
+ url: z6.string()
1109
1131
  }).strict();
1110
- var deploymentSourceSchema = z5.object({
1132
+ var deploymentSourceSchema = z6.object({
1111
1133
  commit_sha: commitShaSchema,
1112
1134
  deployment: deploymentSchema.nullable(),
1113
- environment: z5.string().nullable(),
1114
- repo: z5.string(),
1135
+ environment: z6.string().nullable(),
1136
+ repo: z6.string(),
1115
1137
  subscribable: subscribableResourceSchema2.optional()
1116
1138
  }).strict();
1117
1139
  var outputSchema3 = pluginToolOutputSchema4.merge(
1118
1140
  deploymentSourceSchema.extend({
1119
- target: z5.literal("getDeployment")
1141
+ target: z6.literal("getDeployment")
1120
1142
  })
1121
1143
  );
1122
- var providerCreatorSchema = z5.object({ login: z5.string() }).passthrough().nullable();
1123
- var providerDeploymentSchema = z5.object({
1124
- created_at: z5.string(),
1144
+ var providerCreatorSchema = z6.object({ login: z6.string() }).passthrough().nullable();
1145
+ var providerDeploymentSchema = z6.object({
1146
+ created_at: z6.string(),
1125
1147
  creator: providerCreatorSchema,
1126
- description: z5.string().nullable(),
1127
- environment: z5.string(),
1128
- id: z5.number(),
1129
- ref: z5.string(),
1148
+ description: z6.string().nullable(),
1149
+ environment: z6.string(),
1150
+ id: z6.number(),
1151
+ ref: z6.string(),
1130
1152
  sha: commitShaSchema,
1131
- updated_at: z5.string()
1153
+ updated_at: z6.string()
1132
1154
  }).passthrough();
1133
- var providerStatusSchema = z5.object({
1134
- created_at: z5.string(),
1155
+ var providerStatusSchema = z6.object({
1156
+ created_at: z6.string(),
1135
1157
  creator: providerCreatorSchema,
1136
- description: z5.string().nullable().optional(),
1137
- environment_url: z5.string().nullable().optional(),
1138
- id: z5.number(),
1139
- log_url: z5.string().nullable().optional(),
1140
- state: z5.string()
1158
+ description: z6.string().nullable().optional(),
1159
+ environment_url: z6.string().nullable().optional(),
1160
+ id: z6.number(),
1161
+ log_url: z6.string().nullable().optional(),
1162
+ state: z6.string()
1141
1163
  }).passthrough();
1142
- function parseRepo4(value) {
1143
- const parts = value.split("/").map((part) => part.trim());
1144
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
1145
- throw new PluginToolInputError5('repo must use "owner/name" format');
1146
- }
1147
- return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
1148
- }
1149
- async function readJson2(response) {
1150
- const text2 = await response.text();
1151
- if (!text2) return void 0;
1152
- try {
1153
- return JSON.parse(text2);
1154
- } catch {
1155
- return text2;
1156
- }
1157
- }
1158
1164
  function throwLookupError(target, status, body) {
1159
1165
  const message = `GitHub ${target} lookup failed with HTTP ${status}`;
1160
1166
  const hasValidationErrors = body !== null && typeof body === "object" && !Array.isArray(body) && Array.isArray(body.errors) && body.errors.length > 0;
1161
1167
  if (target === "deployment" && (status === 404 || status === 422 && hasValidationErrors)) {
1162
- throw new PluginToolInputError5(message);
1168
+ throw new PluginToolInputError6(message);
1163
1169
  }
1164
1170
  throw new Error(message);
1165
1171
  }
1166
- function repositoryUrl(repo, path) {
1167
- return `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/${path}`;
1168
- }
1169
1172
  function createGitHubGetDeploymentTool(ctx) {
1170
1173
  return definePluginTool4({
1171
1174
  annotations: {
@@ -1178,57 +1181,31 @@ function createGitHubGetDeploymentTool(ctx) {
1178
1181
  inputSchema: inputSchema3,
1179
1182
  outputSchema: outputSchema3,
1180
1183
  async execute(input) {
1181
- const repo = parseRepo4(input.repo);
1184
+ const repo = parseRepo(input.repo);
1182
1185
  const commitSha = input.commit_sha.toLowerCase();
1183
- const deploymentsUrl = new URL(repositoryUrl(repo, "deployments"));
1184
- deploymentsUrl.searchParams.set("sha", commitSha);
1186
+ const deploymentsQuery = new URLSearchParams({ sha: commitSha });
1185
1187
  if (input.environment) {
1186
- deploymentsUrl.searchParams.set("environment", input.environment);
1188
+ deploymentsQuery.set("environment", input.environment);
1187
1189
  }
1188
- deploymentsUrl.searchParams.set("per_page", "1");
1189
- const deploymentsResponse = await ctx.egress.fetch({
1190
- provider: "github",
1190
+ deploymentsQuery.set("per_page", "1");
1191
+ const deployments = await githubApi(ctx.egress, {
1191
1192
  operation: "github.deployment.list",
1192
- request: new Request(deploymentsUrl, {
1193
- headers: {
1194
- Accept: "application/vnd.github+json",
1195
- "X-GitHub-Api-Version": "2022-11-28"
1196
- }
1197
- })
1193
+ path: `${repoPath(repo)}/deployments?${deploymentsQuery}`
1198
1194
  });
1199
- const deploymentsBody = await readJson2(deploymentsResponse);
1200
- if (!deploymentsResponse.ok) {
1201
- throwLookupError(
1202
- "deployment",
1203
- deploymentsResponse.status,
1204
- deploymentsBody
1205
- );
1195
+ if (!deployments.ok) {
1196
+ throwLookupError("deployment", deployments.status, deployments.body);
1206
1197
  }
1207
- const providerDeployment = z5.array(providerDeploymentSchema).parse(deploymentsBody)[0];
1198
+ const providerDeployment = z6.array(providerDeploymentSchema).parse(deployments.body)[0];
1208
1199
  let deployment = null;
1209
1200
  if (providerDeployment) {
1210
- const statusesResponse = await ctx.egress.fetch({
1211
- provider: "github",
1201
+ const statuses = await githubApi(ctx.egress, {
1212
1202
  operation: "github.deployment-status.list",
1213
- request: new Request(
1214
- `${repositoryUrl(repo, `deployments/${providerDeployment.id}/statuses`)}?per_page=1`,
1215
- {
1216
- headers: {
1217
- Accept: "application/vnd.github+json",
1218
- "X-GitHub-Api-Version": "2022-11-28"
1219
- }
1220
- }
1221
- )
1203
+ path: `${repoPath(repo)}/deployments/${providerDeployment.id}/statuses?per_page=1`
1222
1204
  });
1223
- const statusesBody = await readJson2(statusesResponse);
1224
- if (!statusesResponse.ok) {
1225
- throwLookupError(
1226
- "deployment status",
1227
- statusesResponse.status,
1228
- statusesBody
1229
- );
1205
+ if (!statuses.ok) {
1206
+ throwLookupError("deployment status", statuses.status, statuses.body);
1230
1207
  }
1231
- const providerStatus = z5.array(providerStatusSchema).parse(statusesBody)[0];
1208
+ const providerStatus = z6.array(providerStatusSchema).parse(statuses.body)[0];
1232
1209
  deployment = {
1233
1210
  created_at: providerDeployment.created_at,
1234
1211
  creator: providerDeployment.creator?.login ?? null,
@@ -1276,14 +1253,14 @@ import {
1276
1253
  objectFactsSchema as objectFactsSchema2,
1277
1254
  definePluginTool as definePluginTool5,
1278
1255
  EgressAuthRequired as EgressAuthRequired2,
1279
- PluginToolInputError as PluginToolInputError6,
1256
+ PluginToolInputError as PluginToolInputError7,
1280
1257
  pluginToolOutputSchema as pluginToolOutputSchema5,
1281
1258
  watchResultSchema,
1282
1259
  subscribableResourceSchema as subscribableResourceSchema3
1283
1260
  } from "@sentry/junior-plugin-api";
1284
1261
  import { Type as Type2 } from "@sinclair/typebox";
1285
1262
  import { Value as Value2 } from "@sinclair/typebox/value";
1286
- import { z as z8 } from "zod";
1263
+ import * as z9 from "zod";
1287
1264
 
1288
1265
  // src/pull-request-requesters/store.ts
1289
1266
  import { and, asc, eq, inArray, lt } from "drizzle-orm";
@@ -1298,18 +1275,18 @@ import {
1298
1275
  text,
1299
1276
  timestamp
1300
1277
  } from "drizzle-orm/pg-core";
1301
- import { z as z6 } from "zod";
1302
- var githubPullRequestStateSchema = z6.enum([
1278
+ import * as z7 from "zod";
1279
+ var githubPullRequestStateSchema = z7.enum([
1303
1280
  "closed_unmerged",
1304
1281
  "merged",
1305
1282
  "open"
1306
1283
  ]);
1307
- var githubPullRequestCommitCompositionSchema = z6.enum([
1284
+ var githubPullRequestCommitCompositionSchema = z7.enum([
1308
1285
  "junior_only",
1309
1286
  "mixed"
1310
1287
  ]);
1311
- var githubIssueStateSchema = z6.enum(["closed", "open"]);
1312
- var githubIssueStateReasonSchema = z6.enum([
1288
+ var githubIssueStateSchema = z7.enum(["closed", "open"]);
1289
+ var githubIssueStateReasonSchema = z7.enum([
1313
1290
  "completed",
1314
1291
  "duplicate",
1315
1292
  "not_planned",
@@ -1470,34 +1447,31 @@ async function listGitHubPullRequestOpeners(db, input) {
1470
1447
  }
1471
1448
 
1472
1449
  // src/tools/stack-pull-request.ts
1473
- import { z as z7 } from "zod";
1450
+ import * as z8 from "zod";
1474
1451
  var MAX_STACK_DEPTH = 10;
1475
- var GITHUB_HEADERS = {
1476
- Accept: "application/vnd.github+json",
1477
- "X-GitHub-Api-Version": "2026-03-10"
1478
- };
1479
- var stackTargetSchema = z7.object({
1480
- number: z7.number().int().positive(),
1481
- head: z7.object({
1482
- repo: z7.object({ full_name: z7.string().min(1) }).nullable()
1452
+ var GITHUB_STACKS_API_VERSION = "2026-03-10";
1453
+ var stackTargetSchema = z8.object({
1454
+ number: z8.number().int().positive(),
1455
+ head: z8.object({
1456
+ repo: z8.object({ full_name: z8.string().min(1) }).nullable()
1483
1457
  }),
1484
- base: z7.object({
1485
- ref: z7.string().min(1),
1486
- repo: z7.object({
1487
- default_branch: z7.string().min(1),
1488
- full_name: z7.string().min(1)
1458
+ base: z8.object({
1459
+ ref: z8.string().min(1),
1460
+ repo: z8.object({
1461
+ default_branch: z8.string().min(1),
1462
+ full_name: z8.string().min(1)
1489
1463
  })
1490
1464
  })
1491
1465
  });
1492
- var openPullRequestsSchema = z7.array(
1493
- z7.object({
1494
- number: z7.number().int().positive(),
1495
- base: z7.object({ ref: z7.string().min(1) })
1466
+ var openPullRequestsSchema = z8.array(
1467
+ z8.object({
1468
+ number: z8.number().int().positive(),
1469
+ base: z8.object({ ref: z8.string().min(1) })
1496
1470
  })
1497
1471
  );
1498
- var stackSchema = z7.object({
1499
- number: z7.number().int().positive(),
1500
- pull_requests: z7.array(z7.object({ number: z7.number().int().positive() }))
1472
+ var stackSchema = z8.object({
1473
+ number: z8.number().int().positive(),
1474
+ pull_requests: z8.array(z8.object({ number: z8.number().int().positive() }))
1501
1475
  });
1502
1476
  async function stackGitHubPullRequest(ctx, target) {
1503
1477
  const repo = target.base.repo.full_name;
@@ -1505,16 +1479,13 @@ async function stackGitHubPullRequest(ctx, target) {
1505
1479
  return void 0;
1506
1480
  }
1507
1481
  const [owner, name] = repo.split("/");
1508
- const api = `https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`;
1509
- const github = async (operation, url, schema, body) => {
1510
- const response = await ctx.egress.fetch({
1511
- provider: "github",
1482
+ const api = repoPath({ owner, name });
1483
+ const github = async (operation, path, schema, body) => {
1484
+ const response = await githubApi(ctx.egress, {
1485
+ apiVersion: GITHUB_STACKS_API_VERSION,
1512
1486
  operation,
1513
- request: new Request(url, {
1514
- method: body === void 0 ? "GET" : "POST",
1515
- headers: body === void 0 ? GITHUB_HEADERS : { ...GITHUB_HEADERS, "Content-Type": "application/json" },
1516
- ...body === void 0 ? void 0 : { body: JSON.stringify(body) }
1517
- })
1487
+ path,
1488
+ ...body === void 0 ? void 0 : { method: "POST", body }
1518
1489
  });
1519
1490
  if (!response.ok) {
1520
1491
  ctx.log.warn("github.pull_request.stack_after_create.rejected", {
@@ -1525,7 +1496,7 @@ async function stackGitHubPullRequest(ctx, target) {
1525
1496
  });
1526
1497
  return void 0;
1527
1498
  }
1528
- return schema.parse(await response.json());
1499
+ return schema.parse(response.body);
1529
1500
  };
1530
1501
  const result = (stack) => ({
1531
1502
  number: stack.number,
@@ -1546,7 +1517,7 @@ async function stackGitHubPullRequest(ctx, target) {
1546
1517
  const stacks = await github(
1547
1518
  "github.stack.read",
1548
1519
  `${api}/stacks?pull_request=${parent.number}`,
1549
- z7.array(stackSchema)
1520
+ z8.array(stackSchema)
1550
1521
  );
1551
1522
  if (!stacks) return void 0;
1552
1523
  const stack = stacks[0];
@@ -1621,15 +1592,15 @@ var createPullRequestInputSchema = Type2.Object(
1621
1592
  },
1622
1593
  { additionalProperties: false }
1623
1594
  );
1624
- var createPullRequestToolInputSchema = z8.object({
1625
- repo: z8.string().describe('Repository in "owner/name" format.'),
1626
- title: z8.string().describe("Pull request title."),
1627
- head: z8.string().describe("Head branch or owner:branch ref."),
1628
- base: z8.string().describe("Base branch."),
1629
- body: z8.string().describe(
1595
+ var createPullRequestToolInputSchema = z9.object({
1596
+ repo: z9.string().describe('Repository in "owner/name" format.'),
1597
+ title: z9.string().describe("Pull request title."),
1598
+ head: z9.string().describe("Head branch or owner:branch ref."),
1599
+ base: z9.string().describe("Base branch."),
1600
+ body: z9.string().describe(
1630
1601
  "Pull request body. The runtime appends the conversation footer."
1631
1602
  ).optional(),
1632
- draft: z8.boolean().describe("Whether to open the pull request as a draft.").optional()
1603
+ draft: z9.boolean().describe("Whether to open the pull request as a draft.").optional()
1633
1604
  }).strict();
1634
1605
  var createPullRequestStateSchema = Type2.Union([
1635
1606
  Type2.Object(
@@ -1654,86 +1625,33 @@ var createPullRequestStateSchema = Type2.Union([
1654
1625
  { additionalProperties: false }
1655
1626
  )
1656
1627
  ]);
1657
- var gitHubPullRequestDataSchema = z8.object({
1658
- number: z8.number(),
1659
- url: z8.string(),
1660
- stack: z8.object({ number: z8.number(), pull_requests: z8.array(z8.number()) }).optional(),
1628
+ var gitHubPullRequestDataSchema = z9.object({
1629
+ number: z9.number(),
1630
+ url: z9.string(),
1631
+ stack: z9.object({ number: z9.number(), pull_requests: z9.array(z9.number()) }).optional(),
1661
1632
  subscribable: subscribableResourceSchema3.optional(),
1662
1633
  subscription: watchResultSchema.optional()
1663
1634
  });
1664
1635
  var gitHubPullRequestOutputSchema = pluginToolOutputSchema5.merge(
1665
1636
  gitHubPullRequestDataSchema.extend({
1666
- target: z8.literal("createPullRequest")
1637
+ target: z9.literal("createPullRequest")
1667
1638
  })
1668
1639
  );
1669
1640
  function parseCreatePullRequestInput(input) {
1670
1641
  try {
1671
1642
  return Value2.Parse(createPullRequestInputSchema, input);
1672
1643
  } catch (error) {
1673
- throw new PluginToolInputError6("Invalid GitHub createPullRequest input.", {
1644
+ throw new PluginToolInputError7("Invalid GitHub createPullRequest input.", {
1674
1645
  cause: error
1675
1646
  });
1676
1647
  }
1677
1648
  }
1678
1649
  function nonEmptyString3(value, name) {
1679
1650
  if (!value?.trim()) {
1680
- throw new PluginToolInputError6(`${name} is required`);
1651
+ throw new PluginToolInputError7(`${name} is required`);
1681
1652
  }
1682
1653
  return value.trim();
1683
1654
  }
1684
- function parseRepo5(value) {
1685
- const repo = nonEmptyString3(value, "repo");
1686
- const parts = repo.split("/");
1687
- if (parts.length !== 2 || !parts[0]?.trim() || !parts[1]?.trim()) {
1688
- throw new PluginToolInputError6('repo must use "owner/name" format');
1689
- }
1690
- return {
1691
- owner: parts[0].trim(),
1692
- name: parts[1].trim()
1693
- };
1694
- }
1695
- async function readJsonResponse2(response) {
1696
- const text2 = await response.text();
1697
- if (!text2) {
1698
- return void 0;
1699
- }
1700
- try {
1701
- return JSON.parse(text2);
1702
- } catch {
1703
- return text2;
1704
- }
1705
- }
1706
- function githubApiErrorMessage2(payload) {
1707
- if (payload && typeof payload === "object" && !Array.isArray(payload)) {
1708
- const record = payload;
1709
- const message = record.message;
1710
- if (typeof message === "string") {
1711
- const details = githubApiErrorDetails(record);
1712
- return details ? `${message}: ${details}` : message;
1713
- }
1714
- }
1715
- if (typeof payload === "string" && payload.trim()) {
1716
- return payload.trim();
1717
- }
1718
- return "GitHub request failed";
1719
- }
1720
- function githubApiErrorDetails(payload) {
1721
- const errors = payload.errors;
1722
- if (!Array.isArray(errors)) {
1723
- return void 0;
1724
- }
1725
- const details = errors.map((error) => {
1726
- if (!error || typeof error !== "object" || Array.isArray(error)) {
1727
- return void 0;
1728
- }
1729
- const fields = ["resource", "field", "code", "message"].map((name) => {
1730
- const value = error[name];
1731
- return typeof value === "string" && value.trim() ? `${name}=${value.trim()}` : void 0;
1732
- }).filter((value) => value !== void 0);
1733
- return fields.length ? fields.join(" ") : void 0;
1734
- }).filter((value) => value !== void 0);
1735
- return details.length ? details.join("; ") : void 0;
1736
- }
1737
1655
  function createPullRequestState(value) {
1738
1656
  if (value === void 0) {
1739
1657
  return void 0;
@@ -1756,7 +1674,7 @@ function isDefinitiveGitHubPullRequestCreateRejection(error) {
1756
1674
  return [400, 401, 404, 410, 422].includes(error.status);
1757
1675
  }
1758
1676
  function createGitHubPullRequestRequest(conversationId, input, ctx, requester, dashboardUrl) {
1759
- const repo = parseRepo5(input.repo);
1677
+ const repo = parseRepo(input.repo);
1760
1678
  const payload = {
1761
1679
  title: nonEmptyString3(input.title, "title"),
1762
1680
  head: nonEmptyString3(input.head, "head"),
@@ -1768,31 +1686,18 @@ function createGitHubPullRequestRequest(conversationId, input, ctx, requester, d
1768
1686
  ),
1769
1687
  ...input.draft !== void 0 ? { draft: input.draft } : void 0
1770
1688
  };
1771
- return new Request(
1772
- `https://api.github.com/repos/${encodeURIComponent(
1773
- repo.owner
1774
- )}/${encodeURIComponent(repo.name)}/pulls`,
1775
- {
1776
- method: "POST",
1777
- headers: {
1778
- Accept: "application/vnd.github+json",
1779
- "Content-Type": "application/json",
1780
- "X-GitHub-Api-Version": "2022-11-28"
1781
- },
1782
- body: JSON.stringify(payload)
1783
- }
1784
- );
1689
+ return { path: `${repoPath(repo)}/pulls`, body: payload };
1785
1690
  }
1786
1691
  async function createGitHubPullRequest(ctx, request) {
1787
- const response = await ctx.egress.fetch({
1788
- provider: "github",
1692
+ const response = await githubApi(ctx.egress, {
1789
1693
  operation: "github.pull.create",
1790
- request
1694
+ method: "POST",
1695
+ ...request
1791
1696
  });
1792
- const parsed = await readJsonResponse2(response);
1697
+ const parsed = response.body;
1793
1698
  if (!response.ok) {
1794
1699
  throw new GitHubPullRequestCreateRejectedError(
1795
- `GitHub pull request creation failed with HTTP ${response.status}: ${githubApiErrorMessage2(
1700
+ `GitHub pull request creation failed with HTTP ${response.status}: ${githubErrorMessage(
1796
1701
  parsed
1797
1702
  )}`,
1798
1703
  response.status
@@ -1822,35 +1727,25 @@ async function createGitHubPullRequest(ctx, request) {
1822
1727
  async function recordOpener(ctx, input, state, requester) {
1823
1728
  const { conversationId, identityId } = requester;
1824
1729
  if (!identityId) return;
1825
- const repo = parseRepo5(input.repo);
1730
+ const repo = parseRepo(input.repo);
1826
1731
  await recordGitHubPullRequestOpener(ctx.db, {
1827
1732
  conversationId,
1828
1733
  createdAt: new Date(state.createdAtMs),
1829
1734
  identityId,
1830
1735
  number: state.number,
1831
- repositoryFullName: `${repo.owner}/${repo.name}`
1736
+ repositoryFullName: repo.ref
1832
1737
  });
1833
1738
  }
1834
1739
  async function assignPullRequestRequester(ctx, input, result, requester) {
1835
1740
  const assignee = linkedGitHubLogin(requester?.user);
1836
1741
  if (!assignee) return;
1837
1742
  try {
1838
- const repo = parseRepo5(input.repo);
1839
- const response = await ctx.egress.fetch({
1840
- provider: "github",
1743
+ const repo = parseRepo(input.repo);
1744
+ const response = await githubApi(ctx.egress, {
1841
1745
  operation: "github.pull.assign",
1842
- request: new Request(
1843
- `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/issues/${result.number}/assignees`,
1844
- {
1845
- method: "POST",
1846
- headers: {
1847
- Accept: "application/vnd.github+json",
1848
- "Content-Type": "application/json",
1849
- "X-GitHub-Api-Version": "2022-11-28"
1850
- },
1851
- body: JSON.stringify({ assignees: [assignee] })
1852
- }
1853
- )
1746
+ method: "POST",
1747
+ path: `${repoPath(repo)}/issues/${result.number}/assignees`,
1748
+ body: { assignees: [assignee] }
1854
1749
  });
1855
1750
  if (!response.ok) {
1856
1751
  ctx.log.warn("github.pull_request.assign_after_create.rejected", {
@@ -1868,7 +1763,7 @@ async function assignPullRequestRequester(ctx, input, result, requester) {
1868
1763
  }
1869
1764
  }
1870
1765
  function gitHubPullRequestToolResult(input, result, canSubscribe, omitSuggestedEvents) {
1871
- const repo = parseRepo5(input.repo);
1766
+ const repo = parseRepo(input.repo);
1872
1767
  const subscribable = gitHubPullRequestSubscribable({
1873
1768
  canSubscribe,
1874
1769
  number: result.number,
@@ -2062,49 +1957,33 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
2062
1957
  // src/tools/get-pull-request.ts
2063
1958
  import {
2064
1959
  definePluginTool as definePluginTool6,
2065
- PluginToolInputError as PluginToolInputError7,
1960
+ PluginToolInputError as PluginToolInputError8,
2066
1961
  pluginToolOutputSchema as pluginToolOutputSchema6
2067
1962
  } from "@sentry/junior-plugin-api";
2068
- import { z as z9 } from "zod";
1963
+ import * as z10 from "zod";
2069
1964
  import { subscribableResourceSchema as subscribableResourceSchema4 } from "@sentry/junior-plugin-api";
2070
- var commitShaSchema2 = z9.string().regex(/^[0-9a-f]{40}$/i);
2071
- var inputSchema4 = z9.object({
2072
- repo: z9.string().describe('Repository in "owner/name" format.'),
2073
- number: z9.number().int().positive().describe("Pull request number.")
1965
+ var commitShaSchema2 = z10.string().regex(/^[0-9a-f]{40}$/i);
1966
+ var inputSchema4 = z10.object({
1967
+ repo: z10.string().describe('Repository in "owner/name" format.'),
1968
+ number: z10.number().int().positive().describe("Pull request number.")
2074
1969
  }).strict();
2075
- var pullRequestSchema = z9.object({
2076
- base: z9.string(),
2077
- draft: z9.boolean(),
2078
- head: z9.string(),
1970
+ var pullRequestSchema = z10.object({
1971
+ base: z10.string(),
1972
+ draft: z10.boolean(),
1973
+ head: z10.string(),
2079
1974
  head_sha: commitShaSchema2,
2080
- merged: z9.boolean(),
2081
- number: z9.number(),
2082
- state: z9.string(),
1975
+ merged: z10.boolean(),
1976
+ number: z10.number(),
1977
+ state: z10.string(),
2083
1978
  subscribable: subscribableResourceSchema4.optional(),
2084
- title: z9.string(),
2085
- url: z9.string()
1979
+ title: z10.string(),
1980
+ url: z10.string()
2086
1981
  });
2087
1982
  var outputSchema4 = pluginToolOutputSchema6.merge(
2088
1983
  pullRequestSchema.extend({
2089
- target: z9.literal("getPullRequest")
1984
+ target: z10.literal("getPullRequest")
2090
1985
  })
2091
1986
  );
2092
- function parseRepo6(value) {
2093
- const parts = value.split("/").map((part) => part.trim());
2094
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
2095
- throw new PluginToolInputError7('repo must use "owner/name" format');
2096
- }
2097
- return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
2098
- }
2099
- async function readJson3(response) {
2100
- const text2 = await response.text();
2101
- if (!text2) return void 0;
2102
- try {
2103
- return JSON.parse(text2);
2104
- } catch {
2105
- return text2;
2106
- }
2107
- }
2108
1987
  function createGitHubGetPullRequestTool(ctx) {
2109
1988
  return definePluginTool6({
2110
1989
  annotations: {
@@ -2117,38 +1996,28 @@ function createGitHubGetPullRequestTool(ctx) {
2117
1996
  inputSchema: inputSchema4,
2118
1997
  outputSchema: outputSchema4,
2119
1998
  async execute(input) {
2120
- const repo = parseRepo6(input.repo);
2121
- const response = await ctx.egress.fetch({
2122
- provider: "github",
1999
+ const repo = parseRepo(input.repo);
2000
+ const response = await githubApi(ctx.egress, {
2123
2001
  operation: "github.pull.get",
2124
- request: new Request(
2125
- `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/pulls/${input.number}`,
2126
- {
2127
- headers: {
2128
- Accept: "application/vnd.github+json",
2129
- "X-GitHub-Api-Version": "2022-11-28"
2130
- }
2131
- }
2132
- )
2002
+ path: `${repoPath(repo)}/pulls/${input.number}`
2133
2003
  });
2134
- const parsed = await readJson3(response);
2135
2004
  if (!response.ok) {
2136
2005
  const message = `GitHub pull request lookup failed with HTTP ${response.status}`;
2137
2006
  if (response.status === 404) {
2138
- throw new PluginToolInputError7(message);
2007
+ throw new PluginToolInputError8(message);
2139
2008
  }
2140
2009
  throw new Error(message);
2141
2010
  }
2142
- const providerResult = z9.object({
2143
- base: z9.object({ ref: z9.string() }),
2144
- draft: z9.boolean(),
2145
- head: z9.object({ ref: z9.string(), sha: commitShaSchema2 }),
2146
- html_url: z9.string(),
2147
- merged: z9.boolean().optional().default(false),
2148
- number: z9.number(),
2149
- state: z9.string(),
2150
- title: z9.string()
2151
- }).parse(parsed);
2011
+ const providerResult = z10.object({
2012
+ base: z10.object({ ref: z10.string() }),
2013
+ draft: z10.boolean(),
2014
+ head: z10.object({ ref: z10.string(), sha: commitShaSchema2 }),
2015
+ html_url: z10.string(),
2016
+ merged: z10.boolean().optional().default(false),
2017
+ number: z10.number(),
2018
+ state: z10.string(),
2019
+ title: z10.string()
2020
+ }).parse(response.body);
2152
2021
  const subscribable = gitHubPullRequestSubscribable({
2153
2022
  canSubscribe: ctx.events.canSubscribe,
2154
2023
  number: providerResult.number,
@@ -2175,7 +2044,7 @@ function createGitHubGetPullRequestTool(ctx) {
2175
2044
  url: data.url,
2176
2045
  objectType: "code_change",
2177
2046
  status: data.merged ? "merged" : data.state === "open" && data.draft ? "draft" : data.state,
2178
- ...githubObjectFacts("code_change", parsed)
2047
+ ...githubObjectFacts("code_change", response.body)
2179
2048
  })
2180
2049
  ],
2181
2050
  target: "getPullRequest",
@@ -2188,69 +2057,49 @@ function createGitHubGetPullRequestTool(ctx) {
2188
2057
  // src/tools/get-release.ts
2189
2058
  import {
2190
2059
  definePluginTool as definePluginTool7,
2191
- PluginToolInputError as PluginToolInputError8,
2192
2060
  pluginToolOutputSchema as pluginToolOutputSchema7,
2193
2061
  subscribableResourceSchema as subscribableResourceSchema5
2194
2062
  } from "@sentry/junior-plugin-api";
2195
- import { z as z10 } from "zod";
2196
- var inputSchema5 = z10.object({
2197
- repo: z10.string().describe('Repository in "owner/name" format.'),
2198
- tag: z10.string().trim().min(1).describe(
2063
+ import * as z11 from "zod";
2064
+ var inputSchema5 = z11.object({
2065
+ repo: z11.string().describe('Repository in "owner/name" format.'),
2066
+ tag: z11.string().trim().min(1).describe(
2199
2067
  "Optional release tag name. Omit to inspect and watch every published release in the repository."
2200
2068
  ).optional()
2201
2069
  }).strict();
2202
- var releaseSchema = z10.object({
2203
- created_at: z10.string(),
2204
- draft: z10.boolean(),
2205
- html_url: z10.string(),
2206
- id: z10.number(),
2207
- name: z10.string().nullable(),
2208
- prerelease: z10.boolean(),
2209
- published_at: z10.string().nullable(),
2210
- tag_name: z10.string(),
2211
- target_commitish: z10.string()
2070
+ var releaseSchema = z11.object({
2071
+ created_at: z11.string(),
2072
+ draft: z11.boolean(),
2073
+ html_url: z11.string(),
2074
+ id: z11.number(),
2075
+ name: z11.string().nullable(),
2076
+ prerelease: z11.boolean(),
2077
+ published_at: z11.string().nullable(),
2078
+ tag_name: z11.string(),
2079
+ target_commitish: z11.string()
2212
2080
  }).strict();
2213
- var releaseSourceSchema = z10.object({
2081
+ var releaseSourceSchema = z11.object({
2214
2082
  release: releaseSchema.nullable(),
2215
- repo: z10.string(),
2083
+ repo: z11.string(),
2216
2084
  subscribable: subscribableResourceSchema5.optional(),
2217
- tag: z10.string().nullable()
2085
+ tag: z11.string().nullable()
2218
2086
  }).strict();
2219
2087
  var outputSchema5 = pluginToolOutputSchema7.merge(
2220
2088
  releaseSourceSchema.extend({
2221
- target: z10.literal("getRelease")
2089
+ target: z11.literal("getRelease")
2222
2090
  })
2223
2091
  );
2224
- var providerReleaseSchema = z10.object({
2225
- created_at: z10.string(),
2226
- draft: z10.boolean(),
2227
- html_url: z10.string(),
2228
- id: z10.number(),
2229
- name: z10.string().nullable(),
2230
- prerelease: z10.boolean(),
2231
- published_at: z10.string().nullable(),
2232
- tag_name: z10.string(),
2233
- target_commitish: z10.string()
2092
+ var providerReleaseSchema = z11.object({
2093
+ created_at: z11.string(),
2094
+ draft: z11.boolean(),
2095
+ html_url: z11.string(),
2096
+ id: z11.number(),
2097
+ name: z11.string().nullable(),
2098
+ prerelease: z11.boolean(),
2099
+ published_at: z11.string().nullable(),
2100
+ tag_name: z11.string(),
2101
+ target_commitish: z11.string()
2234
2102
  }).passthrough();
2235
- function parseRepo7(value) {
2236
- const parts = value.split("/").map((part) => part.trim());
2237
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
2238
- throw new PluginToolInputError8('repo must use "owner/name" format');
2239
- }
2240
- return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
2241
- }
2242
- async function readJson4(response) {
2243
- const text2 = await response.text();
2244
- if (!text2) return void 0;
2245
- try {
2246
- return JSON.parse(text2);
2247
- } catch {
2248
- return text2;
2249
- }
2250
- }
2251
- function repositoryUrl2(repo, path) {
2252
- return `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/${path}`;
2253
- }
2254
2103
  function mapRelease(providerRelease) {
2255
2104
  return {
2256
2105
  created_at: providerRelease.created_at,
@@ -2276,45 +2125,28 @@ function createGitHubGetReleaseTool(ctx) {
2276
2125
  inputSchema: inputSchema5,
2277
2126
  outputSchema: outputSchema5,
2278
2127
  async execute(input) {
2279
- const repo = parseRepo7(input.repo);
2128
+ const repo = parseRepo(input.repo);
2280
2129
  const tag = input.tag?.trim() || void 0;
2281
2130
  let release = null;
2282
2131
  if (tag) {
2283
- const response = await ctx.egress.fetch({
2284
- provider: "github",
2132
+ const response = await githubApi(ctx.egress, {
2285
2133
  operation: "github.release.get",
2286
- request: new Request(
2287
- repositoryUrl2(repo, `releases/tags/${encodeURIComponent(tag)}`),
2288
- {
2289
- headers: {
2290
- Accept: "application/vnd.github+json",
2291
- "X-GitHub-Api-Version": "2022-11-28"
2292
- }
2293
- }
2294
- )
2134
+ path: `${repoPath(repo)}/releases/tags/${encodeURIComponent(tag)}`
2295
2135
  });
2296
- const body = await readJson4(response);
2297
2136
  if (response.ok) {
2298
- release = mapRelease(providerReleaseSchema.parse(body));
2137
+ release = mapRelease(providerReleaseSchema.parse(response.body));
2299
2138
  } else if (response.status !== 404) {
2300
2139
  throw new Error(
2301
2140
  `GitHub release lookup failed with HTTP ${response.status}`
2302
2141
  );
2303
2142
  }
2304
2143
  } else {
2305
- const response = await ctx.egress.fetch({
2306
- provider: "github",
2144
+ const response = await githubApi(ctx.egress, {
2307
2145
  operation: "github.release.latest",
2308
- request: new Request(repositoryUrl2(repo, "releases/latest"), {
2309
- headers: {
2310
- Accept: "application/vnd.github+json",
2311
- "X-GitHub-Api-Version": "2022-11-28"
2312
- }
2313
- })
2146
+ path: `${repoPath(repo)}/releases/latest`
2314
2147
  });
2315
- const body = await readJson4(response);
2316
2148
  if (response.ok) {
2317
- release = mapRelease(providerReleaseSchema.parse(body));
2149
+ release = mapRelease(providerReleaseSchema.parse(response.body));
2318
2150
  } else if (response.status === 404) {
2319
2151
  release = null;
2320
2152
  } else {
@@ -2349,39 +2181,23 @@ import {
2349
2181
  pluginToolOutputSchema as pluginToolOutputSchema8,
2350
2182
  subscribableResourceSchema as subscribableResourceSchema6
2351
2183
  } from "@sentry/junior-plugin-api";
2352
- import { z as z11 } from "zod";
2353
- var inputSchema6 = z11.object({
2354
- repo: z11.string().describe('Repository in "owner/name" format.')
2184
+ import * as z12 from "zod";
2185
+ var inputSchema6 = z12.object({
2186
+ repo: z12.string().describe('Repository in "owner/name" format.')
2355
2187
  }).strict();
2356
- var repositorySchema = z11.object({
2357
- default_branch: z11.string(),
2358
- description: z11.string().nullable(),
2359
- full_name: z11.string(),
2360
- private: z11.boolean(),
2188
+ var repositorySchema = z12.object({
2189
+ default_branch: z12.string(),
2190
+ description: z12.string().nullable(),
2191
+ full_name: z12.string(),
2192
+ private: z12.boolean(),
2361
2193
  subscribable: subscribableResourceSchema6.optional(),
2362
- url: z11.string()
2194
+ url: z12.string()
2363
2195
  });
2364
2196
  var outputSchema6 = pluginToolOutputSchema8.merge(
2365
2197
  repositorySchema.extend({
2366
- target: z11.literal("getRepository")
2198
+ target: z12.literal("getRepository")
2367
2199
  })
2368
2200
  );
2369
- function parseRepo8(value) {
2370
- const parts = value.split("/").map((part) => part.trim());
2371
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
2372
- throw new PluginToolInputError9('repo must use "owner/name" format');
2373
- }
2374
- return { owner: parts[0], name: parts[1] };
2375
- }
2376
- async function readJson5(response) {
2377
- const text2 = await response.text();
2378
- if (!text2) return void 0;
2379
- try {
2380
- return JSON.parse(text2);
2381
- } catch {
2382
- return text2;
2383
- }
2384
- }
2385
2201
  function createGitHubGetRepositoryTool(ctx) {
2386
2202
  return definePluginTool8({
2387
2203
  annotations: {
@@ -2394,33 +2210,23 @@ function createGitHubGetRepositoryTool(ctx) {
2394
2210
  inputSchema: inputSchema6,
2395
2211
  outputSchema: outputSchema6,
2396
2212
  async execute(input) {
2397
- const repo = parseRepo8(input.repo);
2398
- const response = await ctx.egress.fetch({
2399
- provider: "github",
2213
+ const repo = parseRepo(input.repo);
2214
+ const response = await githubApi(ctx.egress, {
2400
2215
  operation: "github.repository.get",
2401
- request: new Request(
2402
- `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}`,
2403
- {
2404
- headers: {
2405
- Accept: "application/vnd.github+json",
2406
- "X-GitHub-Api-Version": "2022-11-28"
2407
- }
2408
- }
2409
- )
2216
+ path: repoPath(repo)
2410
2217
  });
2411
- const parsed = await readJson5(response);
2412
2218
  if (!response.ok) {
2413
2219
  throw new PluginToolInputError9(
2414
2220
  `GitHub repository lookup failed with HTTP ${response.status}`
2415
2221
  );
2416
2222
  }
2417
- const providerResult = z11.object({
2418
- default_branch: z11.string(),
2419
- description: z11.string().nullable(),
2420
- full_name: z11.string(),
2421
- html_url: z11.string(),
2422
- private: z11.boolean()
2423
- }).parse(parsed);
2223
+ const providerResult = z12.object({
2224
+ default_branch: z12.string(),
2225
+ description: z12.string().nullable(),
2226
+ full_name: z12.string(),
2227
+ html_url: z12.string(),
2228
+ private: z12.boolean()
2229
+ }).parse(response.body);
2424
2230
  const subscribable = gitHubRepositorySubscribable({
2425
2231
  canSubscribe: ctx.events.canSubscribe,
2426
2232
  repo: providerResult.full_name
@@ -2446,24 +2252,24 @@ import {
2446
2252
  definePluginTool as definePluginTool9,
2447
2253
  pluginToolOutputSchema as pluginToolOutputSchema9
2448
2254
  } from "@sentry/junior-plugin-api";
2449
- import { z as z13 } from "zod";
2255
+ import * as z14 from "zod";
2450
2256
 
2451
2257
  // src/github-status.ts
2452
- import { z as z12 } from "zod";
2258
+ import * as z13 from "zod";
2453
2259
  var GITHUB_STATUS_INCIDENTS_URL = "https://www.githubstatus.com/api/v2/incidents.json";
2454
2260
  var GITHUB_STATUS_TTL_MS = 60 * 1e3;
2455
2261
  var GITHUB_STATUS_TIMEOUT_MS = 5e3;
2456
- var incidentsResponseSchema = z12.object({
2457
- incidents: z12.array(
2458
- z12.object({
2459
- components: z12.array(z12.object({ name: z12.string() })).default([]),
2460
- created_at: z12.string(),
2461
- impact: z12.string(),
2462
- name: z12.string(),
2463
- resolved_at: z12.string().nullable(),
2464
- shortlink: z12.string(),
2465
- started_at: z12.string().nullable().optional(),
2466
- status: z12.string()
2262
+ var incidentsResponseSchema = z13.object({
2263
+ incidents: z13.array(
2264
+ z13.object({
2265
+ components: z13.array(z13.object({ name: z13.string() })).default([]),
2266
+ created_at: z13.string(),
2267
+ impact: z13.string(),
2268
+ name: z13.string(),
2269
+ resolved_at: z13.string().nullable(),
2270
+ shortlink: z13.string(),
2271
+ started_at: z13.string().nullable().optional(),
2272
+ status: z13.string()
2467
2273
  })
2468
2274
  )
2469
2275
  });
@@ -2505,19 +2311,19 @@ async function loadGitHubStatusIncidents(cache, withinMs) {
2505
2311
 
2506
2312
  // src/tools/get-status.ts
2507
2313
  var RECENT_INCIDENT_MS = 24 * 60 * 60 * 1e3;
2508
- var inputSchema7 = z13.object({}).strict();
2509
- var incidentSchema = z13.object({
2510
- components: z13.array(z13.string()),
2511
- impact: z13.string(),
2512
- name: z13.string(),
2513
- resolved_at: z13.string().optional(),
2514
- started_at: z13.string(),
2515
- status: z13.string(),
2516
- url: z13.string()
2314
+ var inputSchema7 = z14.object({}).strict();
2315
+ var incidentSchema = z14.object({
2316
+ components: z14.array(z14.string()),
2317
+ impact: z14.string(),
2318
+ name: z14.string(),
2319
+ resolved_at: z14.string().optional(),
2320
+ started_at: z14.string(),
2321
+ status: z14.string(),
2322
+ url: z14.string()
2517
2323
  });
2518
2324
  var outputSchema7 = pluginToolOutputSchema9.extend({
2519
- target: z13.literal("getStatus"),
2520
- incidents: z13.array(incidentSchema)
2325
+ target: z14.literal("getStatus"),
2326
+ incidents: z14.array(incidentSchema)
2521
2327
  });
2522
2328
  function createGitHubGetStatusTool(ctx) {
2523
2329
  return definePluginTool9({
@@ -2557,60 +2363,36 @@ import {
2557
2363
  pluginToolOutputSchema as pluginToolOutputSchema10,
2558
2364
  subscribableResourceSchema as subscribableResourceSchema7
2559
2365
  } from "@sentry/junior-plugin-api";
2560
- import { z as z14 } from "zod";
2561
- var inputSchema8 = z14.object({
2562
- repo: z14.string().describe('Repository in "owner/name" format.'),
2563
- number: z14.number().int().positive().describe("Issue number."),
2564
- title: z14.string().trim().min(1).optional().describe("Replacement issue title."),
2565
- body: z14.string().optional().describe(
2366
+ import * as z15 from "zod";
2367
+ var inputSchema8 = z15.object({
2368
+ repo: z15.string().describe('Repository in "owner/name" format.'),
2369
+ number: z15.number().int().positive().describe("Issue number."),
2370
+ title: z15.string().trim().min(1).optional().describe("Replacement issue title."),
2371
+ body: z15.string().optional().describe(
2566
2372
  "Replacement issue body. The runtime appends requester attribution and the conversation footer."
2567
2373
  ),
2568
- state: z14.enum(["open", "closed"]).optional().describe("Replacement issue state.")
2374
+ state: z15.enum(["open", "closed"]).optional().describe("Replacement issue state.")
2569
2375
  }).strict().refine(
2570
2376
  ({ title, body, state }) => title !== void 0 || body !== void 0 || state !== void 0,
2571
2377
  { message: "At least one issue field must be provided." }
2572
2378
  );
2573
- var issueSchema = z14.object({
2574
- body: z14.string().nullable(),
2575
- number: z14.number(),
2576
- state: z14.string(),
2379
+ var issueSchema = z15.object({
2380
+ body: z15.string().nullable(),
2381
+ number: z15.number(),
2382
+ state: z15.string(),
2577
2383
  subscribable: subscribableResourceSchema7.optional(),
2578
- title: z14.string(),
2579
- url: z14.string()
2384
+ title: z15.string(),
2385
+ url: z15.string()
2580
2386
  });
2581
2387
  var outputSchema8 = pluginToolOutputSchema10.merge(
2582
2388
  issueSchema.extend({
2583
- target: z14.literal("updateIssue")
2389
+ target: z15.literal("updateIssue")
2584
2390
  })
2585
2391
  );
2586
2392
  function nonEmptyString4(value, name) {
2587
2393
  if (!value?.trim()) throw new PluginToolInputError10(`${name} is required`);
2588
2394
  return value.trim();
2589
2395
  }
2590
- function parseRepo9(value) {
2591
- const parts = value.split("/").map((part) => part.trim());
2592
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
2593
- throw new PluginToolInputError10('repo must use "owner/name" format');
2594
- }
2595
- return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
2596
- }
2597
- async function readJson6(response) {
2598
- const text2 = await response.text();
2599
- if (!text2) return void 0;
2600
- try {
2601
- return JSON.parse(text2);
2602
- } catch {
2603
- return text2;
2604
- }
2605
- }
2606
- function githubApiErrorMessage3(payload) {
2607
- if (payload && typeof payload === "object" && !Array.isArray(payload)) {
2608
- const message = payload.message;
2609
- if (typeof message === "string" && message.trim()) return message.trim();
2610
- }
2611
- if (typeof payload === "string" && payload.trim()) return payload.trim();
2612
- return "GitHub request failed";
2613
- }
2614
2396
  function createGitHubUpdateIssueTool(ctx) {
2615
2397
  return definePluginTool10({
2616
2398
  annotations: {
@@ -2630,7 +2412,11 @@ function createGitHubUpdateIssueTool(ctx) {
2630
2412
  });
2631
2413
  }
2632
2414
  const update = parsedInput.data;
2633
- const repo = parseRepo9(update.repo);
2415
+ const repo = parseRepo(update.repo);
2416
+ const currentBody = update.body !== void 0 ? await readGitHubBody(ctx.egress, {
2417
+ operation: "github.issue.get",
2418
+ path: `${repoPath(repo)}/issues/${update.number}`
2419
+ }) : void 0;
2634
2420
  const payload = {
2635
2421
  ...update.title !== void 0 ? { title: update.title } : void 0,
2636
2422
  ...update.body !== void 0 ? {
@@ -2638,7 +2424,8 @@ function createGitHubUpdateIssueTool(ctx) {
2638
2424
  appendGitHubRequesterAttribution(
2639
2425
  update.body,
2640
2426
  ctx,
2641
- await resolveGitHubRequester(ctx)
2427
+ await resolveGitHubRequester(ctx),
2428
+ currentBody
2642
2429
  ),
2643
2430
  nonEmptyString4(ctx.conversationId, "conversationId"),
2644
2431
  ctx.slack?.conversationLink?.url
@@ -2646,34 +2433,24 @@ function createGitHubUpdateIssueTool(ctx) {
2646
2433
  } : void 0,
2647
2434
  ...update.state !== void 0 ? { state: update.state } : void 0
2648
2435
  };
2649
- const response = await ctx.egress.fetch({
2650
- provider: "github",
2436
+ const response = await githubApi(ctx.egress, {
2651
2437
  operation: "github.issue.update",
2652
- request: new Request(
2653
- `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/issues/${update.number}`,
2654
- {
2655
- method: "PATCH",
2656
- headers: {
2657
- Accept: "application/vnd.github+json",
2658
- "Content-Type": "application/json",
2659
- "X-GitHub-Api-Version": "2022-11-28"
2660
- },
2661
- body: JSON.stringify(payload)
2662
- }
2663
- )
2438
+ method: "PATCH",
2439
+ path: `${repoPath(repo)}/issues/${update.number}`,
2440
+ body: payload
2664
2441
  });
2665
- const parsed = await readJson6(response);
2442
+ const parsed = response.body;
2666
2443
  if (!response.ok) {
2667
2444
  throw new Error(
2668
- `GitHub issue update failed with HTTP ${response.status}: ${githubApiErrorMessage3(parsed)}`
2445
+ `GitHub issue update failed with HTTP ${response.status}: ${githubErrorMessage(parsed)}`
2669
2446
  );
2670
2447
  }
2671
- const providerResult = z14.object({
2672
- body: z14.string().nullable().optional().default(null),
2673
- html_url: z14.string(),
2674
- number: z14.number(),
2675
- state: z14.string(),
2676
- title: z14.string()
2448
+ const providerResult = z15.object({
2449
+ body: z15.string().nullable().optional().default(null),
2450
+ html_url: z15.string(),
2451
+ number: z15.number(),
2452
+ state: z15.string(),
2453
+ title: z15.string()
2677
2454
  }).parse(parsed);
2678
2455
  const subscribable = gitHubIssueSubscribable({
2679
2456
  canSubscribe: ctx.events.canSubscribe,
@@ -2710,18 +2487,18 @@ import {
2710
2487
  PluginToolInputError as PluginToolInputError11,
2711
2488
  pluginToolOutputSchema as pluginToolOutputSchema11
2712
2489
  } from "@sentry/junior-plugin-api";
2713
- import { z as z15 } from "zod";
2490
+ import * as z16 from "zod";
2714
2491
  import { subscribableResourceSchema as subscribableResourceSchema8 } from "@sentry/junior-plugin-api";
2715
- var inputSchema9 = z15.object({
2716
- repo: z15.string().describe('Repository in "owner/name" format.'),
2717
- number: z15.number().int().positive().describe("Pull request number."),
2718
- title: z15.string().trim().min(1).optional().describe("Replacement pull request title."),
2719
- body: z15.string().optional().describe(
2492
+ var inputSchema9 = z16.object({
2493
+ repo: z16.string().describe('Repository in "owner/name" format.'),
2494
+ number: z16.number().int().positive().describe("Pull request number."),
2495
+ title: z16.string().trim().min(1).optional().describe("Replacement pull request title."),
2496
+ body: z16.string().optional().describe(
2720
2497
  "Replacement pull request body. The runtime appends requester attribution and the conversation footer."
2721
2498
  ),
2722
- base: z15.string().trim().min(1).optional().describe("Replacement base branch."),
2723
- state: z15.enum(["open", "closed"]).optional().describe("Replacement pull request state."),
2724
- draft: z15.boolean().optional().describe(
2499
+ base: z16.string().trim().min(1).optional().describe("Replacement base branch."),
2500
+ state: z16.enum(["open", "closed"]).optional().describe("Replacement pull request state."),
2501
+ draft: z16.boolean().optional().describe(
2725
2502
  "Set false to mark a draft pull request ready for review, or true to convert it back to a draft."
2726
2503
  )
2727
2504
  }).strict().refine(
@@ -2736,27 +2513,24 @@ var CONVERT_TO_DRAFT = {
2736
2513
  operationName: "ConvertPullRequestToDraft",
2737
2514
  query: "mutation ConvertPullRequestToDraft($id: ID!) { result: convertPullRequestToDraft(input: {pullRequestId: $id}) { pullRequest { isDraft } } }"
2738
2515
  };
2739
- var draftMutationResponseSchema = z15.object({
2740
- data: z15.object({
2741
- result: z15.object({ pullRequest: z15.object({ isDraft: z15.boolean() }) })
2516
+ var draftMutationResponseSchema = z16.object({
2517
+ data: z16.object({
2518
+ result: z16.object({ pullRequest: z16.object({ isDraft: z16.boolean() }) })
2742
2519
  })
2743
2520
  });
2744
- var graphqlErrorsSchema = z15.object({
2745
- errors: z15.array(z15.object({ message: z15.string() })).min(1)
2746
- });
2747
- var pullRequestSchema2 = z15.object({
2748
- base: z15.string(),
2749
- body: z15.string().nullable(),
2750
- draft: z15.boolean(),
2751
- number: z15.number(),
2752
- state: z15.string(),
2521
+ var pullRequestSchema2 = z16.object({
2522
+ base: z16.string(),
2523
+ body: z16.string().nullable(),
2524
+ draft: z16.boolean(),
2525
+ number: z16.number(),
2526
+ state: z16.string(),
2753
2527
  subscribable: subscribableResourceSchema8.optional(),
2754
- title: z15.string(),
2755
- url: z15.string()
2528
+ title: z16.string(),
2529
+ url: z16.string()
2756
2530
  });
2757
2531
  var outputSchema9 = pluginToolOutputSchema11.merge(
2758
2532
  pullRequestSchema2.extend({
2759
- target: z15.literal("updatePullRequest")
2533
+ target: z16.literal("updatePullRequest")
2760
2534
  })
2761
2535
  );
2762
2536
  function nonEmptyString5(value, name) {
@@ -2765,58 +2539,27 @@ function nonEmptyString5(value, name) {
2765
2539
  }
2766
2540
  return value.trim();
2767
2541
  }
2768
- function parseRepo10(value) {
2769
- const parts = value.split("/").map((part) => part.trim());
2770
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
2771
- throw new PluginToolInputError11('repo must use "owner/name" format');
2772
- }
2773
- return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
2774
- }
2775
- async function readJson7(response) {
2776
- const text2 = await response.text();
2777
- if (!text2) return void 0;
2778
- try {
2779
- return JSON.parse(text2);
2780
- } catch {
2781
- return text2;
2782
- }
2783
- }
2784
- function githubApiErrorMessage4(payload) {
2785
- if (payload && typeof payload === "object" && !Array.isArray(payload)) {
2786
- const message = payload.message;
2787
- if (typeof message === "string" && message.trim()) return message.trim();
2788
- }
2789
- if (typeof payload === "string" && payload.trim()) return payload.trim();
2790
- return "GitHub request failed";
2791
- }
2792
2542
  async function setPullRequestDraft(input) {
2793
2543
  const mutation = input.draft ? CONVERT_TO_DRAFT : MARK_READY_FOR_REVIEW;
2794
- const response = await input.egress.fetch({
2795
- provider: "github",
2544
+ const response = await githubApi(input.egress, {
2796
2545
  operation: `github.pull.draft.update:${input.repo.toLowerCase()}`,
2797
- request: new Request("https://api.github.com/graphql", {
2798
- method: "POST",
2799
- headers: { "Content-Type": "application/json" },
2800
- body: JSON.stringify({
2801
- operationName: mutation.operationName,
2802
- query: mutation.query,
2803
- variables: { id: input.nodeId }
2804
- })
2805
- })
2546
+ method: "POST",
2547
+ path: "/graphql",
2548
+ body: {
2549
+ operationName: mutation.operationName,
2550
+ query: mutation.query,
2551
+ variables: { id: input.nodeId }
2552
+ }
2806
2553
  });
2807
- const payload = await readJson7(response);
2554
+ const payload = response.body;
2808
2555
  const isDraft = draftMutationResponseSchema.safeParse(payload).data?.data.result.pullRequest.isDraft;
2809
2556
  if (!response.ok || isDraft !== input.draft) {
2810
2557
  throw new Error(
2811
- `GitHub pull request draft update failed with HTTP ${response.status}: ${githubGraphqlErrorMessage(payload)}`
2558
+ `GitHub pull request draft update failed with HTTP ${response.status}: ${githubErrorMessage(payload)}`
2812
2559
  );
2813
2560
  }
2814
2561
  return isDraft;
2815
2562
  }
2816
- function githubGraphqlErrorMessage(payload) {
2817
- const result = graphqlErrorsSchema.safeParse(payload);
2818
- return result.success ? result.data.errors.map((error) => error.message).join("; ") : githubApiErrorMessage4(payload);
2819
- }
2820
2563
  function createGitHubUpdatePullRequestTool(ctx) {
2821
2564
  return definePluginTool11({
2822
2565
  annotations: {
@@ -2837,13 +2580,22 @@ function createGitHubUpdatePullRequestTool(ctx) {
2837
2580
  );
2838
2581
  }
2839
2582
  const update = parsedInput.data;
2840
- const repo = parseRepo10(update.repo);
2583
+ const repo = parseRepo(update.repo);
2841
2584
  const requester = await resolveGitHubRequester(ctx);
2585
+ const currentBody = update.body !== void 0 ? await readGitHubBody(ctx.egress, {
2586
+ operation: "github.pull.get",
2587
+ path: `${repoPath(repo)}/pulls/${update.number}`
2588
+ }) : void 0;
2842
2589
  const payload = {
2843
2590
  ...update.title !== void 0 ? { title: update.title } : void 0,
2844
2591
  ...update.body !== void 0 ? {
2845
2592
  body: appendGitHubFooter(
2846
- appendGitHubRequesterAttribution(update.body, ctx, requester),
2593
+ appendGitHubRequesterAttribution(
2594
+ update.body,
2595
+ ctx,
2596
+ requester,
2597
+ currentBody
2598
+ ),
2847
2599
  nonEmptyString5(ctx.conversationId, "conversationId"),
2848
2600
  ctx.slack?.conversationLink?.url
2849
2601
  )
@@ -2851,37 +2603,28 @@ function createGitHubUpdatePullRequestTool(ctx) {
2851
2603
  ...update.base !== void 0 ? { base: update.base } : void 0,
2852
2604
  ...update.state !== void 0 ? { state: update.state } : void 0
2853
2605
  };
2854
- const pullUrl = `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/pulls/${update.number}`;
2855
2606
  const hasRestUpdate = Object.keys(payload).length > 0;
2856
- const response = await ctx.egress.fetch({
2857
- provider: "github",
2607
+ const response = await githubApi(ctx.egress, {
2858
2608
  operation: hasRestUpdate ? "github.pull.update" : "github.pull.get",
2859
- request: new Request(pullUrl, {
2860
- method: hasRestUpdate ? "PATCH" : "GET",
2861
- headers: {
2862
- Accept: "application/vnd.github+json",
2863
- "X-GitHub-Api-Version": "2022-11-28",
2864
- ...hasRestUpdate ? { "Content-Type": "application/json" } : void 0
2865
- },
2866
- ...hasRestUpdate ? { body: JSON.stringify(payload) } : void 0
2867
- })
2609
+ path: `${repoPath(repo)}/pulls/${update.number}`,
2610
+ ...hasRestUpdate ? { method: "PATCH", body: payload } : void 0
2868
2611
  });
2869
- const parsed = await readJson7(response);
2612
+ const parsed = response.body;
2870
2613
  if (!response.ok) {
2871
2614
  throw new Error(
2872
- `GitHub pull request update failed with HTTP ${response.status}: ${githubApiErrorMessage4(parsed)}`
2615
+ `GitHub pull request update failed with HTTP ${response.status}: ${githubErrorMessage(parsed)}`
2873
2616
  );
2874
2617
  }
2875
- const providerResult = z15.object({
2876
- base: z15.object({ ref: z15.string() }),
2877
- body: z15.string().nullable().optional().default(null),
2878
- draft: z15.boolean(),
2879
- html_url: z15.string(),
2880
- merged: z15.boolean(),
2881
- node_id: z15.string().optional(),
2882
- number: z15.number(),
2883
- state: z15.string(),
2884
- title: z15.string()
2618
+ const providerResult = z16.object({
2619
+ base: z16.object({ ref: z16.string() }),
2620
+ body: z16.string().nullable().optional().default(null),
2621
+ draft: z16.boolean(),
2622
+ html_url: z16.string(),
2623
+ merged: z16.boolean(),
2624
+ node_id: z16.string().optional(),
2625
+ number: z16.number(),
2626
+ state: z16.string(),
2627
+ title: z16.string()
2885
2628
  }).parse(parsed);
2886
2629
  if (update.draft !== void 0 && update.draft !== providerResult.draft) {
2887
2630
  if (!providerResult.node_id) {
@@ -2946,7 +2689,7 @@ import {
2946
2689
  PluginToolInputError as PluginToolInputError12,
2947
2690
  pluginToolOutputSchema as pluginToolOutputSchema12
2948
2691
  } from "@sentry/junior-plugin-api";
2949
- import { z as z16 } from "zod";
2692
+ import * as z17 from "zod";
2950
2693
  var STATUS_TO_REACTION_CONTENT = {
2951
2694
  reviewing: "eyes",
2952
2695
  addressed: "+1",
@@ -2955,32 +2698,25 @@ var STATUS_TO_REACTION_CONTENT = {
2955
2698
  var FEEDBACK_REACTION_CONTENTS = new Set(
2956
2699
  Object.values(STATUS_TO_REACTION_CONTENT)
2957
2700
  );
2958
- var inputSchema10 = z16.object({
2959
- repo: z16.string().describe('Repository in "owner/name" format.'),
2960
- comment_kind: z16.enum(["conversation", "review"]).describe(
2701
+ var inputSchema10 = z17.object({
2702
+ repo: z17.string().describe('Repository in "owner/name" format.'),
2703
+ comment_kind: z17.enum(["conversation", "review"]).describe(
2961
2704
  'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment.'
2962
2705
  ),
2963
- comment_id: z16.number().int().positive().describe(
2706
+ comment_id: z17.number().int().positive().describe(
2964
2707
  "GitHub comment id (conversation comment id or inline review comment id)."
2965
2708
  ),
2966
- status: z16.enum(["addressed", "declined"]).describe(
2709
+ status: z17.enum(["addressed", "declined"]).describe(
2967
2710
  "Feedback outcome. Maps to a reaction: addressed -> +1, declined -> -1."
2968
2711
  )
2969
2712
  }).strict();
2970
2713
  var outputSchema10 = pluginToolOutputSchema12.extend({
2971
- target: z16.literal("updatePullRequestFeedback"),
2972
- repo: z16.string(),
2973
- comment_id: z16.number(),
2974
- status: z16.enum(["addressed", "declined"]),
2975
- reaction_id: z16.number()
2714
+ target: z17.literal("updatePullRequestFeedback"),
2715
+ repo: z17.string(),
2716
+ comment_id: z17.number(),
2717
+ status: z17.enum(["addressed", "declined"]),
2718
+ reaction_id: z17.number()
2976
2719
  });
2977
- function parseRepo11(value) {
2978
- const parts = value.split("/").map((part) => part.trim());
2979
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
2980
- throw new PluginToolInputError12('repo must use "owner/name" format');
2981
- }
2982
- return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
2983
- }
2984
2720
  function pullRequestCommentPath(input) {
2985
2721
  const segment = input.commentKind === "conversation" ? "issues" : "pulls";
2986
2722
  return `/repos/${encodeURIComponent(input.owner)}/${encodeURIComponent(input.name)}/${segment}/comments/${input.commentId}`;
@@ -2991,70 +2727,42 @@ function pullRequestCommentReactionsPath(input) {
2991
2727
  function pullRequestFeedbackReactionContent(status) {
2992
2728
  return STATUS_TO_REACTION_CONTENT[status];
2993
2729
  }
2994
- async function readJson8(response) {
2995
- const text2 = await response.text();
2996
- if (!text2) return void 0;
2997
- try {
2998
- return JSON.parse(text2);
2999
- } catch {
3000
- return text2;
3001
- }
3002
- }
3003
- function githubError2(payload) {
3004
- if (payload && typeof payload === "object" && !Array.isArray(payload)) {
3005
- const message = payload.message;
3006
- if (typeof message === "string" && message.trim()) return message.trim();
3007
- }
3008
- return "GitHub request failed";
3009
- }
3010
- var reactionSchema = z16.object({
3011
- id: z16.number(),
3012
- content: z16.string(),
3013
- user: z16.object({ id: z16.number() }).nullable()
2730
+ var reactionSchema = z17.object({
2731
+ id: z17.number(),
2732
+ content: z17.string(),
2733
+ user: z17.object({ id: z17.number() }).nullable()
3014
2734
  });
3015
2735
  async function assertBotAuthoredPullRequest(egress, input) {
3016
- const headers = {
3017
- Accept: "application/vnd.github+json",
3018
- "X-GitHub-Api-Version": "2022-11-28"
3019
- };
3020
- const commentResponse = await egress.fetch({
3021
- provider: "github",
2736
+ const commentResponse = await githubApi(egress, {
3022
2737
  operation: "github.pull.comment.get",
3023
- request: new Request(
3024
- `https://api.github.com${pullRequestCommentPath(input)}`,
3025
- { headers }
3026
- )
2738
+ path: pullRequestCommentPath(input)
3027
2739
  });
3028
- const commentPayload = await readJson8(commentResponse);
2740
+ const commentPayload = commentResponse.body;
3029
2741
  if (!commentResponse.ok) {
3030
- const message = `GitHub comment lookup failed with HTTP ${commentResponse.status}: ${githubError2(commentPayload)}`;
2742
+ const message = `GitHub comment lookup failed with HTTP ${commentResponse.status}: ${githubErrorMessage(commentPayload)}`;
3031
2743
  if (commentResponse.status === 404) throw new PluginToolInputError12(message);
3032
2744
  throw new Error(message);
3033
2745
  }
3034
- const comment = z16.object({
3035
- issue_url: z16.string().optional(),
3036
- pull_request_url: z16.string().optional()
2746
+ const comment = z17.object({
2747
+ issue_url: z17.string().optional(),
2748
+ pull_request_url: z17.string().optional()
3037
2749
  }).safeParse(commentPayload);
3038
2750
  const parentUrl = comment.success ? input.commentKind === "conversation" ? comment.data.issue_url : comment.data.pull_request_url : void 0;
3039
- const number = /\/(?:issues|pulls)\/(\d+)$/.exec(parentUrl ?? "")?.[1];
3040
- if (!number) {
2751
+ const number22 = /\/(?:issues|pulls)\/(\d+)$/.exec(parentUrl ?? "")?.[1];
2752
+ if (!number22) {
3041
2753
  throw new Error("GitHub comment did not name its issue or pull request.");
3042
2754
  }
3043
- const pullResponse = await egress.fetch({
3044
- provider: "github",
2755
+ const pullResponse = await githubApi(egress, {
3045
2756
  operation: "github.pull.get",
3046
- request: new Request(
3047
- `https://api.github.com/repos/${encodeURIComponent(input.owner)}/${encodeURIComponent(input.name)}/pulls/${number}`,
3048
- { headers }
3049
- )
2757
+ path: `${repoPath(input)}/pulls/${number22}`
3050
2758
  });
3051
- const pullPayload = await readJson8(pullResponse);
2759
+ const pullPayload = pullResponse.body;
3052
2760
  if (!pullResponse.ok && pullResponse.status !== 404) {
3053
2761
  throw new Error(
3054
- `GitHub pull request lookup failed with HTTP ${pullResponse.status}: ${githubError2(pullPayload)}`
2762
+ `GitHub pull request lookup failed with HTTP ${pullResponse.status}: ${githubErrorMessage(pullPayload)}`
3055
2763
  );
3056
2764
  }
3057
- const pull = z16.object({ user: z16.object({ id: z16.number() }).nullable() }).safeParse(pullPayload);
2765
+ const pull = z17.object({ user: z17.object({ id: z17.number() }).nullable() }).safeParse(pullPayload);
3058
2766
  if (!pullResponse.ok || !pull.success || pull.data.user?.id !== input.botUserId) {
3059
2767
  throw new PluginToolInputError12(
3060
2768
  "This bot can only set feedback status on comments on pull requests it authored."
@@ -3089,7 +2797,7 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
3089
2797
  comment_kind: commentKind,
3090
2798
  status
3091
2799
  } = parsedInput.data;
3092
- const repo = parseRepo11(parsedInput.data.repo);
2800
+ const repo = parseRepo(parsedInput.data.repo);
3093
2801
  const botUserId = botUserIdFromEmail(botEmail);
3094
2802
  if (botUserId === void 0) {
3095
2803
  throw new Error("GitHub App bot identity is not configured.");
@@ -3102,26 +2810,23 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
3102
2810
  botUserId
3103
2811
  });
3104
2812
  const targetContent = pullRequestFeedbackReactionContent(status);
3105
- const baseUrl = `https://api.github.com${pullRequestCommentReactionsPath({
2813
+ const reactionsPath = pullRequestCommentReactionsPath({
3106
2814
  owner: repo.owner,
3107
2815
  name: repo.name,
3108
2816
  commentKind,
3109
2817
  commentId
3110
- })}`;
3111
- const listResponse = await ctx.egress.fetch({
3112
- provider: "github",
2818
+ });
2819
+ const listResponse = await githubApi(ctx.egress, {
3113
2820
  operation: "github.pull.comment-reaction.list",
3114
- request: new Request(`${baseUrl}?per_page=100`, {
3115
- headers: { Accept: "application/vnd.github+json" }
3116
- })
2821
+ path: `${reactionsPath}?per_page=100`
3117
2822
  });
3118
- const listPayload = await readJson8(listResponse);
2823
+ const listPayload = listResponse.body;
3119
2824
  if (!listResponse.ok) {
3120
2825
  throw new Error(
3121
- `GitHub reaction lookup failed with HTTP ${listResponse.status}: ${githubError2(listPayload)}`
2826
+ `GitHub reaction lookup failed with HTTP ${listResponse.status}: ${githubErrorMessage(listPayload)}`
3122
2827
  );
3123
2828
  }
3124
- const botReactions = z16.array(reactionSchema).parse(listPayload).filter(
2829
+ const botReactions = z17.array(reactionSchema).parse(listPayload).filter(
3125
2830
  (reaction) => reaction.user?.id === botUserId && FEEDBACK_REACTION_CONTENTS.has(reaction.content)
3126
2831
  );
3127
2832
  const existing = botReactions.find(
@@ -3129,17 +2834,14 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
3129
2834
  );
3130
2835
  for (const stale of botReactions) {
3131
2836
  if (stale.content === targetContent) continue;
3132
- const deleteResponse = await ctx.egress.fetch({
3133
- provider: "github",
2837
+ const deleteResponse = await githubApi(ctx.egress, {
3134
2838
  operation: "github.pull.comment-reaction.delete",
3135
- request: new Request(`${baseUrl}/${stale.id}`, {
3136
- method: "DELETE"
3137
- })
2839
+ method: "DELETE",
2840
+ path: `${reactionsPath}/${stale.id}`
3138
2841
  });
3139
2842
  if (!deleteResponse.ok && deleteResponse.status !== 404) {
3140
- const deletePayload = await readJson8(deleteResponse);
3141
2843
  throw new Error(
3142
- `GitHub reaction removal failed with HTTP ${deleteResponse.status}: ${githubError2(deletePayload)}`
2844
+ `GitHub reaction removal failed with HTTP ${deleteResponse.status}: ${githubErrorMessage(deleteResponse.body)}`
3143
2845
  );
3144
2846
  }
3145
2847
  }
@@ -3152,22 +2854,16 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
3152
2854
  reaction_id: existing.id
3153
2855
  };
3154
2856
  }
3155
- const createResponse = await ctx.egress.fetch({
3156
- provider: "github",
2857
+ const createResponse = await githubApi(ctx.egress, {
3157
2858
  operation: "github.pull.comment-reaction.create",
3158
- request: new Request(baseUrl, {
3159
- method: "POST",
3160
- headers: {
3161
- Accept: "application/vnd.github+json",
3162
- "Content-Type": "application/json"
3163
- },
3164
- body: JSON.stringify({ content: targetContent })
3165
- })
2859
+ method: "POST",
2860
+ path: reactionsPath,
2861
+ body: { content: targetContent }
3166
2862
  });
3167
- const createPayload = await readJson8(createResponse);
2863
+ const createPayload = createResponse.body;
3168
2864
  if (!createResponse.ok) {
3169
2865
  throw new Error(
3170
- `GitHub reaction creation failed with HTTP ${createResponse.status}: ${githubError2(createPayload)}`
2866
+ `GitHub reaction creation failed with HTTP ${createResponse.status}: ${githubErrorMessage(createPayload)}`
3171
2867
  );
3172
2868
  }
3173
2869
  const created = reactionSchema.parse(createPayload);
@@ -3188,45 +2884,22 @@ import {
3188
2884
  PluginToolInputError as PluginToolInputError13,
3189
2885
  pluginToolOutputSchema as pluginToolOutputSchema13
3190
2886
  } from "@sentry/junior-plugin-api";
3191
- import { z as z17 } from "zod";
3192
- var inputSchema11 = z17.object({
3193
- repo: z17.string().describe(
2887
+ import * as z18 from "zod";
2888
+ var inputSchema11 = z18.object({
2889
+ repo: z18.string().describe(
3194
2890
  'Repository in "owner/name" format. Required because GraphQL has no repo path.'
3195
2891
  ),
3196
- thread_id: z17.string().trim().min(1).describe(
2892
+ thread_id: z18.string().trim().min(1).describe(
3197
2893
  "GitHub pull request review thread node ID (the `threadId` / `id` variable used by `gh api graphql` resolveReviewThread)."
3198
2894
  )
3199
2895
  }).strict();
3200
2896
  var outputSchema11 = pluginToolOutputSchema13.extend({
3201
- target: z17.literal("resolvePullRequestReviewThread"),
3202
- repo: z17.string(),
3203
- number: z17.number(),
3204
- thread_id: z17.string(),
3205
- resolved: z17.boolean()
2897
+ target: z18.literal("resolvePullRequestReviewThread"),
2898
+ repo: z18.string(),
2899
+ number: z18.number(),
2900
+ thread_id: z18.string(),
2901
+ resolved: z18.boolean()
3206
2902
  });
3207
- function parseRepo12(value) {
3208
- const parts = value.split("/").map((part) => part.trim());
3209
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
3210
- throw new PluginToolInputError13('repo must use "owner/name" format');
3211
- }
3212
- return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
3213
- }
3214
- async function readJson9(response) {
3215
- const text2 = await response.text();
3216
- if (!text2) return void 0;
3217
- try {
3218
- return JSON.parse(text2);
3219
- } catch {
3220
- return text2;
3221
- }
3222
- }
3223
- function githubError3(payload) {
3224
- if (payload && typeof payload === "object" && !Array.isArray(payload)) {
3225
- const message = payload.message;
3226
- if (typeof message === "string" && message.trim()) return message.trim();
3227
- }
3228
- return "GitHub request failed";
3229
- }
3230
2903
  function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
3231
2904
  return definePluginTool13({
3232
2905
  // No action review: the tool checks in code that the bot authored the pull
@@ -3251,7 +2924,7 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
3251
2924
  { cause: parsedInput.error }
3252
2925
  );
3253
2926
  }
3254
- const repo = parseRepo12(parsedInput.data.repo);
2927
+ const repo = parseRepo(parsedInput.data.repo);
3255
2928
  const botUserId = botUserIdFromEmail(botEmail);
3256
2929
  if (botUserId === void 0) {
3257
2930
  throw new Error("GitHub App bot identity is not configured.");
@@ -3269,37 +2942,34 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
3269
2942
  }
3270
2943
  }
3271
2944
  }`;
3272
- const lookupResponse = await ctx.egress.fetch({
3273
- provider: "github",
2945
+ const lookupResponse = await githubApi(ctx.egress, {
3274
2946
  operation: "github.pull.review-thread.get",
3275
- request: new Request("https://api.github.com/graphql", {
3276
- method: "POST",
3277
- headers: { "Content-Type": "application/json" },
3278
- body: JSON.stringify({
3279
- operationName: "ReviewThreadOwnership",
3280
- query,
3281
- variables: { threadId: parsedInput.data.thread_id }
3282
- })
3283
- })
2947
+ method: "POST",
2948
+ path: "/graphql",
2949
+ body: {
2950
+ operationName: "ReviewThreadOwnership",
2951
+ query,
2952
+ variables: { threadId: parsedInput.data.thread_id }
2953
+ }
3284
2954
  });
3285
- const lookupPayload = await readJson9(lookupResponse);
2955
+ const lookupPayload = lookupResponse.body;
3286
2956
  if (!lookupResponse.ok) {
3287
2957
  throw new Error(
3288
- `GitHub review thread lookup failed with HTTP ${lookupResponse.status}: ${githubError3(lookupPayload)}`
2958
+ `GitHub review thread lookup failed with HTTP ${lookupResponse.status}: ${githubErrorMessage(lookupPayload)}`
3289
2959
  );
3290
2960
  }
3291
- const threadNodeSchema = z17.object({
3292
- id: z17.string(),
3293
- isResolved: z17.boolean(),
3294
- pullRequest: z17.object({
3295
- author: z17.object({ databaseId: z17.number().optional() }).passthrough().nullable(),
3296
- number: z17.number(),
3297
- repository: z17.object({ nameWithOwner: z17.string() }).passthrough()
2961
+ const threadNodeSchema = z18.object({
2962
+ id: z18.string(),
2963
+ isResolved: z18.boolean(),
2964
+ pullRequest: z18.object({
2965
+ author: z18.object({ databaseId: z18.number().optional() }).passthrough().nullable(),
2966
+ number: z18.number(),
2967
+ repository: z18.object({ nameWithOwner: z18.string() }).passthrough()
3298
2968
  }).passthrough()
3299
2969
  }).passthrough();
3300
- const lookupResultSchema = z17.object({
3301
- data: z17.object({
3302
- node: z17.unknown().nullable().optional()
2970
+ const lookupResultSchema = z18.object({
2971
+ data: z18.object({
2972
+ node: z18.unknown().nullable().optional()
3303
2973
  }).passthrough()
3304
2974
  }).passthrough();
3305
2975
  const lookupResult = lookupResultSchema.safeParse(lookupPayload);
@@ -3330,29 +3000,26 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
3330
3000
  thread { id isResolved }
3331
3001
  }
3332
3002
  }`;
3333
- const resolveResponse = await ctx.egress.fetch({
3334
- provider: "github",
3003
+ const resolveResponse = await githubApi(ctx.egress, {
3335
3004
  operation: `github.pull.review-thread.resolve:${repo.ref.toLowerCase()}`,
3336
- request: new Request("https://api.github.com/graphql", {
3337
- method: "POST",
3338
- headers: { "Content-Type": "application/json" },
3339
- body: JSON.stringify({
3340
- operationName: "ResolveReviewThread",
3341
- query: mutation,
3342
- variables: { threadId: thread.id }
3343
- })
3344
- })
3005
+ method: "POST",
3006
+ path: "/graphql",
3007
+ body: {
3008
+ operationName: "ResolveReviewThread",
3009
+ query: mutation,
3010
+ variables: { threadId: thread.id }
3011
+ }
3345
3012
  });
3346
- const resolvePayload = await readJson9(resolveResponse);
3013
+ const resolvePayload = resolveResponse.body;
3347
3014
  if (!resolveResponse.ok) {
3348
3015
  throw new Error(
3349
- `GitHub review thread resolution failed with HTTP ${resolveResponse.status}: ${githubError3(resolvePayload)}`
3016
+ `GitHub review thread resolution failed with HTTP ${resolveResponse.status}: ${githubErrorMessage(resolvePayload)}`
3350
3017
  );
3351
3018
  }
3352
- const resolveResultSchema = z17.object({
3353
- data: z17.object({
3354
- resolveReviewThread: z17.object({
3355
- thread: z17.object({ id: z17.string(), isResolved: z17.boolean() }).passthrough()
3019
+ const resolveResultSchema = z18.object({
3020
+ data: z18.object({
3021
+ resolveReviewThread: z18.object({
3022
+ thread: z18.object({ id: z18.string(), isResolved: z18.boolean() }).passthrough()
3356
3023
  }).passthrough()
3357
3024
  }).passthrough()
3358
3025
  }).passthrough();
@@ -3384,59 +3051,35 @@ import {
3384
3051
  PluginToolInputError as PluginToolInputError14,
3385
3052
  pluginToolOutputSchema as pluginToolOutputSchema14
3386
3053
  } from "@sentry/junior-plugin-api";
3387
- import { z as z18 } from "zod";
3388
- var reviewCommentSchema = z18.object({
3389
- path: z18.string().trim().min(1).describe("File path in the pull request."),
3390
- body: z18.string().trim().min(1).describe("Inline review comment."),
3391
- line: z18.number().int().positive().describe("Line in the pull request diff."),
3392
- side: z18.enum(["LEFT", "RIGHT"]).describe("Side of the pull request diff."),
3393
- start_line: z18.number().int().positive().optional().describe("First line of a multi-line comment."),
3394
- start_side: z18.enum(["LEFT", "RIGHT"]).optional().describe("First side of a multi-line comment.")
3054
+ import * as z19 from "zod";
3055
+ var reviewCommentSchema = z19.object({
3056
+ path: z19.string().trim().min(1).describe("File path in the pull request."),
3057
+ body: z19.string().trim().min(1).describe("Inline review comment."),
3058
+ line: z19.number().int().positive().describe("Line in the pull request diff."),
3059
+ side: z19.enum(["LEFT", "RIGHT"]).describe("Side of the pull request diff."),
3060
+ start_line: z19.number().int().positive().optional().describe("First line of a multi-line comment."),
3061
+ start_side: z19.enum(["LEFT", "RIGHT"]).optional().describe("First side of a multi-line comment.")
3395
3062
  }).strict().refine(
3396
3063
  ({ start_line, start_side }) => start_line === void 0 === (start_side === void 0),
3397
3064
  { message: "start_line and start_side must be provided together." }
3398
3065
  );
3399
- var inputSchema12 = z18.object({
3400
- repo: z18.string().describe('Repository in "owner/name" format.'),
3401
- number: z18.number().int().positive().describe("Pull request number."),
3402
- event: z18.enum(["COMMENT", "REQUEST_CHANGES"]).describe("Review result. You cannot approve pull requests."),
3403
- body: z18.string().trim().min(1).describe("Review summary."),
3404
- comments: z18.array(reviewCommentSchema).optional().describe("Optional inline review comments.")
3066
+ var inputSchema12 = z19.object({
3067
+ repo: z19.string().describe('Repository in "owner/name" format.'),
3068
+ number: z19.number().int().positive().describe("Pull request number."),
3069
+ event: z19.enum(["COMMENT", "REQUEST_CHANGES"]).describe("Review result. You cannot approve pull requests."),
3070
+ body: z19.string().trim().min(1).describe("Review summary."),
3071
+ comments: z19.array(reviewCommentSchema).optional().describe("Optional inline review comments.")
3405
3072
  }).strict();
3406
3073
  var outputSchema12 = pluginToolOutputSchema14.extend({
3407
- target: z18.literal("submitPullRequestReview"),
3408
- repo: z18.string(),
3409
- number: z18.number(),
3410
- review_id: z18.number(),
3411
- state: z18.string(),
3412
- url: z18.string()
3074
+ target: z19.literal("submitPullRequestReview"),
3075
+ repo: z19.string(),
3076
+ number: z19.number(),
3077
+ review_id: z19.number(),
3078
+ state: z19.string(),
3079
+ url: z19.string()
3413
3080
  });
3414
- function parseRepo13(value) {
3415
- const parts = value.split("/").map((part) => part.trim());
3416
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
3417
- throw new PluginToolInputError14('repo must use "owner/name" format');
3418
- }
3419
- return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
3420
- }
3421
- async function readJson10(response) {
3422
- const text2 = await response.text();
3423
- if (!text2) return void 0;
3424
- try {
3425
- return JSON.parse(text2);
3426
- } catch {
3427
- return text2;
3428
- }
3429
- }
3430
- function githubError4(body) {
3431
- if (body && typeof body === "object" && !Array.isArray(body)) {
3432
- const message = body.message;
3433
- if (typeof message === "string" && message.trim()) return message.trim();
3434
- }
3435
- if (typeof body === "string" && body.trim()) return body.trim();
3436
- return "GitHub request failed";
3437
- }
3438
3081
  function throwReviewError(status, body) {
3439
- const message = `GitHub pull request review failed with HTTP ${status}: ${githubError4(body)}`;
3082
+ const message = `GitHub pull request review failed with HTTP ${status}: ${githubErrorMessage(body)}`;
3440
3083
  if (status === 404 || status === 422) {
3441
3084
  throw new PluginToolInputError14(message);
3442
3085
  }
@@ -3455,7 +3098,7 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
3455
3098
  inputSchema: inputSchema12,
3456
3099
  outputSchema: outputSchema12,
3457
3100
  async execute(review) {
3458
- const repo = parseRepo13(review.repo);
3101
+ const repo = parseRepo(review.repo);
3459
3102
  const comments = review.comments?.map((comment) => ({
3460
3103
  path: comment.path,
3461
3104
  body: comment.body,
@@ -3464,31 +3107,20 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
3464
3107
  ...comment.start_line !== void 0 ? { start_line: comment.start_line } : void 0,
3465
3108
  ...comment.start_side !== void 0 ? { start_side: comment.start_side } : void 0
3466
3109
  }));
3467
- const response = await egress.fetch({
3468
- provider: "github",
3110
+ const response = await githubApi(egress, {
3469
3111
  operation: "github.pull.review.create",
3470
- request: new Request(
3471
- `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/pulls/${review.number}/reviews`,
3472
- {
3473
- method: "POST",
3474
- headers: {
3475
- Accept: "application/vnd.github+json",
3476
- "Content-Type": "application/json",
3477
- "X-GitHub-Api-Version": "2022-11-28"
3478
- },
3479
- body: JSON.stringify({
3480
- body: review.body,
3481
- event: review.event,
3482
- ...comments ? { comments } : void 0
3483
- })
3484
- }
3485
- )
3112
+ method: "POST",
3113
+ path: `${repoPath(repo)}/pulls/${review.number}/reviews`,
3114
+ body: {
3115
+ body: review.body,
3116
+ event: review.event,
3117
+ ...comments ? { comments } : void 0
3118
+ }
3486
3119
  });
3487
- const parsed = await readJson10(response);
3488
3120
  if (!response.ok) {
3489
- throwReviewError(response.status, parsed);
3121
+ throwReviewError(response.status, response.body);
3490
3122
  }
3491
- const providerResult = z18.object({ id: z18.number(), html_url: z18.string(), state: z18.string() }).parse(parsed);
3123
+ const providerResult = z19.object({ id: z19.number(), html_url: z19.string(), state: z19.string() }).parse(response.body);
3492
3124
  return {
3493
3125
  target: "submitPullRequestReview",
3494
3126
  repo: repo.ref,
@@ -3531,26 +3163,26 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
3531
3163
 
3532
3164
  // src/webhooks/handler.ts
3533
3165
  import { createHmac, timingSafeEqual } from "crypto";
3534
- import { z as z28 } from "zod";
3166
+ import * as z29 from "zod";
3535
3167
 
3536
3168
  // src/issue-outcomes/store.ts
3537
3169
  import { and as and2, eq as eq2, lte, sql as sql2 } from "drizzle-orm";
3538
- import { z as z19 } from "zod";
3539
- var githubIssueOutcomeInputSchema = z19.object({
3540
- candidateOwned: z19.boolean(),
3541
- closedAt: z19.date().optional(),
3542
- issueId: z19.string().min(1),
3543
- number: z19.number().int().positive(),
3544
- openedAt: z19.date(),
3545
- repositoryFullName: z19.string().min(1),
3546
- repositoryId: z19.string().min(1),
3170
+ import * as z20 from "zod";
3171
+ var githubIssueOutcomeInputSchema = z20.object({
3172
+ candidateOwned: z20.boolean(),
3173
+ closedAt: z20.date().optional(),
3174
+ issueId: z20.string().min(1),
3175
+ number: z20.number().int().positive(),
3176
+ openedAt: z20.date(),
3177
+ repositoryFullName: z20.string().min(1),
3178
+ repositoryId: z20.string().min(1),
3547
3179
  state: githubIssueStateSchema,
3548
3180
  stateReason: githubIssueStateReasonSchema.optional(),
3549
- updatedAt: z19.date()
3181
+ updatedAt: z20.date()
3550
3182
  }).strict();
3551
- var githubIssueConversationsInputSchema = z19.object({
3552
- conversationIds: z19.array(z19.string().min(1)).min(1),
3553
- issueId: z19.string().min(1)
3183
+ var githubIssueConversationsInputSchema = z20.object({
3184
+ conversationIds: z20.array(z20.string().min(1)).min(1),
3185
+ issueId: z20.string().min(1)
3554
3186
  }).strict();
3555
3187
  function projectionValues(input) {
3556
3188
  return {
@@ -3614,33 +3246,33 @@ async function recordGitHubIssueConversations(db, input) {
3614
3246
 
3615
3247
  // src/pull-request-outcomes/store.ts
3616
3248
  import { and as and3, eq as eq3, lte as lte2, ne, sql as sql3 } from "drizzle-orm";
3617
- import { z as z20 } from "zod";
3618
- var githubPullRequestOutcomeInputSchema = z20.object({
3619
- candidateOwned: z20.boolean(),
3620
- closedAt: z20.date().optional(),
3249
+ import * as z21 from "zod";
3250
+ var githubPullRequestOutcomeInputSchema = z21.object({
3251
+ candidateOwned: z21.boolean(),
3252
+ closedAt: z21.date().optional(),
3621
3253
  commitComposition: githubPullRequestCommitCompositionSchema.optional(),
3622
- mergedAt: z20.date().optional(),
3623
- number: z20.number().int().positive(),
3624
- openedAt: z20.date(),
3625
- pullRequestId: z20.string().min(1),
3626
- repositoryFullName: z20.string().min(1),
3627
- repositoryId: z20.string().min(1),
3254
+ mergedAt: z21.date().optional(),
3255
+ number: z21.number().int().positive(),
3256
+ openedAt: z21.date(),
3257
+ pullRequestId: z21.string().min(1),
3258
+ repositoryFullName: z21.string().min(1),
3259
+ repositoryId: z21.string().min(1),
3628
3260
  state: githubPullRequestStateSchema,
3629
- title: z20.string().min(1).optional(),
3630
- updatedAt: z20.date()
3261
+ title: z21.string().min(1).optional(),
3262
+ updatedAt: z21.date()
3631
3263
  }).strict();
3632
- var githubPullRequestConversationsInputSchema = z20.object({
3633
- conversationIds: z20.array(z20.string().min(1)).min(1),
3634
- pullRequestId: z20.string().min(1)
3264
+ var githubPullRequestConversationsInputSchema = z21.object({
3265
+ conversationIds: z21.array(z21.string().min(1)).min(1),
3266
+ pullRequestId: z21.string().min(1)
3635
3267
  }).strict();
3636
- var githubPullRequestLinkedIssuesInputSchema = z20.object({
3637
- linkedIssues: z20.array(
3638
- z20.object({
3639
- number: z20.number().int().positive(),
3640
- repositoryFullName: z20.string().min(1)
3268
+ var githubPullRequestLinkedIssuesInputSchema = z21.object({
3269
+ linkedIssues: z21.array(
3270
+ z21.object({
3271
+ number: z21.number().int().positive(),
3272
+ repositoryFullName: z21.string().min(1)
3641
3273
  }).strict()
3642
3274
  ).min(1),
3643
- pullRequestId: z20.string().min(1)
3275
+ pullRequestId: z21.string().min(1)
3644
3276
  }).strict();
3645
3277
  function projectionValues2(input) {
3646
3278
  return {
@@ -3845,39 +3477,39 @@ async function releaseGitHubPullRequestReadySync(db, target, claim) {
3845
3477
  }
3846
3478
 
3847
3479
  // src/webhooks/issue-outcome.ts
3848
- import { z as z21 } from "zod";
3849
- var canonicalIssueOutcomeSchema = z21.object({
3850
- action: z21.enum(["opened", "closed", "reopened"]),
3851
- issue: z21.object({
3852
- body: z21.string().nullable().optional(),
3853
- closed_at: z21.string().nullable().optional(),
3854
- created_at: z21.string(),
3855
- id: z21.number().int().positive(),
3856
- number: z21.number().int().positive(),
3480
+ import * as z22 from "zod";
3481
+ var canonicalIssueOutcomeSchema = z22.object({
3482
+ action: z22.enum(["opened", "closed", "reopened"]),
3483
+ issue: z22.object({
3484
+ body: z22.string().nullable().optional(),
3485
+ closed_at: z22.string().nullable().optional(),
3486
+ created_at: z22.string(),
3487
+ id: z22.number().int().positive(),
3488
+ number: z22.number().int().positive(),
3857
3489
  state_reason: githubIssueStateReasonSchema.nullable().optional(),
3858
- updated_at: z21.string(),
3859
- user: z21.object({ login: z21.string().min(1) }).strict()
3490
+ updated_at: z22.string(),
3491
+ user: z22.object({ login: z22.string().min(1) }).strict()
3860
3492
  }).strict(),
3861
- repository: z21.object({
3862
- full_name: z21.string().min(1),
3863
- id: z21.number().int().positive()
3493
+ repository: z22.object({
3494
+ full_name: z22.string().min(1),
3495
+ id: z22.number().int().positive()
3864
3496
  }).strict()
3865
3497
  }).strict();
3866
- var issueOutcomeSchema = z21.object({
3867
- action: z21.enum(["opened", "closed", "reopened"]),
3868
- issue: z21.object({
3869
- body: z21.string().nullable().optional(),
3870
- closed_at: z21.string().nullable().optional(),
3871
- created_at: z21.string(),
3872
- id: z21.number().int().positive(),
3873
- number: z21.number().int().positive(),
3498
+ var issueOutcomeSchema = z22.object({
3499
+ action: z22.enum(["opened", "closed", "reopened"]),
3500
+ issue: z22.object({
3501
+ body: z22.string().nullable().optional(),
3502
+ closed_at: z22.string().nullable().optional(),
3503
+ created_at: z22.string(),
3504
+ id: z22.number().int().positive(),
3505
+ number: z22.number().int().positive(),
3874
3506
  state_reason: githubIssueStateReasonSchema.nullable().optional(),
3875
- updated_at: z21.string(),
3876
- user: z21.object({ login: z21.string().min(1) }).passthrough()
3507
+ updated_at: z22.string(),
3508
+ user: z22.object({ login: z22.string().min(1) }).passthrough()
3877
3509
  }).passthrough(),
3878
- repository: z21.object({
3879
- full_name: z21.string().min(1),
3880
- id: z21.number().int().positive()
3510
+ repository: z22.object({
3511
+ full_name: z22.string().min(1),
3512
+ id: z22.number().int().positive()
3881
3513
  }).passthrough()
3882
3514
  }).passthrough().transform(
3883
3515
  (provider) => canonicalIssueOutcomeSchema.parse({
@@ -3898,7 +3530,7 @@ var issueOutcomeSchema = z21.object({
3898
3530
  }
3899
3531
  })
3900
3532
  );
3901
- var issueLifecycleActionSchema = z21.object({ action: z21.string() }).passthrough();
3533
+ var issueLifecycleActionSchema = z22.object({ action: z22.string() }).passthrough();
3902
3534
  function timestamp2(value) {
3903
3535
  if (!value) return void 0;
3904
3536
  const parsed = new Date(value);
@@ -3942,21 +3574,21 @@ function normalizeGitHubIssueOutcome(args) {
3942
3574
  updatedAt
3943
3575
  };
3944
3576
  }
3945
- var canonicalIssueConversationSchema = z21.object({
3946
- issue: z21.object({
3947
- body: z21.string().nullable().optional(),
3948
- id: z21.number().int().positive(),
3949
- user: z21.object({ login: z21.string().min(1) }).strict()
3577
+ var canonicalIssueConversationSchema = z22.object({
3578
+ issue: z22.object({
3579
+ body: z22.string().nullable().optional(),
3580
+ id: z22.number().int().positive(),
3581
+ user: z22.object({ login: z22.string().min(1) }).strict()
3950
3582
  }).strict(),
3951
- sender: z21.object({ login: z21.string().min(1) }).strict().optional()
3583
+ sender: z22.object({ login: z22.string().min(1) }).strict().optional()
3952
3584
  }).strict();
3953
- var issueConversationSchema = z21.object({
3954
- issue: z21.object({
3955
- body: z21.string().nullable().optional(),
3956
- id: z21.number().int().positive(),
3957
- user: z21.object({ login: z21.string().min(1) }).passthrough()
3585
+ var issueConversationSchema = z22.object({
3586
+ issue: z22.object({
3587
+ body: z22.string().nullable().optional(),
3588
+ id: z22.number().int().positive(),
3589
+ user: z22.object({ login: z22.string().min(1) }).passthrough()
3958
3590
  }).passthrough(),
3959
- sender: z21.object({ login: z21.string().min(1) }).passthrough().optional()
3591
+ sender: z22.object({ login: z22.string().min(1) }).passthrough().optional()
3960
3592
  }).passthrough().transform(
3961
3593
  (provider) => canonicalIssueConversationSchema.parse({
3962
3594
  issue: {
@@ -3983,43 +3615,43 @@ function normalizeGitHubIssueConversations(args) {
3983
3615
  }
3984
3616
 
3985
3617
  // src/webhooks/pull-request-outcome.ts
3986
- import { z as z22 } from "zod";
3987
- var canonicalPullRequestOutcomeSchema = z22.object({
3988
- action: z22.enum(["opened", "closed", "reopened"]),
3989
- pull_request: z22.object({
3990
- body: z22.string().nullable().optional(),
3991
- closed_at: z22.string().nullable().optional(),
3992
- created_at: z22.string(),
3993
- id: z22.number().int().positive(),
3994
- merged: z22.boolean(),
3995
- merged_at: z22.string().nullable().optional(),
3996
- number: z22.number().int().positive(),
3997
- title: z22.string().min(1).optional(),
3998
- updated_at: z22.string(),
3999
- user: z22.object({ login: z22.string().min(1) }).strict()
3618
+ import * as z23 from "zod";
3619
+ var canonicalPullRequestOutcomeSchema = z23.object({
3620
+ action: z23.enum(["opened", "closed", "reopened"]),
3621
+ pull_request: z23.object({
3622
+ body: z23.string().nullable().optional(),
3623
+ closed_at: z23.string().nullable().optional(),
3624
+ created_at: z23.string(),
3625
+ id: z23.number().int().positive(),
3626
+ merged: z23.boolean(),
3627
+ merged_at: z23.string().nullable().optional(),
3628
+ number: z23.number().int().positive(),
3629
+ title: z23.string().min(1).optional(),
3630
+ updated_at: z23.string(),
3631
+ user: z23.object({ login: z23.string().min(1) }).strict()
4000
3632
  }).strict(),
4001
- repository: z22.object({
4002
- full_name: z22.string().min(1),
4003
- id: z22.number().int().positive()
3633
+ repository: z23.object({
3634
+ full_name: z23.string().min(1),
3635
+ id: z23.number().int().positive()
4004
3636
  }).strict()
4005
3637
  }).strict();
4006
- var pullRequestOutcomeSchema = z22.object({
4007
- action: z22.enum(["opened", "closed", "reopened"]),
4008
- pull_request: z22.object({
4009
- body: z22.string().nullable().optional(),
4010
- closed_at: z22.string().nullable().optional(),
4011
- created_at: z22.string(),
4012
- id: z22.number().int().positive(),
4013
- merged: z22.boolean(),
4014
- merged_at: z22.string().nullable().optional(),
4015
- number: z22.number().int().positive(),
4016
- title: z22.string().min(1).optional(),
4017
- updated_at: z22.string(),
4018
- user: z22.object({ login: z22.string().min(1) }).passthrough()
3638
+ var pullRequestOutcomeSchema = z23.object({
3639
+ action: z23.enum(["opened", "closed", "reopened"]),
3640
+ pull_request: z23.object({
3641
+ body: z23.string().nullable().optional(),
3642
+ closed_at: z23.string().nullable().optional(),
3643
+ created_at: z23.string(),
3644
+ id: z23.number().int().positive(),
3645
+ merged: z23.boolean(),
3646
+ merged_at: z23.string().nullable().optional(),
3647
+ number: z23.number().int().positive(),
3648
+ title: z23.string().min(1).optional(),
3649
+ updated_at: z23.string(),
3650
+ user: z23.object({ login: z23.string().min(1) }).passthrough()
4019
3651
  }).passthrough(),
4020
- repository: z22.object({
4021
- full_name: z22.string().min(1),
4022
- id: z22.number().int().positive()
3652
+ repository: z23.object({
3653
+ full_name: z23.string().min(1),
3654
+ id: z23.number().int().positive()
4023
3655
  }).passthrough()
4024
3656
  }).passthrough().transform(
4025
3657
  (provider) => canonicalPullRequestOutcomeSchema.parse({
@@ -4042,24 +3674,24 @@ var pullRequestOutcomeSchema = z22.object({
4042
3674
  }
4043
3675
  })
4044
3676
  );
4045
- var pullRequestLifecycleActionSchema = z22.object({ action: z22.string() }).passthrough();
4046
- var canonicalPullRequestConversationSchema = z22.object({
4047
- pull_request: z22.object({
4048
- body: z22.string().nullable().optional(),
4049
- id: z22.number().int().positive(),
4050
- user: z22.object({ login: z22.string().min(1) }).strict()
3677
+ var pullRequestLifecycleActionSchema = z23.object({ action: z23.string() }).passthrough();
3678
+ var canonicalPullRequestConversationSchema = z23.object({
3679
+ pull_request: z23.object({
3680
+ body: z23.string().nullable().optional(),
3681
+ id: z23.number().int().positive(),
3682
+ user: z23.object({ login: z23.string().min(1) }).strict()
4051
3683
  }).strict(),
4052
- repository: z22.object({ full_name: z22.string().min(1) }).strict(),
4053
- sender: z22.object({ login: z22.string().min(1) }).strict()
3684
+ repository: z23.object({ full_name: z23.string().min(1) }).strict(),
3685
+ sender: z23.object({ login: z23.string().min(1) }).strict()
4054
3686
  }).strict();
4055
- var pullRequestConversationSchema = z22.object({
4056
- pull_request: z22.object({
4057
- body: z22.string().nullable().optional(),
4058
- id: z22.number().int().positive(),
4059
- user: z22.object({ login: z22.string().min(1) }).passthrough()
3687
+ var pullRequestConversationSchema = z23.object({
3688
+ pull_request: z23.object({
3689
+ body: z23.string().nullable().optional(),
3690
+ id: z23.number().int().positive(),
3691
+ user: z23.object({ login: z23.string().min(1) }).passthrough()
4060
3692
  }).passthrough(),
4061
- repository: z22.object({ full_name: z22.string().min(1) }).passthrough(),
4062
- sender: z22.object({ login: z22.string().min(1) }).passthrough()
3693
+ repository: z23.object({ full_name: z23.string().min(1) }).passthrough(),
3694
+ sender: z23.object({ login: z23.string().min(1) }).passthrough()
4063
3695
  }).passthrough().transform(
4064
3696
  (provider) => canonicalPullRequestConversationSchema.parse({
4065
3697
  pull_request: {
@@ -4146,20 +3778,20 @@ function normalizeGitHubPullRequestLinkedIssues(args) {
4146
3778
  }
4147
3779
 
4148
3780
  // src/webhooks/merge-conflict.ts
4149
- import { z as z23 } from "zod";
3781
+ import * as z24 from "zod";
4150
3782
  var EVENT_TYPE = "pull_request.merge_conflict";
4151
3783
  var CLOSED_EVENT_TYPES = /* @__PURE__ */ new Set([
4152
3784
  "pull_request.closed_unmerged",
4153
3785
  "pull_request.merged"
4154
3786
  ]);
4155
- var pullRequestSchema3 = z23.object({
4156
- base: z23.object({ ref: z23.string().min(1) }),
4157
- number: z23.number().int().positive().optional(),
4158
- head: z23.object({ sha: z23.string().min(1) }),
4159
- html_url: z23.string().min(1).optional(),
4160
- mergeable: z23.boolean().nullable().optional(),
4161
- mergeable_state: z23.string().optional(),
4162
- state: z23.string()
3787
+ var pullRequestSchema3 = z24.object({
3788
+ base: z24.object({ ref: z24.string().min(1) }),
3789
+ number: z24.number().int().positive().optional(),
3790
+ head: z24.object({ sha: z24.string().min(1) }),
3791
+ html_url: z24.string().min(1).optional(),
3792
+ mergeable: z24.boolean().nullable().optional(),
3793
+ mergeable_state: z24.string().optional(),
3794
+ state: z24.string()
4163
3795
  });
4164
3796
  function gitHubMergeConflictEvents(input) {
4165
3797
  const { conflict } = input;
@@ -4199,7 +3831,7 @@ async function hasMatch(hasMatchEvent, ref) {
4199
3831
  return false;
4200
3832
  }
4201
3833
  function deliveredPullRequest(payload, ref) {
4202
- const parsed = z23.object({ pull_request: pullRequestSchema3 }).safeParse(payload);
3834
+ const parsed = z24.object({ pull_request: pullRequestSchema3 }).safeParse(payload);
4203
3835
  const pullRequest = parsed.success ? parsed.data.pull_request : void 0;
4204
3836
  return pullRequest?.number === ref.number && typeof pullRequest.mergeable === "boolean" ? pullRequest : void 0;
4205
3837
  }
@@ -4237,10 +3869,10 @@ async function loadGitHubMergeConflictEvents(args) {
4237
3869
  }
4238
3870
 
4239
3871
  // src/webhooks/pull-request-ready.ts
4240
- import { z as z25 } from "zod";
3872
+ import * as z26 from "zod";
4241
3873
 
4242
3874
  // src/webhooks/installation-requests.ts
4243
- import { z as z24 } from "zod";
3875
+ import * as z25 from "zod";
4244
3876
  function splitRepository(fullName, label) {
4245
3877
  const [owner, name, ...extra] = fullName.split("/");
4246
3878
  if (!owner || !name || extra.length > 0) {
@@ -4301,9 +3933,9 @@ async function markPullRequestFeedbackReviewing(env, target) {
4301
3933
  }
4302
3934
  );
4303
3935
  }
4304
- var repositoryPermissionSchema = z24.object({
4305
- permission: z24.string().min(1),
4306
- role_name: z24.string().optional()
3936
+ var repositoryPermissionSchema = z25.object({
3937
+ permission: z25.string().min(1),
3938
+ role_name: z25.string().optional()
4307
3939
  });
4308
3940
  var REPOSITORY_ROLE_TTL_MS = 10 * 60 * 1e3;
4309
3941
  async function loadRepositoryRole(env, cache, target) {
@@ -4333,18 +3965,18 @@ async function loadRepositoryRole(env, cache, target) {
4333
3965
  }
4334
3966
  );
4335
3967
  }
4336
- var pullRequestSchema4 = z24.object({
4337
- draft: z24.boolean().optional(),
4338
- html_url: z24.string().url(),
4339
- mergeable_state: z24.string().nullable().optional(),
4340
- merged: z24.boolean(),
4341
- state: z24.enum(["open", "closed"]),
4342
- title: z24.string()
3968
+ var pullRequestSchema4 = z25.object({
3969
+ draft: z25.boolean().optional(),
3970
+ html_url: z25.string().url(),
3971
+ mergeable_state: z25.string().nullable().optional(),
3972
+ merged: z25.boolean(),
3973
+ state: z25.enum(["open", "closed"]),
3974
+ title: z25.string()
4343
3975
  });
4344
- var reviewsSchema = z24.array(
4345
- z24.object({
4346
- state: z24.string(),
4347
- user: z24.object({ login: z24.string() }).nullable()
3976
+ var reviewsSchema = z25.array(
3977
+ z25.object({
3978
+ state: z25.string(),
3979
+ user: z25.object({ login: z25.string() }).nullable()
4348
3980
  })
4349
3981
  );
4350
3982
  async function loadPullRequestMergeState(env, pullRequest) {
@@ -4409,10 +4041,10 @@ var READY_ACTIONS = {
4409
4041
  ]),
4410
4042
  pull_request_review: /* @__PURE__ */ new Set(["dismissed", "submitted"])
4411
4043
  };
4412
- var pullRequestWebhookSchema = z25.object({
4413
- action: z25.string(),
4414
- pull_request: z25.object({ number: z25.number().int().positive() }),
4415
- repository: z25.object({ full_name: z25.string().min(1) })
4044
+ var pullRequestWebhookSchema = z26.object({
4045
+ action: z26.string(),
4046
+ pull_request: z26.object({ number: z26.number().int().positive() }),
4047
+ repository: z26.object({ full_name: z26.string().min(1) })
4416
4048
  });
4417
4049
  function pullRequestReadyTargets(eventName, body) {
4418
4050
  if (eventName === "check_suite") return checkSuitePullRequests(body);
@@ -4507,7 +4139,7 @@ async function syncGitHubPullRequestReadyNotices(args) {
4507
4139
  }
4508
4140
 
4509
4141
  // src/webhooks/pull-request-match-data.ts
4510
- import { z as z26 } from "zod";
4142
+ import * as z27 from "zod";
4511
4143
  var LOOKUPS_BY_MATCH_KEY = {
4512
4144
  authors: ["authors"],
4513
4145
  openerEmail: ["opener"],
@@ -4515,22 +4147,22 @@ var LOOKUPS_BY_MATCH_KEY = {
4515
4147
  openerUsername: ["opener"]
4516
4148
  };
4517
4149
  var ALL_LOOKUPS = ["authors", "opener", "openerRole"];
4518
- var lookupDataSchema = z26.object({
4519
- authors: z26.array(z26.string().min(1)).min(1).optional(),
4520
- openerRole: z26.string().min(1).optional(),
4521
- openerUsername: z26.string().min(1).optional()
4150
+ var lookupDataSchema = z27.object({
4151
+ authors: z27.array(z27.string().min(1)).min(1).optional(),
4152
+ openerRole: z27.string().min(1).optional(),
4153
+ openerUsername: z27.string().min(1).optional()
4522
4154
  }).strict();
4523
4155
  function lookupData(input) {
4524
4156
  return lookupDataSchema.parse(definedValues(input));
4525
4157
  }
4526
- var webhookSchema = z26.object({
4527
- repository: z26.object({ full_name: z26.string().min(1) })
4158
+ var webhookSchema = z27.object({
4159
+ repository: z27.object({ full_name: z27.string().min(1) })
4528
4160
  });
4529
4161
  function pullRequestNumbers(events) {
4530
4162
  const numbers = /* @__PURE__ */ new Map();
4531
4163
  for (const event of events) {
4532
- const number = event.data?.pullRequest;
4533
- if (typeof number === "number") numbers.set(event.eventKey, number);
4164
+ const number22 = event.data?.pullRequest;
4165
+ if (typeof number22 === "number") numbers.set(event.eventKey, number22);
4534
4166
  }
4535
4167
  return numbers;
4536
4168
  }
@@ -4544,8 +4176,8 @@ function logFailure(context, lookup, error) {
4544
4176
  }
4545
4177
  async function withJuniorOpeners(context, events) {
4546
4178
  const botNumber = (event) => {
4547
- const number = context.numbers.get(event.eventKey);
4548
- return number !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number : void 0;
4179
+ const number22 = context.numbers.get(event.eventKey);
4180
+ return number22 !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number22 : void 0;
4549
4181
  };
4550
4182
  const numbers = events.flatMap((event) => botNumber(event) ?? []);
4551
4183
  if (numbers.length === 0) return events;
@@ -4564,9 +4196,9 @@ async function withJuniorOpeners(context, events) {
4564
4196
  }
4565
4197
  }
4566
4198
  return events.map((event) => {
4567
- const number = botNumber(event);
4568
- if (number === void 0) return event;
4569
- const identityId = openers.get(number)?.identityId;
4199
+ const number22 = botNumber(event);
4200
+ if (number22 === void 0) return event;
4201
+ const identityId = openers.get(number22)?.identityId;
4570
4202
  const login = identityId ? logins.get(identityId) : void 0;
4571
4203
  const {
4572
4204
  openerEmail: _email,
@@ -4588,8 +4220,8 @@ async function withRolesAndAuthors(context, events, lookups) {
4588
4220
  if (!loadRole && !loadAuthors) return events;
4589
4221
  return await Promise.all(
4590
4222
  events.map(async (event) => {
4591
- const number = context.numbers.get(event.eventKey);
4592
- if (number === void 0) return event;
4223
+ const number22 = context.numbers.get(event.eventKey);
4224
+ if (number22 === void 0) return event;
4593
4225
  const login = event.data?.openerUsername;
4594
4226
  if (loadRole && typeof login === "string" && !roles.has(login)) {
4595
4227
  roles.set(
@@ -4599,16 +4231,16 @@ async function withRolesAndAuthors(context, events, lookups) {
4599
4231
  )
4600
4232
  );
4601
4233
  }
4602
- if (loadAuthors && !authors.has(number)) {
4234
+ if (loadAuthors && !authors.has(number22)) {
4603
4235
  authors.set(
4604
- number,
4605
- loadAuthors({ number, repositoryFullName }).catch(
4236
+ number22,
4237
+ loadAuthors({ number: number22, repositoryFullName }).catch(
4606
4238
  (error) => logFailure(context, "authors", error)
4607
4239
  )
4608
4240
  );
4609
4241
  }
4610
4242
  const role = loadRole && typeof login === "string" ? await roles.get(login) : void 0;
4611
- const logins = loadAuthors ? await authors.get(number) : void 0;
4243
+ const logins = loadAuthors ? await authors.get(number22) : void 0;
4612
4244
  if (!role && !logins?.length) return event;
4613
4245
  return {
4614
4246
  ...event,
@@ -4667,7 +4299,7 @@ async function withGitHubPullRequestMatchData(args) {
4667
4299
  }
4668
4300
 
4669
4301
  // src/webhooks/pull-request-people.ts
4670
- import { z as z27 } from "zod";
4302
+ import * as z28 from "zod";
4671
4303
  var PEOPLE_EVENTS = /* @__PURE__ */ new Set([
4672
4304
  "pull_request.review.approved",
4673
4305
  "pull_request.merged"
@@ -4677,18 +4309,18 @@ var PAGE_SIZE = 100;
4677
4309
  var MAX_PAGES = 3;
4678
4310
  var CO_AUTHOR_TRAILER = /^co-authored-by:[^<\n]*<([^>\s]+@[^>\s]+)>\s*$/gim;
4679
4311
  var GITHUB_NOREPLY_EMAIL = /^(?:\d+\+)?(?<login>[^@+]+)@users\.noreply\.github\.com$/i;
4680
- var webhookSchema2 = z27.object({
4681
- pull_request: z27.object({
4682
- assignees: z27.array(z27.object({ login: z27.string().min(1) })).nullish(),
4683
- number: z27.number(),
4684
- user: z27.object({ login: z27.string().min(1) }).nullish()
4312
+ var webhookSchema2 = z28.object({
4313
+ pull_request: z28.object({
4314
+ assignees: z28.array(z28.object({ login: z28.string().min(1) })).nullish(),
4315
+ number: z28.number(),
4316
+ user: z28.object({ login: z28.string().min(1) }).nullish()
4685
4317
  }),
4686
- repository: z27.object({ full_name: z27.string().min(1) })
4318
+ repository: z28.object({ full_name: z28.string().min(1) })
4687
4319
  });
4688
- var commitPageSchema = z27.array(
4689
- z27.object({
4690
- author: z27.object({ login: z27.string().min(1) }).nullish(),
4691
- commit: z27.object({ message: z27.string() })
4320
+ var commitPageSchema = z28.array(
4321
+ z28.object({
4322
+ author: z28.object({ login: z28.string().min(1) }).nullish(),
4323
+ commit: z28.object({ message: z28.string() })
4692
4324
  })
4693
4325
  );
4694
4326
  function shareCommitPages(load) {
@@ -4833,10 +4465,10 @@ function webhookInstallationId(body) {
4833
4465
  }
4834
4466
  return parseInstallationId(installation.id);
4835
4467
  }
4836
- var feedbackTargetSchema = z28.object({
4837
- commentId: z28.number(),
4838
- commentKind: z28.enum(["conversation", "review"]),
4839
- repo: z28.string().min(1)
4468
+ var feedbackTargetSchema = z29.object({
4469
+ commentId: z29.number(),
4470
+ commentKind: z29.enum(["conversation", "review"]),
4471
+ repo: z29.string().min(1)
4840
4472
  });
4841
4473
  function pullRequestFeedbackTarget(events) {
4842
4474
  const event = events.find(
@@ -5107,30 +4739,30 @@ function gitHubResourceUrl(input) {
5107
4739
  if (input.resourceType === "repository") {
5108
4740
  return `https://github.com/${input.identifier}`;
5109
4741
  }
5110
- const [repo, number] = input.identifier.split("#");
5111
- if (!repo || !number) return void 0;
4742
+ const [repo, number22] = input.identifier.split("#");
4743
+ if (!repo || !number22) return void 0;
5112
4744
  if (input.resourceType === "pull_request") {
5113
- return `https://github.com/${repo}/pull/${number}`;
4745
+ return `https://github.com/${repo}/pull/${number22}`;
5114
4746
  }
5115
4747
  if (input.resourceType === "issue") {
5116
- return `https://github.com/${repo}/issues/${number}`;
4748
+ return `https://github.com/${repo}/issues/${number22}`;
5117
4749
  }
5118
4750
  return void 0;
5119
4751
  }
5120
4752
 
5121
4753
  // src/pull-request-outcomes/commit-composition.ts
5122
- import { z as z29 } from "zod";
5123
- var canonicalCommitSchema = z29.object({
5124
- authorEmail: z29.string().nullable(),
5125
- authorLogin: z29.string().nullable()
4754
+ import * as z30 from "zod";
4755
+ var canonicalCommitSchema = z30.object({
4756
+ authorEmail: z30.string().nullable(),
4757
+ authorLogin: z30.string().nullable()
5126
4758
  }).strict();
5127
- var providerCommitSchema = z29.object({
5128
- author: z29.object({ login: z29.string() }).passthrough().nullable(),
5129
- commit: z29.object({
5130
- author: z29.object({ email: z29.string() }).passthrough().nullable()
4759
+ var providerCommitSchema = z30.object({
4760
+ author: z30.object({ login: z30.string() }).passthrough().nullable(),
4761
+ commit: z30.object({
4762
+ author: z30.object({ email: z30.string() }).passthrough().nullable()
5131
4763
  }).passthrough()
5132
4764
  }).passthrough();
5133
- var commitPageSchema2 = z29.array(providerCommitSchema).transform(
4765
+ var commitPageSchema2 = z30.array(providerCommitSchema).transform(
5134
4766
  (commits) => commits.map(
5135
4767
  (commit) => canonicalCommitSchema.parse({
5136
4768
  authorEmail: commit.commit.author?.email ?? null,
@@ -5637,8 +5269,8 @@ function linkifyLine(line) {
5637
5269
  if (isReferenceBoundary(index2 === 0 ? void 0 : line[index2 - 1])) {
5638
5270
  const match = GITHUB_ISSUE_REFERENCE_PATTERN.exec(line.slice(index2));
5639
5271
  if (match) {
5640
- const [reference, owner, repository2, number] = match;
5641
- output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number})`;
5272
+ const [reference, owner, repository2, number22] = match;
5273
+ output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number22})`;
5642
5274
  index2 += reference.length;
5643
5275
  continue;
5644
5276
  }
@@ -5780,9 +5412,9 @@ function parseGitHubReferences(text2, config) {
5780
5412
  }
5781
5413
  return [...references.values()];
5782
5414
  }
5783
- function objectTitle(kind, object) {
5784
- if (!isRecord(object)) return void 0;
5785
- const raw = kind === "commit" ? isRecord(object.commit) && typeof object.commit.message === "string" ? object.commit.message.split("\n")[0] : void 0 : typeof object.title === "string" ? object.title : void 0;
5415
+ function objectTitle(kind, object30) {
5416
+ if (!isRecord(object30)) return void 0;
5417
+ const raw = kind === "commit" ? isRecord(object30.commit) && typeof object30.commit.message === "string" ? object30.commit.message.split("\n")[0] : void 0 : typeof object30.title === "string" ? object30.title : void 0;
5786
5418
  return raw?.replace(/\s+/g, " ").trim() || void 0;
5787
5419
  }
5788
5420
  async function loadGitHubConversationTitleContext(args) {
@@ -6210,7 +5842,7 @@ function shouldInspectGitHubGraphqlResponse(ctx) {
6210
5842
  var GITHUB_ERROR_BODY_LIMIT_BYTES = 4 * 1024;
6211
5843
  var GITHUB_ACCESS_DENIED_MESSAGE = "Resource not accessible by integration";
6212
5844
  var GITHUB_ACCEPTED_PERMISSIONS_PATTERN = /^[a-z_]+=[a-z]+(?:\s*[,;]\s*[a-z_]+=[a-z]+)*$/;
6213
- function githubErrorMessage(bodyText) {
5845
+ function githubErrorMessage2(bodyText) {
6214
5846
  if (!bodyText) {
6215
5847
  return void 0;
6216
5848
  }
@@ -6227,7 +5859,7 @@ async function githubForbiddenPermissionDeniedMessage(ctx) {
6227
5859
  const url = sso.match(/\burl=(https:\/\/github\.com\/\S+)/)?.[1];
6228
5860
  return `GitHub requires SAML SSO authorization for this credential.${url ? ` Authorize it at ${url}` : ""}`;
6229
5861
  }
6230
- const message = githubErrorMessage(
5862
+ const message = githubErrorMessage2(
6231
5863
  await ctx.response.readText(GITHUB_ERROR_BODY_LIMIT_BYTES)
6232
5864
  );
6233
5865
  if (message !== GITHUB_ACCESS_DENIED_MESSAGE) {
@@ -6649,26 +6281,17 @@ function githubPlugin(options = {}) {
6649
6281
  operation: "github.pull.get"
6650
6282
  }
6651
6283
  }[reference.kind];
6652
- const response = await ctx.egress.fetch({
6653
- provider: "github",
6284
+ const response = await githubApi(ctx.egress, {
6654
6285
  operation,
6655
- request: new Request(
6656
- `https://api.github.com/repos/${encodeURIComponent(reference.owner)}/${encodeURIComponent(reference.name)}/${collection}/${encodeURIComponent(reference.id)}`,
6657
- {
6658
- headers: {
6659
- Accept: "application/vnd.github+json",
6660
- "X-GitHub-Api-Version": "2022-11-28"
6661
- },
6662
- signal: ctx.signal
6663
- }
6664
- )
6286
+ path: `${repoPath(reference)}/${collection}/${encodeURIComponent(reference.id)}`,
6287
+ signal: ctx.signal
6665
6288
  });
6666
6289
  if (!response.ok) {
6667
6290
  throw new Error(
6668
6291
  `GitHub ${reference.kind} lookup failed with HTTP ${response.status}`
6669
6292
  );
6670
6293
  }
6671
- return await response.json();
6294
+ return response.body;
6672
6295
  }
6673
6296
  });
6674
6297
  },