@sentry/junior-github 0.296.0 → 0.298.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/annotations.d.ts +13 -2
- package/dist/{chunk-D74ZUIJR.js → chunk-OK6BNAGC.js} +44 -10
- package/dist/events/pull-request.d.ts +7 -2
- package/dist/index.js +1338 -877
- package/dist/pull-request-outcomes/apply.d.ts +20 -0
- package/dist/pull-request-outcomes/reconcile.d.ts +36 -0
- package/dist/pull-request-outcomes/store.d.ts +9 -0
- package/dist/testing.js +1 -1
- package/dist/tools/react-to-issue.d.ts +137 -0
- package/dist/tools/update-issue-comment.d.ts +138 -0
- package/dist/tools/update-issue.d.ts +2 -4
- package/dist/tools/update-pull-request.d.ts +2 -4
- package/dist/webhooks/events.d.ts +6 -0
- package/dist/webhooks/installation-requests.d.ts +8 -0
- package/dist/webhooks/pull-request-activity.d.ts +11 -0
- package/package.json +2 -2
- package/skills/github-code/SKILL.md +2 -0
- package/skills/github-issues/SKILL.md +4 -4
- package/skills/github-issues/references/api-surface.md +3 -1
package/dist/index.js
CHANGED
|
@@ -38,6 +38,8 @@ import {
|
|
|
38
38
|
gitHubPullRequestEventGuidance,
|
|
39
39
|
gitHubPullRequestResource,
|
|
40
40
|
gitHubPullRequestSubscribable,
|
|
41
|
+
gitHubPullRequestSubscription,
|
|
42
|
+
gitHubPullRequestTerminalEvents,
|
|
41
43
|
gitHubReleaseSourceSubscribable,
|
|
42
44
|
gitHubRepoDataSchema,
|
|
43
45
|
gitHubRepositorySubscribable,
|
|
@@ -59,7 +61,7 @@ import {
|
|
|
59
61
|
readGrantPermissions,
|
|
60
62
|
requireEnv,
|
|
61
63
|
resolveUserAccount
|
|
62
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-OK6BNAGC.js";
|
|
63
65
|
|
|
64
66
|
// src/tool-support/attribution.ts
|
|
65
67
|
import * as z from "zod";
|
|
@@ -280,13 +282,81 @@ import {
|
|
|
280
282
|
mergeEventMatchFields
|
|
281
283
|
} from "@sentry/junior-plugin-api";
|
|
282
284
|
|
|
283
|
-
// src/tools/
|
|
285
|
+
// src/tools/react-to-issue.ts
|
|
284
286
|
import {
|
|
285
287
|
definePluginTool,
|
|
286
288
|
PluginToolInputError as PluginToolInputError2,
|
|
287
289
|
pluginToolOutputSchema
|
|
288
290
|
} from "@sentry/junior-plugin-api";
|
|
289
291
|
import * as z2 from "zod";
|
|
292
|
+
var REACTION_CONTENTS = [
|
|
293
|
+
"+1",
|
|
294
|
+
"-1",
|
|
295
|
+
"laugh",
|
|
296
|
+
"confused",
|
|
297
|
+
"heart",
|
|
298
|
+
"hooray",
|
|
299
|
+
"rocket",
|
|
300
|
+
"eyes"
|
|
301
|
+
];
|
|
302
|
+
var inputSchema = z2.object({
|
|
303
|
+
repo: z2.string().describe('Repository in "owner/name" format.'),
|
|
304
|
+
number: z2.number().int().positive().describe("Issue or pull request number."),
|
|
305
|
+
content: z2.enum(REACTION_CONTENTS).describe("Reaction to add.")
|
|
306
|
+
}).strict();
|
|
307
|
+
var outputSchema = pluginToolOutputSchema.extend({
|
|
308
|
+
target: z2.literal("reactToIssue"),
|
|
309
|
+
repo: z2.string(),
|
|
310
|
+
number: z2.number(),
|
|
311
|
+
content: z2.enum(REACTION_CONTENTS),
|
|
312
|
+
reaction_id: z2.number()
|
|
313
|
+
});
|
|
314
|
+
function createGitHubReactToIssueTool(egress) {
|
|
315
|
+
return definePluginTool({
|
|
316
|
+
annotations: {
|
|
317
|
+
destructiveHint: false,
|
|
318
|
+
// GitHub returns the existing reaction when the bot already added it.
|
|
319
|
+
idempotentHint: true,
|
|
320
|
+
openWorldHint: true,
|
|
321
|
+
readOnlyHint: false
|
|
322
|
+
},
|
|
323
|
+
description: "React with an emoji to a GitHub issue or pull request itself, for example to show that you started work on it. Reacting again with the same content changes nothing.",
|
|
324
|
+
inputSchema,
|
|
325
|
+
outputSchema,
|
|
326
|
+
async execute(input) {
|
|
327
|
+
const repo = parseRepo(input.repo);
|
|
328
|
+
const response = await githubApi(egress, {
|
|
329
|
+
operation: "github.issue.reaction.create",
|
|
330
|
+
method: "POST",
|
|
331
|
+
path: `${repoPath(repo)}/issues/${input.number}/reactions`,
|
|
332
|
+
body: { content: input.content }
|
|
333
|
+
});
|
|
334
|
+
if (!response.ok) {
|
|
335
|
+
const message = `GitHub issue reaction failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
|
|
336
|
+
if (response.status === 404 || response.status === 422) {
|
|
337
|
+
throw new PluginToolInputError2(message);
|
|
338
|
+
}
|
|
339
|
+
throw new Error(message);
|
|
340
|
+
}
|
|
341
|
+
const reaction = z2.object({ id: z2.number() }).parse(response.body);
|
|
342
|
+
return {
|
|
343
|
+
target: "reactToIssue",
|
|
344
|
+
repo: repo.ref,
|
|
345
|
+
number: input.number,
|
|
346
|
+
content: input.content,
|
|
347
|
+
reaction_id: reaction.id
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/tools/clone-repository.ts
|
|
354
|
+
import {
|
|
355
|
+
definePluginTool as definePluginTool2,
|
|
356
|
+
PluginToolInputError as PluginToolInputError3,
|
|
357
|
+
pluginToolOutputSchema as pluginToolOutputSchema2
|
|
358
|
+
} from "@sentry/junior-plugin-api";
|
|
359
|
+
import * as z3 from "zod";
|
|
290
360
|
|
|
291
361
|
// src/sandbox-paths.ts
|
|
292
362
|
var RESERVED_SANDBOX_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
@@ -299,9 +369,9 @@ function isReservedSandboxDirectory(path) {
|
|
|
299
369
|
}
|
|
300
370
|
|
|
301
371
|
// src/tools/clone-repository.ts
|
|
302
|
-
var
|
|
303
|
-
repo:
|
|
304
|
-
directory:
|
|
372
|
+
var inputSchema2 = z3.object({
|
|
373
|
+
repo: z3.string().describe('Repository in "owner/name" format.'),
|
|
374
|
+
directory: z3.string().regex(/^(?:[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*)$/).refine(
|
|
305
375
|
(value) => !value.split("/").some((part) => part === "." || part === ".."),
|
|
306
376
|
{
|
|
307
377
|
message: "Directory must be a relative path without . or .. segments."
|
|
@@ -309,24 +379,24 @@ var inputSchema = z2.object({
|
|
|
309
379
|
).describe(
|
|
310
380
|
"Optional destination directory under the sandbox root. Defaults to repos/{name}."
|
|
311
381
|
).optional(),
|
|
312
|
-
allow_ad_hoc:
|
|
382
|
+
allow_ad_hoc: z3.boolean().optional().describe(
|
|
313
383
|
"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."
|
|
314
384
|
)
|
|
315
385
|
}).strict();
|
|
316
|
-
var cloneSchema =
|
|
317
|
-
path:
|
|
318
|
-
repo:
|
|
319
|
-
note:
|
|
386
|
+
var cloneSchema = z3.object({
|
|
387
|
+
path: z3.string(),
|
|
388
|
+
repo: z3.string(),
|
|
389
|
+
note: z3.string().optional()
|
|
320
390
|
});
|
|
321
|
-
var
|
|
391
|
+
var outputSchema2 = pluginToolOutputSchema2.merge(
|
|
322
392
|
cloneSchema.extend({
|
|
323
|
-
target:
|
|
393
|
+
target: z3.literal("cloneRepository")
|
|
324
394
|
})
|
|
325
395
|
);
|
|
326
396
|
function parseRepo2(value) {
|
|
327
397
|
const parts = value.split("/").map((part) => part.trim());
|
|
328
398
|
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
329
|
-
throw new
|
|
399
|
+
throw new PluginToolInputError3('repo must use "owner/name" format');
|
|
330
400
|
}
|
|
331
401
|
return { owner: parts[0], name: parts[1] };
|
|
332
402
|
}
|
|
@@ -336,11 +406,11 @@ function quotedNames(workspaces) {
|
|
|
336
406
|
function workspaceRequiredError(repoId, workspaces) {
|
|
337
407
|
const names = quotedNames(workspaces);
|
|
338
408
|
if (workspaces.length === 1) {
|
|
339
|
-
return new
|
|
409
|
+
return new PluginToolInputError3(
|
|
340
410
|
`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.`
|
|
341
411
|
);
|
|
342
412
|
}
|
|
343
|
-
return new
|
|
413
|
+
return new PluginToolInputError3(
|
|
344
414
|
`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.`
|
|
345
415
|
);
|
|
346
416
|
}
|
|
@@ -378,7 +448,7 @@ async function removePartialClone(ctx, path) {
|
|
|
378
448
|
}
|
|
379
449
|
}
|
|
380
450
|
function createGitHubCloneRepositoryTool(ctx) {
|
|
381
|
-
return
|
|
451
|
+
return definePluginTool2({
|
|
382
452
|
annotations: {
|
|
383
453
|
// Remote GitHub effect is contents-read only. Sandbox checkout creation is
|
|
384
454
|
// the same class of ephemeral local materialization as webFetch artifacts,
|
|
@@ -395,8 +465,8 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
395
465
|
return directory ? `Shallow-clone ${input.repo} into the local sandbox at ${directory}${adHoc} for inspection (no GitHub mutation).` : `Shallow-clone ${input.repo} into the local sandbox${adHoc} for inspection (no GitHub mutation).`;
|
|
396
466
|
},
|
|
397
467
|
executionMode: "sequential",
|
|
398
|
-
inputSchema,
|
|
399
|
-
outputSchema,
|
|
468
|
+
inputSchema: inputSchema2,
|
|
469
|
+
outputSchema: outputSchema2,
|
|
400
470
|
async execute(input, options) {
|
|
401
471
|
const repo = parseRepo2(input.repo);
|
|
402
472
|
const repoId = `${repo.owner}/${repo.name}`;
|
|
@@ -426,7 +496,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
426
496
|
const directory = input.directory ?? defaultDirectory(repo.name);
|
|
427
497
|
const rootSegment = directory.split("/")[0] ?? directory;
|
|
428
498
|
if (isReservedSandboxDirectory(rootSegment)) {
|
|
429
|
-
throw new
|
|
499
|
+
throw new PluginToolInputError3(
|
|
430
500
|
`Directory conflicts with a reserved sandbox path: ${directory}`
|
|
431
501
|
);
|
|
432
502
|
}
|
|
@@ -440,7 +510,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
440
510
|
signal: commandSignal(options.signal, 3e4)
|
|
441
511
|
});
|
|
442
512
|
if (mkdir.exitCode !== 0) {
|
|
443
|
-
throw new
|
|
513
|
+
throw new PluginToolInputError3(
|
|
444
514
|
`Failed to create clone parent directory: ${parentDirectory}`
|
|
445
515
|
);
|
|
446
516
|
}
|
|
@@ -452,7 +522,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
452
522
|
signal: commandSignal(options.signal, 3e4)
|
|
453
523
|
});
|
|
454
524
|
if (exists.exitCode === 0) {
|
|
455
|
-
throw new
|
|
525
|
+
throw new PluginToolInputError3(`destination already exists: ${path}`);
|
|
456
526
|
}
|
|
457
527
|
let clone;
|
|
458
528
|
try {
|
|
@@ -475,7 +545,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
475
545
|
}
|
|
476
546
|
if (clone.exitCode !== 0) {
|
|
477
547
|
await removePartialClone(ctx, path);
|
|
478
|
-
throw new
|
|
548
|
+
throw new PluginToolInputError3(
|
|
479
549
|
`GitHub repository clone failed: ${clone.stderr.trim() || `exit ${clone.exitCode}`}`
|
|
480
550
|
);
|
|
481
551
|
}
|
|
@@ -491,25 +561,25 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
491
561
|
|
|
492
562
|
// src/tools/comment-on-issue.ts
|
|
493
563
|
import {
|
|
494
|
-
definePluginTool as
|
|
495
|
-
PluginToolInputError as
|
|
496
|
-
pluginToolOutputSchema as
|
|
564
|
+
definePluginTool as definePluginTool3,
|
|
565
|
+
PluginToolInputError as PluginToolInputError4,
|
|
566
|
+
pluginToolOutputSchema as pluginToolOutputSchema3
|
|
497
567
|
} from "@sentry/junior-plugin-api";
|
|
498
|
-
import * as
|
|
499
|
-
var
|
|
500
|
-
repo:
|
|
501
|
-
number:
|
|
502
|
-
body:
|
|
568
|
+
import * as z4 from "zod";
|
|
569
|
+
var inputSchema3 = z4.object({
|
|
570
|
+
repo: z4.string().describe('Repository in "owner/name" format.'),
|
|
571
|
+
number: z4.number().int().positive().describe("Issue number."),
|
|
572
|
+
body: z4.string().trim().min(1).describe("Comment text.")
|
|
503
573
|
}).strict();
|
|
504
|
-
var
|
|
505
|
-
target:
|
|
506
|
-
repo:
|
|
507
|
-
number:
|
|
508
|
-
comment_id:
|
|
509
|
-
url:
|
|
574
|
+
var outputSchema3 = pluginToolOutputSchema3.extend({
|
|
575
|
+
target: z4.literal("commentOnIssue"),
|
|
576
|
+
repo: z4.string(),
|
|
577
|
+
number: z4.number(),
|
|
578
|
+
comment_id: z4.number(),
|
|
579
|
+
url: z4.string()
|
|
510
580
|
});
|
|
511
581
|
function createGitHubCommentOnIssueTool(egress) {
|
|
512
|
-
return
|
|
582
|
+
return definePluginTool3({
|
|
513
583
|
annotations: {
|
|
514
584
|
destructiveHint: false,
|
|
515
585
|
idempotentHint: false,
|
|
@@ -517,8 +587,8 @@ function createGitHubCommentOnIssueTool(egress) {
|
|
|
517
587
|
readOnlyHint: false
|
|
518
588
|
},
|
|
519
589
|
description: "Post a comment on a GitHub issue. Returns the comment id and URL.",
|
|
520
|
-
inputSchema:
|
|
521
|
-
outputSchema:
|
|
590
|
+
inputSchema: inputSchema3,
|
|
591
|
+
outputSchema: outputSchema3,
|
|
522
592
|
async execute(input) {
|
|
523
593
|
const repo = parseRepo(input.repo);
|
|
524
594
|
const response = await githubApi(egress, {
|
|
@@ -530,11 +600,11 @@ function createGitHubCommentOnIssueTool(egress) {
|
|
|
530
600
|
if (!response.ok) {
|
|
531
601
|
const message = `GitHub issue comment failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
|
|
532
602
|
if (response.status === 404 || response.status === 422) {
|
|
533
|
-
throw new
|
|
603
|
+
throw new PluginToolInputError4(message);
|
|
534
604
|
}
|
|
535
605
|
throw new Error(message);
|
|
536
606
|
}
|
|
537
|
-
const comment =
|
|
607
|
+
const comment = z4.object({ id: z4.number(), html_url: z4.string() }).parse(response.body);
|
|
538
608
|
return {
|
|
539
609
|
target: "commentOnIssue",
|
|
540
610
|
repo: repo.ref,
|
|
@@ -548,25 +618,25 @@ function createGitHubCommentOnIssueTool(egress) {
|
|
|
548
618
|
|
|
549
619
|
// src/tools/comment-on-pull-request.ts
|
|
550
620
|
import {
|
|
551
|
-
definePluginTool as
|
|
552
|
-
PluginToolInputError as
|
|
553
|
-
pluginToolOutputSchema as
|
|
621
|
+
definePluginTool as definePluginTool4,
|
|
622
|
+
PluginToolInputError as PluginToolInputError5,
|
|
623
|
+
pluginToolOutputSchema as pluginToolOutputSchema4
|
|
554
624
|
} from "@sentry/junior-plugin-api";
|
|
555
|
-
import * as
|
|
556
|
-
var
|
|
557
|
-
repo:
|
|
558
|
-
number:
|
|
559
|
-
body:
|
|
560
|
-
in_reply_to:
|
|
625
|
+
import * as z5 from "zod";
|
|
626
|
+
var inputSchema4 = z5.object({
|
|
627
|
+
repo: z5.string().describe('Repository in "owner/name" format.'),
|
|
628
|
+
number: z5.number().int().positive().describe("Pull request number."),
|
|
629
|
+
body: z5.string().trim().min(1).describe("Comment text."),
|
|
630
|
+
in_reply_to: z5.number().int().positive().optional().describe(
|
|
561
631
|
"Inline review comment id. Set it to reply in that comment's thread. Omit it to comment on the pull request."
|
|
562
632
|
)
|
|
563
633
|
}).strict();
|
|
564
|
-
var
|
|
565
|
-
target:
|
|
566
|
-
repo:
|
|
567
|
-
number:
|
|
568
|
-
comment_id:
|
|
569
|
-
url:
|
|
634
|
+
var outputSchema4 = pluginToolOutputSchema4.extend({
|
|
635
|
+
target: z5.literal("commentOnPullRequest"),
|
|
636
|
+
repo: z5.string(),
|
|
637
|
+
number: z5.number(),
|
|
638
|
+
comment_id: z5.number(),
|
|
639
|
+
url: z5.string()
|
|
570
640
|
});
|
|
571
641
|
async function threadRootId(egress, prefix, commentId) {
|
|
572
642
|
const response = await githubApi(egress, {
|
|
@@ -575,14 +645,14 @@ async function threadRootId(egress, prefix, commentId) {
|
|
|
575
645
|
});
|
|
576
646
|
if (!response.ok) {
|
|
577
647
|
const message = `GitHub review comment lookup failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
|
|
578
|
-
if (response.status === 404) throw new
|
|
648
|
+
if (response.status === 404) throw new PluginToolInputError5(message);
|
|
579
649
|
throw new Error(message);
|
|
580
650
|
}
|
|
581
|
-
const comment =
|
|
651
|
+
const comment = z5.object({ in_reply_to_id: z5.number().nullish() }).parse(response.body);
|
|
582
652
|
return comment.in_reply_to_id ?? commentId;
|
|
583
653
|
}
|
|
584
654
|
function createGitHubCommentOnPullRequestTool(egress) {
|
|
585
|
-
return
|
|
655
|
+
return definePluginTool4({
|
|
586
656
|
annotations: {
|
|
587
657
|
destructiveHint: false,
|
|
588
658
|
idempotentHint: false,
|
|
@@ -590,8 +660,8 @@ function createGitHubCommentOnPullRequestTool(egress) {
|
|
|
590
660
|
readOnlyHint: false
|
|
591
661
|
},
|
|
592
662
|
description: "Post a conversation comment on a GitHub pull request, or reply in an inline review thread with in_reply_to. For issues, use github_commentOnIssue. Use it to answer a question asked in a pull request review or comment. Returns the comment id and URL.",
|
|
593
|
-
inputSchema:
|
|
594
|
-
outputSchema:
|
|
663
|
+
inputSchema: inputSchema4,
|
|
664
|
+
outputSchema: outputSchema4,
|
|
595
665
|
async execute(input) {
|
|
596
666
|
const repo = parseRepo(input.repo);
|
|
597
667
|
const prefix = repoPath(repo);
|
|
@@ -605,11 +675,11 @@ function createGitHubCommentOnPullRequestTool(egress) {
|
|
|
605
675
|
if (!response.ok) {
|
|
606
676
|
const message = `GitHub pull request comment failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
|
|
607
677
|
if (response.status === 404 || response.status === 422) {
|
|
608
|
-
throw new
|
|
678
|
+
throw new PluginToolInputError5(message);
|
|
609
679
|
}
|
|
610
680
|
throw new Error(message);
|
|
611
681
|
}
|
|
612
|
-
const comment =
|
|
682
|
+
const comment = z5.object({ id: z5.number(), html_url: z5.string() }).parse(response.body);
|
|
613
683
|
return {
|
|
614
684
|
target: "commentOnPullRequest",
|
|
615
685
|
repo: repo.ref,
|
|
@@ -623,21 +693,21 @@ function createGitHubCommentOnPullRequestTool(egress) {
|
|
|
623
693
|
}
|
|
624
694
|
|
|
625
695
|
// src/object-facts.ts
|
|
626
|
-
import * as
|
|
627
|
-
var person =
|
|
628
|
-
var responseSchema =
|
|
629
|
-
body:
|
|
696
|
+
import * as z6 from "zod";
|
|
697
|
+
var person = z6.object({ login: z6.string() });
|
|
698
|
+
var responseSchema = z6.object({
|
|
699
|
+
body: z6.string().nullable().optional(),
|
|
630
700
|
user: person.nullable().optional(),
|
|
631
|
-
requested_reviewers:
|
|
632
|
-
assignees:
|
|
633
|
-
labels:
|
|
634
|
-
head:
|
|
635
|
-
base:
|
|
636
|
-
mergeable:
|
|
637
|
-
changed_files:
|
|
638
|
-
additions:
|
|
639
|
-
deletions:
|
|
640
|
-
updated_at:
|
|
701
|
+
requested_reviewers: z6.array(person).optional(),
|
|
702
|
+
assignees: z6.array(person).optional(),
|
|
703
|
+
labels: z6.array(z6.union([z6.string(), z6.object({ name: z6.string() })])).optional(),
|
|
704
|
+
head: z6.object({ ref: z6.string() }).optional(),
|
|
705
|
+
base: z6.object({ ref: z6.string() }).optional(),
|
|
706
|
+
mergeable: z6.boolean().nullable().optional(),
|
|
707
|
+
changed_files: z6.number().int().nonnegative().optional(),
|
|
708
|
+
additions: z6.number().int().nonnegative().optional(),
|
|
709
|
+
deletions: z6.number().int().nonnegative().optional(),
|
|
710
|
+
updated_at: z6.iso.datetime({ offset: true }).optional()
|
|
641
711
|
});
|
|
642
712
|
var short = (value) => {
|
|
643
713
|
const text2 = value?.trim();
|
|
@@ -682,6 +752,9 @@ function githubObjectFacts(type, response) {
|
|
|
682
752
|
}
|
|
683
753
|
|
|
684
754
|
// src/annotations.ts
|
|
755
|
+
import {
|
|
756
|
+
objectFactsMatchType
|
|
757
|
+
} from "@sentry/junior-plugin-api";
|
|
685
758
|
function githubObjectType(annotation) {
|
|
686
759
|
if (annotation.objectType === "task" || annotation.objectType === "code_change") {
|
|
687
760
|
return annotation.objectType;
|
|
@@ -738,10 +811,13 @@ async function updateGitHubAnnotation(store, input) {
|
|
|
738
811
|
plugin: _plugin,
|
|
739
812
|
createdAt: _createdAt,
|
|
740
813
|
updatedAt: _updatedAt,
|
|
814
|
+
facts,
|
|
741
815
|
...annotation
|
|
742
816
|
} = current;
|
|
743
817
|
await store.upsert({
|
|
744
818
|
...annotation,
|
|
819
|
+
// Facts saved for another object type are not valid for this one.
|
|
820
|
+
...facts && objectFactsMatchType(facts, input.objectType) ? { facts } : void 0,
|
|
745
821
|
objectType: input.objectType,
|
|
746
822
|
status: input.status
|
|
747
823
|
});
|
|
@@ -756,28 +832,47 @@ async function updateGitHubAnnotation(store, input) {
|
|
|
756
832
|
status: input.status
|
|
757
833
|
});
|
|
758
834
|
}
|
|
835
|
+
async function updateGitHubAnnotations(args) {
|
|
836
|
+
const results = await Promise.allSettled(
|
|
837
|
+
args.conversationIds.map(
|
|
838
|
+
(conversationId) => updateGitHubAnnotation(
|
|
839
|
+
args.annotations.forConversation(conversationId),
|
|
840
|
+
args.update
|
|
841
|
+
)
|
|
842
|
+
)
|
|
843
|
+
);
|
|
844
|
+
for (const result of results) {
|
|
845
|
+
if (result.status === "fulfilled") continue;
|
|
846
|
+
args.log?.error("GitHub conversation annotation update failed", {
|
|
847
|
+
errorType: result.reason instanceof Error ? result.reason.name : "UnknownError",
|
|
848
|
+
number: args.update.number,
|
|
849
|
+
objectType: args.update.objectType,
|
|
850
|
+
repository: args.update.repo
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
759
854
|
|
|
760
855
|
// src/tools/create-issue.ts
|
|
761
856
|
import {
|
|
762
857
|
objectFactsSchema,
|
|
763
|
-
definePluginTool as
|
|
858
|
+
definePluginTool as definePluginTool5,
|
|
764
859
|
EgressAuthRequired,
|
|
765
|
-
PluginToolInputError as
|
|
860
|
+
PluginToolInputError as PluginToolInputError7,
|
|
766
861
|
subscribableResourceSchema,
|
|
767
|
-
pluginToolOutputSchema as
|
|
862
|
+
pluginToolOutputSchema as pluginToolOutputSchema5
|
|
768
863
|
} from "@sentry/junior-plugin-api";
|
|
769
864
|
import { Type } from "@sinclair/typebox";
|
|
770
865
|
import { Value } from "@sinclair/typebox/value";
|
|
771
|
-
import * as
|
|
866
|
+
import * as z7 from "zod";
|
|
772
867
|
|
|
773
868
|
// src/tools/footer.ts
|
|
774
|
-
import { PluginToolInputError as
|
|
869
|
+
import { PluginToolInputError as PluginToolInputError6 } from "@sentry/junior-plugin-api";
|
|
775
870
|
var GITHUB_SESSION_FOOTER_START = "<!-- junior-session-footer:start -->";
|
|
776
871
|
var GITHUB_SESSION_FOOTER_END = "<!-- junior-session-footer:end -->";
|
|
777
872
|
var GITHUB_CONVERSATION_ID_MARKER = "junior-conversation-id:";
|
|
778
873
|
function nonEmptyString(value, name) {
|
|
779
874
|
if (!value?.trim()) {
|
|
780
|
-
throw new
|
|
875
|
+
throw new PluginToolInputError6(`${name} is required`);
|
|
781
876
|
}
|
|
782
877
|
return value.trim();
|
|
783
878
|
}
|
|
@@ -854,11 +949,11 @@ function githubLinkedIssues(body, repositoryFullName) {
|
|
|
854
949
|
if (!body) return [];
|
|
855
950
|
const references = /* @__PURE__ */ new Map();
|
|
856
951
|
const add = (linkedRepository, rawNumber) => {
|
|
857
|
-
const
|
|
858
|
-
if (!Number.isInteger(
|
|
952
|
+
const number31 = Number.parseInt(rawNumber, 10);
|
|
953
|
+
if (!Number.isInteger(number31) || number31 <= 0) return;
|
|
859
954
|
const normalizedRepository = linkedRepository.toLowerCase();
|
|
860
|
-
references.set(`${normalizedRepository}#${
|
|
861
|
-
number:
|
|
955
|
+
references.set(`${normalizedRepository}#${number31}`, {
|
|
956
|
+
number: number31,
|
|
862
957
|
repositoryFullName: linkedRepository
|
|
863
958
|
});
|
|
864
959
|
};
|
|
@@ -921,11 +1016,11 @@ var createIssueInputSchema = Type.Object(
|
|
|
921
1016
|
},
|
|
922
1017
|
{ additionalProperties: false }
|
|
923
1018
|
);
|
|
924
|
-
var createIssueToolInputSchema =
|
|
925
|
-
repo:
|
|
926
|
-
title:
|
|
927
|
-
body:
|
|
928
|
-
labels:
|
|
1019
|
+
var createIssueToolInputSchema = z7.object({
|
|
1020
|
+
repo: z7.string().describe('Repository in "owner/name" format.'),
|
|
1021
|
+
title: z7.string().describe("Issue title."),
|
|
1022
|
+
body: z7.string().describe("Issue body. The runtime appends the conversation footer.").optional(),
|
|
1023
|
+
labels: z7.array(z7.string()).describe("Labels to apply to the issue.").optional()
|
|
929
1024
|
}).strict();
|
|
930
1025
|
var createIssueStateSchema = Type.Union([
|
|
931
1026
|
Type.Object(
|
|
@@ -950,14 +1045,14 @@ var createIssueStateSchema = Type.Union([
|
|
|
950
1045
|
{ additionalProperties: false }
|
|
951
1046
|
)
|
|
952
1047
|
]);
|
|
953
|
-
var gitHubIssueDataSchema =
|
|
954
|
-
number:
|
|
1048
|
+
var gitHubIssueDataSchema = z7.object({
|
|
1049
|
+
number: z7.number(),
|
|
955
1050
|
subscribable: subscribableResourceSchema.optional(),
|
|
956
|
-
url:
|
|
1051
|
+
url: z7.string()
|
|
957
1052
|
});
|
|
958
|
-
var gitHubIssueOutputSchema =
|
|
1053
|
+
var gitHubIssueOutputSchema = pluginToolOutputSchema5.merge(
|
|
959
1054
|
gitHubIssueDataSchema.extend({
|
|
960
|
-
target:
|
|
1055
|
+
target: z7.literal("createIssue")
|
|
961
1056
|
})
|
|
962
1057
|
);
|
|
963
1058
|
function gitHubIssueToolResult(input, result, canSubscribe) {
|
|
@@ -994,14 +1089,14 @@ function parseCreateIssueInput(input) {
|
|
|
994
1089
|
try {
|
|
995
1090
|
return Value.Parse(createIssueInputSchema, input);
|
|
996
1091
|
} catch (error) {
|
|
997
|
-
throw new
|
|
1092
|
+
throw new PluginToolInputError7("Invalid GitHub createIssue input.", {
|
|
998
1093
|
cause: error
|
|
999
1094
|
});
|
|
1000
1095
|
}
|
|
1001
1096
|
}
|
|
1002
1097
|
function nonEmptyString2(value, name) {
|
|
1003
1098
|
if (!value?.trim()) {
|
|
1004
|
-
throw new
|
|
1099
|
+
throw new PluginToolInputError7(`${name} is required`);
|
|
1005
1100
|
}
|
|
1006
1101
|
return value.trim();
|
|
1007
1102
|
}
|
|
@@ -1075,7 +1170,7 @@ async function createGitHubIssue(ctx, request) {
|
|
|
1075
1170
|
};
|
|
1076
1171
|
}
|
|
1077
1172
|
function createGitHubIssueTool(ctx) {
|
|
1078
|
-
return
|
|
1173
|
+
return definePluginTool5({
|
|
1079
1174
|
annotations: {
|
|
1080
1175
|
destructiveHint: false,
|
|
1081
1176
|
idempotentHint: true,
|
|
@@ -1122,7 +1217,7 @@ function createGitHubIssueTool(ctx) {
|
|
|
1122
1217
|
conversationId,
|
|
1123
1218
|
parsedInput,
|
|
1124
1219
|
ctx,
|
|
1125
|
-
ctx.
|
|
1220
|
+
ctx.conversationLink?.url
|
|
1126
1221
|
);
|
|
1127
1222
|
const pendingState = {
|
|
1128
1223
|
status: "pending",
|
|
@@ -1168,85 +1263,85 @@ function createGitHubIssueTool(ctx) {
|
|
|
1168
1263
|
|
|
1169
1264
|
// src/tools/get-deployment.ts
|
|
1170
1265
|
import {
|
|
1171
|
-
definePluginTool as
|
|
1172
|
-
PluginToolInputError as
|
|
1173
|
-
pluginToolOutputSchema as
|
|
1266
|
+
definePluginTool as definePluginTool6,
|
|
1267
|
+
PluginToolInputError as PluginToolInputError8,
|
|
1268
|
+
pluginToolOutputSchema as pluginToolOutputSchema6,
|
|
1174
1269
|
subscribableResourceSchema as subscribableResourceSchema2
|
|
1175
1270
|
} from "@sentry/junior-plugin-api";
|
|
1176
|
-
import * as
|
|
1177
|
-
var commitShaSchema =
|
|
1178
|
-
var
|
|
1179
|
-
repo:
|
|
1271
|
+
import * as z8 from "zod";
|
|
1272
|
+
var commitShaSchema = z8.string().regex(/^[0-9a-f]{40}$/i);
|
|
1273
|
+
var inputSchema5 = z8.object({
|
|
1274
|
+
repo: z8.string().describe('Repository in "owner/name" format.'),
|
|
1180
1275
|
commit_sha: commitShaSchema.describe(
|
|
1181
1276
|
"Full 40-character Git commit SHA recorded by the deployment."
|
|
1182
1277
|
),
|
|
1183
|
-
environment:
|
|
1278
|
+
environment: z8.string().trim().min(1).describe(
|
|
1184
1279
|
'Optional GitHub deployment environment, such as "Production". Omit to inspect and watch deployments for the commit across environments.'
|
|
1185
1280
|
).optional()
|
|
1186
1281
|
}).strict();
|
|
1187
|
-
var statusSchema =
|
|
1188
|
-
created_at:
|
|
1189
|
-
creator:
|
|
1190
|
-
description:
|
|
1191
|
-
environment_url:
|
|
1192
|
-
id:
|
|
1193
|
-
log_url:
|
|
1194
|
-
state:
|
|
1282
|
+
var statusSchema = z8.object({
|
|
1283
|
+
created_at: z8.string(),
|
|
1284
|
+
creator: z8.string().nullable(),
|
|
1285
|
+
description: z8.string().nullable(),
|
|
1286
|
+
environment_url: z8.string().nullable(),
|
|
1287
|
+
id: z8.number(),
|
|
1288
|
+
log_url: z8.string().nullable(),
|
|
1289
|
+
state: z8.string()
|
|
1195
1290
|
}).strict();
|
|
1196
|
-
var deploymentSchema =
|
|
1197
|
-
created_at:
|
|
1198
|
-
creator:
|
|
1199
|
-
description:
|
|
1200
|
-
environment:
|
|
1201
|
-
id:
|
|
1291
|
+
var deploymentSchema = z8.object({
|
|
1292
|
+
created_at: z8.string(),
|
|
1293
|
+
creator: z8.string().nullable(),
|
|
1294
|
+
description: z8.string().nullable(),
|
|
1295
|
+
environment: z8.string(),
|
|
1296
|
+
id: z8.number(),
|
|
1202
1297
|
latest_status: statusSchema.nullable(),
|
|
1203
|
-
ref:
|
|
1298
|
+
ref: z8.string(),
|
|
1204
1299
|
sha: commitShaSchema,
|
|
1205
|
-
updated_at:
|
|
1206
|
-
url:
|
|
1300
|
+
updated_at: z8.string(),
|
|
1301
|
+
url: z8.string()
|
|
1207
1302
|
}).strict();
|
|
1208
|
-
var deploymentSourceSchema =
|
|
1303
|
+
var deploymentSourceSchema = z8.object({
|
|
1209
1304
|
commit_sha: commitShaSchema,
|
|
1210
1305
|
deployment: deploymentSchema.nullable(),
|
|
1211
|
-
environment:
|
|
1212
|
-
repo:
|
|
1306
|
+
environment: z8.string().nullable(),
|
|
1307
|
+
repo: z8.string(),
|
|
1213
1308
|
subscribable: subscribableResourceSchema2.optional()
|
|
1214
1309
|
}).strict();
|
|
1215
|
-
var
|
|
1310
|
+
var outputSchema5 = pluginToolOutputSchema6.merge(
|
|
1216
1311
|
deploymentSourceSchema.extend({
|
|
1217
|
-
target:
|
|
1312
|
+
target: z8.literal("getDeployment")
|
|
1218
1313
|
})
|
|
1219
1314
|
);
|
|
1220
|
-
var providerCreatorSchema =
|
|
1221
|
-
var providerDeploymentSchema =
|
|
1222
|
-
created_at:
|
|
1315
|
+
var providerCreatorSchema = z8.object({ login: z8.string() }).passthrough().nullable();
|
|
1316
|
+
var providerDeploymentSchema = z8.object({
|
|
1317
|
+
created_at: z8.string(),
|
|
1223
1318
|
creator: providerCreatorSchema,
|
|
1224
|
-
description:
|
|
1225
|
-
environment:
|
|
1226
|
-
id:
|
|
1227
|
-
ref:
|
|
1319
|
+
description: z8.string().nullable(),
|
|
1320
|
+
environment: z8.string(),
|
|
1321
|
+
id: z8.number(),
|
|
1322
|
+
ref: z8.string(),
|
|
1228
1323
|
sha: commitShaSchema,
|
|
1229
|
-
updated_at:
|
|
1324
|
+
updated_at: z8.string()
|
|
1230
1325
|
}).passthrough();
|
|
1231
|
-
var providerStatusSchema =
|
|
1232
|
-
created_at:
|
|
1326
|
+
var providerStatusSchema = z8.object({
|
|
1327
|
+
created_at: z8.string(),
|
|
1233
1328
|
creator: providerCreatorSchema,
|
|
1234
|
-
description:
|
|
1235
|
-
environment_url:
|
|
1236
|
-
id:
|
|
1237
|
-
log_url:
|
|
1238
|
-
state:
|
|
1329
|
+
description: z8.string().nullable().optional(),
|
|
1330
|
+
environment_url: z8.string().nullable().optional(),
|
|
1331
|
+
id: z8.number(),
|
|
1332
|
+
log_url: z8.string().nullable().optional(),
|
|
1333
|
+
state: z8.string()
|
|
1239
1334
|
}).passthrough();
|
|
1240
1335
|
function throwLookupError(target, status, body) {
|
|
1241
1336
|
const message = `GitHub ${target} lookup failed with HTTP ${status}`;
|
|
1242
1337
|
const hasValidationErrors = body !== null && typeof body === "object" && !Array.isArray(body) && Array.isArray(body.errors) && body.errors.length > 0;
|
|
1243
1338
|
if (target === "deployment" && (status === 404 || status === 422 && hasValidationErrors)) {
|
|
1244
|
-
throw new
|
|
1339
|
+
throw new PluginToolInputError8(message);
|
|
1245
1340
|
}
|
|
1246
1341
|
throw new Error(message);
|
|
1247
1342
|
}
|
|
1248
1343
|
function createGitHubGetDeploymentTool(ctx) {
|
|
1249
|
-
return
|
|
1344
|
+
return definePluginTool6({
|
|
1250
1345
|
annotations: {
|
|
1251
1346
|
destructiveHint: false,
|
|
1252
1347
|
idempotentHint: true,
|
|
@@ -1254,8 +1349,8 @@ function createGitHubGetDeploymentTool(ctx) {
|
|
|
1254
1349
|
readOnlyHint: true
|
|
1255
1350
|
},
|
|
1256
1351
|
description: "Get the latest GitHub deployment and status for an exact repository and full commit SHA, optionally limited to one environment. The result remains subscribable when no deployment exists yet, so use it before waiting for a deployment outcome.",
|
|
1257
|
-
inputSchema:
|
|
1258
|
-
outputSchema:
|
|
1352
|
+
inputSchema: inputSchema5,
|
|
1353
|
+
outputSchema: outputSchema5,
|
|
1259
1354
|
async execute(input) {
|
|
1260
1355
|
const repo = parseRepo(input.repo);
|
|
1261
1356
|
const commitSha = input.commit_sha.toLowerCase();
|
|
@@ -1271,7 +1366,7 @@ function createGitHubGetDeploymentTool(ctx) {
|
|
|
1271
1366
|
if (!deployments.ok) {
|
|
1272
1367
|
throwLookupError("deployment", deployments.status, deployments.body);
|
|
1273
1368
|
}
|
|
1274
|
-
const providerDeployment =
|
|
1369
|
+
const providerDeployment = z8.array(providerDeploymentSchema).parse(deployments.body)[0];
|
|
1275
1370
|
let deployment = null;
|
|
1276
1371
|
if (providerDeployment) {
|
|
1277
1372
|
const statuses = await githubApi(ctx.egress, {
|
|
@@ -1281,7 +1376,7 @@ function createGitHubGetDeploymentTool(ctx) {
|
|
|
1281
1376
|
if (!statuses.ok) {
|
|
1282
1377
|
throwLookupError("deployment status", statuses.status, statuses.body);
|
|
1283
1378
|
}
|
|
1284
|
-
const providerStatus =
|
|
1379
|
+
const providerStatus = z8.array(providerStatusSchema).parse(statuses.body)[0];
|
|
1285
1380
|
deployment = {
|
|
1286
1381
|
created_at: providerDeployment.created_at,
|
|
1287
1382
|
creator: providerDeployment.creator?.login ?? null,
|
|
@@ -1326,47 +1421,47 @@ function createGitHubGetDeploymentTool(ctx) {
|
|
|
1326
1421
|
|
|
1327
1422
|
// src/tools/get-issue.ts
|
|
1328
1423
|
import {
|
|
1329
|
-
definePluginTool as
|
|
1330
|
-
PluginToolInputError as
|
|
1331
|
-
pluginToolOutputSchema as
|
|
1424
|
+
definePluginTool as definePluginTool7,
|
|
1425
|
+
PluginToolInputError as PluginToolInputError9,
|
|
1426
|
+
pluginToolOutputSchema as pluginToolOutputSchema7,
|
|
1332
1427
|
subscribableResourceSchema as subscribableResourceSchema3
|
|
1333
1428
|
} from "@sentry/junior-plugin-api";
|
|
1334
|
-
import * as
|
|
1429
|
+
import * as z9 from "zod";
|
|
1335
1430
|
var CLAIM_NOTE = "If you start work on this issue, first claim it with github_updateIssue and assign_requester: true.";
|
|
1336
|
-
var
|
|
1337
|
-
repo:
|
|
1338
|
-
number:
|
|
1431
|
+
var inputSchema6 = z9.object({
|
|
1432
|
+
repo: z9.string().describe('Repository in "owner/name" format.'),
|
|
1433
|
+
number: z9.number().int().positive().describe("Issue number.")
|
|
1339
1434
|
}).strict();
|
|
1340
|
-
var issueSchema =
|
|
1341
|
-
assignees:
|
|
1342
|
-
author:
|
|
1343
|
-
body:
|
|
1344
|
-
comments:
|
|
1345
|
-
labels:
|
|
1346
|
-
note:
|
|
1347
|
-
number:
|
|
1348
|
-
state:
|
|
1435
|
+
var issueSchema = z9.object({
|
|
1436
|
+
assignees: z9.array(z9.string()),
|
|
1437
|
+
author: z9.string().optional(),
|
|
1438
|
+
body: z9.string().nullable(),
|
|
1439
|
+
comments: z9.number(),
|
|
1440
|
+
labels: z9.array(z9.string()),
|
|
1441
|
+
note: z9.string().optional(),
|
|
1442
|
+
number: z9.number(),
|
|
1443
|
+
state: z9.string(),
|
|
1349
1444
|
subscribable: subscribableResourceSchema3.optional(),
|
|
1350
|
-
title:
|
|
1351
|
-
url:
|
|
1445
|
+
title: z9.string(),
|
|
1446
|
+
url: z9.string()
|
|
1352
1447
|
});
|
|
1353
|
-
var
|
|
1354
|
-
issueSchema.extend({ target:
|
|
1448
|
+
var outputSchema6 = pluginToolOutputSchema7.merge(
|
|
1449
|
+
issueSchema.extend({ target: z9.literal("getIssue") })
|
|
1355
1450
|
);
|
|
1356
|
-
var providerIssueSchema =
|
|
1357
|
-
assignees:
|
|
1358
|
-
body:
|
|
1359
|
-
comments:
|
|
1360
|
-
html_url:
|
|
1361
|
-
labels:
|
|
1362
|
-
number:
|
|
1363
|
-
repository_url:
|
|
1364
|
-
state:
|
|
1365
|
-
title:
|
|
1366
|
-
user:
|
|
1451
|
+
var providerIssueSchema = z9.object({
|
|
1452
|
+
assignees: z9.array(z9.object({ login: z9.string() })).nullish().transform((assignees) => assignees?.map(({ login: login2 }) => login2) ?? []),
|
|
1453
|
+
body: z9.string().nullable().optional().default(null),
|
|
1454
|
+
comments: z9.number().optional().default(0),
|
|
1455
|
+
html_url: z9.string(),
|
|
1456
|
+
labels: z9.array(z9.object({ name: z9.string() })).optional().default([]).transform((labels) => labels.map(({ name }) => name)),
|
|
1457
|
+
number: z9.number(),
|
|
1458
|
+
repository_url: z9.string().optional(),
|
|
1459
|
+
state: z9.string(),
|
|
1460
|
+
title: z9.string(),
|
|
1461
|
+
user: z9.object({ login: z9.string() }).nullish()
|
|
1367
1462
|
});
|
|
1368
1463
|
function createGitHubGetIssueTool(ctx) {
|
|
1369
|
-
return
|
|
1464
|
+
return definePluginTool7({
|
|
1370
1465
|
annotations: {
|
|
1371
1466
|
destructiveHint: false,
|
|
1372
1467
|
idempotentHint: true,
|
|
@@ -1374,8 +1469,8 @@ function createGitHubGetIssueTool(ctx) {
|
|
|
1374
1469
|
readOnlyHint: true
|
|
1375
1470
|
},
|
|
1376
1471
|
description: "Get a GitHub issue. Read its comments with gh api repos/OWNER/REPO/issues/NUMBER/comments.",
|
|
1377
|
-
inputSchema:
|
|
1378
|
-
outputSchema:
|
|
1472
|
+
inputSchema: inputSchema6,
|
|
1473
|
+
outputSchema: outputSchema6,
|
|
1379
1474
|
async execute(input) {
|
|
1380
1475
|
const repo = parseRepo(input.repo);
|
|
1381
1476
|
const [response, requester] = await Promise.all([
|
|
@@ -1389,7 +1484,7 @@ function createGitHubGetIssueTool(ctx) {
|
|
|
1389
1484
|
if (!response.ok) {
|
|
1390
1485
|
const message = `GitHub issue lookup failed with HTTP ${response.status}`;
|
|
1391
1486
|
if (response.status === 404) {
|
|
1392
|
-
throw new
|
|
1487
|
+
throw new PluginToolInputError9(message);
|
|
1393
1488
|
}
|
|
1394
1489
|
throw new Error(message);
|
|
1395
1490
|
}
|
|
@@ -1440,16 +1535,16 @@ function issueRepoRef(repositoryUrl) {
|
|
|
1440
1535
|
// src/tools/create-pull-request.ts
|
|
1441
1536
|
import {
|
|
1442
1537
|
objectFactsSchema as objectFactsSchema2,
|
|
1443
|
-
definePluginTool as
|
|
1538
|
+
definePluginTool as definePluginTool8,
|
|
1444
1539
|
EgressAuthRequired as EgressAuthRequired2,
|
|
1445
|
-
PluginToolInputError as
|
|
1446
|
-
pluginToolOutputSchema as
|
|
1540
|
+
PluginToolInputError as PluginToolInputError10,
|
|
1541
|
+
pluginToolOutputSchema as pluginToolOutputSchema8,
|
|
1447
1542
|
watchResultSchema,
|
|
1448
1543
|
subscribableResourceSchema as subscribableResourceSchema4
|
|
1449
1544
|
} from "@sentry/junior-plugin-api";
|
|
1450
1545
|
import { Type as Type2 } from "@sinclair/typebox";
|
|
1451
1546
|
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
1452
|
-
import * as
|
|
1547
|
+
import * as z12 from "zod";
|
|
1453
1548
|
|
|
1454
1549
|
// src/pull-request-requesters/store.ts
|
|
1455
1550
|
import { and, asc, eq, inArray, lt } from "drizzle-orm";
|
|
@@ -1464,18 +1559,18 @@ import {
|
|
|
1464
1559
|
text,
|
|
1465
1560
|
timestamp
|
|
1466
1561
|
} from "drizzle-orm/pg-core";
|
|
1467
|
-
import * as
|
|
1468
|
-
var githubPullRequestStateSchema =
|
|
1562
|
+
import * as z10 from "zod";
|
|
1563
|
+
var githubPullRequestStateSchema = z10.enum([
|
|
1469
1564
|
"closed_unmerged",
|
|
1470
1565
|
"merged",
|
|
1471
1566
|
"open"
|
|
1472
1567
|
]);
|
|
1473
|
-
var githubPullRequestCommitCompositionSchema =
|
|
1568
|
+
var githubPullRequestCommitCompositionSchema = z10.enum([
|
|
1474
1569
|
"junior_only",
|
|
1475
1570
|
"mixed"
|
|
1476
1571
|
]);
|
|
1477
|
-
var githubIssueStateSchema =
|
|
1478
|
-
var githubIssueStateReasonSchema =
|
|
1572
|
+
var githubIssueStateSchema = z10.enum(["closed", "open"]);
|
|
1573
|
+
var githubIssueStateReasonSchema = z10.enum([
|
|
1479
1574
|
"completed",
|
|
1480
1575
|
"duplicate",
|
|
1481
1576
|
"not_planned",
|
|
@@ -1636,32 +1731,32 @@ async function listGitHubPullRequestOpeners(db, input) {
|
|
|
1636
1731
|
}
|
|
1637
1732
|
|
|
1638
1733
|
// src/tools/stack-pull-request.ts
|
|
1639
|
-
import * as
|
|
1734
|
+
import * as z11 from "zod";
|
|
1640
1735
|
var MAX_STACK_DEPTH = 10;
|
|
1641
1736
|
var GITHUB_STACKS_API_VERSION = "2026-03-10";
|
|
1642
|
-
var stackTargetSchema =
|
|
1643
|
-
number:
|
|
1644
|
-
head:
|
|
1645
|
-
ref:
|
|
1646
|
-
repo:
|
|
1737
|
+
var stackTargetSchema = z11.object({
|
|
1738
|
+
number: z11.number().int().positive(),
|
|
1739
|
+
head: z11.object({
|
|
1740
|
+
ref: z11.string().min(1),
|
|
1741
|
+
repo: z11.object({ full_name: z11.string().min(1) }).nullable()
|
|
1647
1742
|
}),
|
|
1648
|
-
base:
|
|
1649
|
-
ref:
|
|
1650
|
-
repo:
|
|
1651
|
-
default_branch:
|
|
1652
|
-
full_name:
|
|
1743
|
+
base: z11.object({
|
|
1744
|
+
ref: z11.string().min(1),
|
|
1745
|
+
repo: z11.object({
|
|
1746
|
+
default_branch: z11.string().min(1),
|
|
1747
|
+
full_name: z11.string().min(1)
|
|
1653
1748
|
})
|
|
1654
1749
|
})
|
|
1655
1750
|
});
|
|
1656
|
-
var openPullRequestsSchema =
|
|
1657
|
-
|
|
1658
|
-
number:
|
|
1659
|
-
base:
|
|
1751
|
+
var openPullRequestsSchema = z11.array(
|
|
1752
|
+
z11.object({
|
|
1753
|
+
number: z11.number().int().positive(),
|
|
1754
|
+
base: z11.object({ ref: z11.string().min(1) })
|
|
1660
1755
|
})
|
|
1661
1756
|
);
|
|
1662
|
-
var stackSchema =
|
|
1663
|
-
number:
|
|
1664
|
-
pull_requests:
|
|
1757
|
+
var stackSchema = z11.object({
|
|
1758
|
+
number: z11.number().int().positive(),
|
|
1759
|
+
pull_requests: z11.array(z11.object({ number: z11.number().int().positive() }))
|
|
1665
1760
|
});
|
|
1666
1761
|
async function stackGitHubPullRequest(ctx, target) {
|
|
1667
1762
|
const repo = target.base.repo.full_name;
|
|
@@ -1709,7 +1804,7 @@ async function stackGitHubPullRequest(ctx, target) {
|
|
|
1709
1804
|
const stacks = await github(
|
|
1710
1805
|
"github.stack.read",
|
|
1711
1806
|
`${api}/stacks?pull_request=${parent.number}`,
|
|
1712
|
-
|
|
1807
|
+
z11.array(stackSchema)
|
|
1713
1808
|
);
|
|
1714
1809
|
if (!stacks) return void 0;
|
|
1715
1810
|
const stack = stacks[0];
|
|
@@ -1784,15 +1879,15 @@ var createPullRequestInputSchema = Type2.Object(
|
|
|
1784
1879
|
},
|
|
1785
1880
|
{ additionalProperties: false }
|
|
1786
1881
|
);
|
|
1787
|
-
var createPullRequestToolInputSchema =
|
|
1788
|
-
repo:
|
|
1789
|
-
title:
|
|
1790
|
-
head:
|
|
1791
|
-
base:
|
|
1792
|
-
body:
|
|
1882
|
+
var createPullRequestToolInputSchema = z12.object({
|
|
1883
|
+
repo: z12.string().describe('Repository in "owner/name" format.'),
|
|
1884
|
+
title: z12.string().describe("Pull request title."),
|
|
1885
|
+
head: z12.string().describe("Head branch or owner:branch ref."),
|
|
1886
|
+
base: z12.string().describe("Base branch."),
|
|
1887
|
+
body: z12.string().describe(
|
|
1793
1888
|
"Pull request body. The runtime appends the conversation footer."
|
|
1794
1889
|
).optional(),
|
|
1795
|
-
draft:
|
|
1890
|
+
draft: z12.boolean().describe("Whether to open the pull request as a draft.").optional()
|
|
1796
1891
|
}).strict();
|
|
1797
1892
|
var createPullRequestStateSchema = Type2.Union([
|
|
1798
1893
|
Type2.Object(
|
|
@@ -1817,30 +1912,30 @@ var createPullRequestStateSchema = Type2.Union([
|
|
|
1817
1912
|
{ additionalProperties: false }
|
|
1818
1913
|
)
|
|
1819
1914
|
]);
|
|
1820
|
-
var gitHubPullRequestDataSchema =
|
|
1821
|
-
number:
|
|
1822
|
-
url:
|
|
1823
|
-
stack:
|
|
1915
|
+
var gitHubPullRequestDataSchema = z12.object({
|
|
1916
|
+
number: z12.number(),
|
|
1917
|
+
url: z12.string(),
|
|
1918
|
+
stack: z12.object({ number: z12.number(), pull_requests: z12.array(z12.number()) }).optional(),
|
|
1824
1919
|
subscribable: subscribableResourceSchema4.optional(),
|
|
1825
1920
|
subscription: watchResultSchema.optional()
|
|
1826
1921
|
});
|
|
1827
|
-
var gitHubPullRequestOutputSchema =
|
|
1922
|
+
var gitHubPullRequestOutputSchema = pluginToolOutputSchema8.merge(
|
|
1828
1923
|
gitHubPullRequestDataSchema.extend({
|
|
1829
|
-
target:
|
|
1924
|
+
target: z12.literal("createPullRequest")
|
|
1830
1925
|
})
|
|
1831
1926
|
);
|
|
1832
1927
|
function parseCreatePullRequestInput(input) {
|
|
1833
1928
|
try {
|
|
1834
1929
|
return Value2.Parse(createPullRequestInputSchema, input);
|
|
1835
1930
|
} catch (error) {
|
|
1836
|
-
throw new
|
|
1931
|
+
throw new PluginToolInputError10("Invalid GitHub createPullRequest input.", {
|
|
1837
1932
|
cause: error
|
|
1838
1933
|
});
|
|
1839
1934
|
}
|
|
1840
1935
|
}
|
|
1841
1936
|
function nonEmptyString3(value, name) {
|
|
1842
1937
|
if (!value?.trim()) {
|
|
1843
|
-
throw new
|
|
1938
|
+
throw new PluginToolInputError10(`${name} is required`);
|
|
1844
1939
|
}
|
|
1845
1940
|
return value.trim();
|
|
1846
1941
|
}
|
|
@@ -2029,7 +2124,7 @@ async function gitHubPullRequestStructuredResult(ctx, input, result, subscriptio
|
|
|
2029
2124
|
}
|
|
2030
2125
|
}
|
|
2031
2126
|
function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
2032
|
-
return
|
|
2127
|
+
return definePluginTool8({
|
|
2033
2128
|
annotations: {
|
|
2034
2129
|
destructiveHint: false,
|
|
2035
2130
|
idempotentHint: true,
|
|
@@ -2085,7 +2180,7 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
2085
2180
|
parsedInput,
|
|
2086
2181
|
ctx,
|
|
2087
2182
|
requester,
|
|
2088
|
-
ctx.
|
|
2183
|
+
ctx.conversationLink?.url
|
|
2089
2184
|
);
|
|
2090
2185
|
const pendingState = {
|
|
2091
2186
|
status: "pending",
|
|
@@ -2148,36 +2243,36 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
2148
2243
|
|
|
2149
2244
|
// src/tools/get-pull-request.ts
|
|
2150
2245
|
import {
|
|
2151
|
-
definePluginTool as
|
|
2152
|
-
PluginToolInputError as
|
|
2153
|
-
pluginToolOutputSchema as
|
|
2246
|
+
definePluginTool as definePluginTool9,
|
|
2247
|
+
PluginToolInputError as PluginToolInputError11,
|
|
2248
|
+
pluginToolOutputSchema as pluginToolOutputSchema9
|
|
2154
2249
|
} from "@sentry/junior-plugin-api";
|
|
2155
|
-
import * as
|
|
2250
|
+
import * as z13 from "zod";
|
|
2156
2251
|
import { subscribableResourceSchema as subscribableResourceSchema5 } from "@sentry/junior-plugin-api";
|
|
2157
|
-
var commitShaSchema2 =
|
|
2158
|
-
var
|
|
2159
|
-
repo:
|
|
2160
|
-
number:
|
|
2252
|
+
var commitShaSchema2 = z13.string().regex(/^[0-9a-f]{40}$/i);
|
|
2253
|
+
var inputSchema7 = z13.object({
|
|
2254
|
+
repo: z13.string().describe('Repository in "owner/name" format.'),
|
|
2255
|
+
number: z13.number().int().positive().describe("Pull request number.")
|
|
2161
2256
|
}).strict();
|
|
2162
|
-
var pullRequestSchema =
|
|
2163
|
-
base:
|
|
2164
|
-
draft:
|
|
2165
|
-
head:
|
|
2257
|
+
var pullRequestSchema = z13.object({
|
|
2258
|
+
base: z13.string(),
|
|
2259
|
+
draft: z13.boolean(),
|
|
2260
|
+
head: z13.string(),
|
|
2166
2261
|
head_sha: commitShaSchema2,
|
|
2167
|
-
merged:
|
|
2168
|
-
number:
|
|
2169
|
-
state:
|
|
2262
|
+
merged: z13.boolean(),
|
|
2263
|
+
number: z13.number(),
|
|
2264
|
+
state: z13.string(),
|
|
2170
2265
|
subscribable: subscribableResourceSchema5.optional(),
|
|
2171
|
-
title:
|
|
2172
|
-
url:
|
|
2266
|
+
title: z13.string(),
|
|
2267
|
+
url: z13.string()
|
|
2173
2268
|
});
|
|
2174
|
-
var
|
|
2269
|
+
var outputSchema7 = pluginToolOutputSchema9.merge(
|
|
2175
2270
|
pullRequestSchema.extend({
|
|
2176
|
-
target:
|
|
2271
|
+
target: z13.literal("getPullRequest")
|
|
2177
2272
|
})
|
|
2178
2273
|
);
|
|
2179
2274
|
function createGitHubGetPullRequestTool(ctx) {
|
|
2180
|
-
return
|
|
2275
|
+
return definePluginTool9({
|
|
2181
2276
|
annotations: {
|
|
2182
2277
|
destructiveHint: false,
|
|
2183
2278
|
idempotentHint: true,
|
|
@@ -2185,8 +2280,8 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2185
2280
|
readOnlyHint: true
|
|
2186
2281
|
},
|
|
2187
2282
|
description: "Get a GitHub pull request. Use this when an existing PR may need event monitoring; the result includes a subscribable hint when GitHub webhooks are configured.",
|
|
2188
|
-
inputSchema:
|
|
2189
|
-
outputSchema:
|
|
2283
|
+
inputSchema: inputSchema7,
|
|
2284
|
+
outputSchema: outputSchema7,
|
|
2190
2285
|
async execute(input) {
|
|
2191
2286
|
const repo = parseRepo(input.repo);
|
|
2192
2287
|
const response = await githubApi(ctx.egress, {
|
|
@@ -2196,19 +2291,19 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2196
2291
|
if (!response.ok) {
|
|
2197
2292
|
const message = `GitHub pull request lookup failed with HTTP ${response.status}`;
|
|
2198
2293
|
if (response.status === 404) {
|
|
2199
|
-
throw new
|
|
2294
|
+
throw new PluginToolInputError11(message);
|
|
2200
2295
|
}
|
|
2201
2296
|
throw new Error(message);
|
|
2202
2297
|
}
|
|
2203
|
-
const providerResult =
|
|
2204
|
-
base:
|
|
2205
|
-
draft:
|
|
2206
|
-
head:
|
|
2207
|
-
html_url:
|
|
2208
|
-
merged:
|
|
2209
|
-
number:
|
|
2210
|
-
state:
|
|
2211
|
-
title:
|
|
2298
|
+
const providerResult = z13.object({
|
|
2299
|
+
base: z13.object({ ref: z13.string() }),
|
|
2300
|
+
draft: z13.boolean(),
|
|
2301
|
+
head: z13.object({ ref: z13.string(), sha: commitShaSchema2 }),
|
|
2302
|
+
html_url: z13.string(),
|
|
2303
|
+
merged: z13.boolean().optional().default(false),
|
|
2304
|
+
number: z13.number(),
|
|
2305
|
+
state: z13.string(),
|
|
2306
|
+
title: z13.string()
|
|
2212
2307
|
}).parse(response.body);
|
|
2213
2308
|
const subscribable = gitHubPullRequestSubscribable({
|
|
2214
2309
|
canSubscribe: ctx.events.canSubscribe,
|
|
@@ -2248,49 +2343,49 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2248
2343
|
|
|
2249
2344
|
// src/tools/get-release.ts
|
|
2250
2345
|
import {
|
|
2251
|
-
definePluginTool as
|
|
2252
|
-
pluginToolOutputSchema as
|
|
2346
|
+
definePluginTool as definePluginTool10,
|
|
2347
|
+
pluginToolOutputSchema as pluginToolOutputSchema10,
|
|
2253
2348
|
subscribableResourceSchema as subscribableResourceSchema6
|
|
2254
2349
|
} from "@sentry/junior-plugin-api";
|
|
2255
|
-
import * as
|
|
2256
|
-
var
|
|
2257
|
-
repo:
|
|
2258
|
-
tag:
|
|
2350
|
+
import * as z14 from "zod";
|
|
2351
|
+
var inputSchema8 = z14.object({
|
|
2352
|
+
repo: z14.string().describe('Repository in "owner/name" format.'),
|
|
2353
|
+
tag: z14.string().trim().min(1).describe(
|
|
2259
2354
|
"Optional release tag name. Omit to inspect and watch every published release in the repository."
|
|
2260
2355
|
).optional()
|
|
2261
2356
|
}).strict();
|
|
2262
|
-
var releaseSchema =
|
|
2263
|
-
created_at:
|
|
2264
|
-
draft:
|
|
2265
|
-
html_url:
|
|
2266
|
-
id:
|
|
2267
|
-
name:
|
|
2268
|
-
prerelease:
|
|
2269
|
-
published_at:
|
|
2270
|
-
tag_name:
|
|
2271
|
-
target_commitish:
|
|
2357
|
+
var releaseSchema = z14.object({
|
|
2358
|
+
created_at: z14.string(),
|
|
2359
|
+
draft: z14.boolean(),
|
|
2360
|
+
html_url: z14.string(),
|
|
2361
|
+
id: z14.number(),
|
|
2362
|
+
name: z14.string().nullable(),
|
|
2363
|
+
prerelease: z14.boolean(),
|
|
2364
|
+
published_at: z14.string().nullable(),
|
|
2365
|
+
tag_name: z14.string(),
|
|
2366
|
+
target_commitish: z14.string()
|
|
2272
2367
|
}).strict();
|
|
2273
|
-
var releaseSourceSchema =
|
|
2368
|
+
var releaseSourceSchema = z14.object({
|
|
2274
2369
|
release: releaseSchema.nullable(),
|
|
2275
|
-
repo:
|
|
2370
|
+
repo: z14.string(),
|
|
2276
2371
|
subscribable: subscribableResourceSchema6.optional(),
|
|
2277
|
-
tag:
|
|
2372
|
+
tag: z14.string().nullable()
|
|
2278
2373
|
}).strict();
|
|
2279
|
-
var
|
|
2374
|
+
var outputSchema8 = pluginToolOutputSchema10.merge(
|
|
2280
2375
|
releaseSourceSchema.extend({
|
|
2281
|
-
target:
|
|
2376
|
+
target: z14.literal("getRelease")
|
|
2282
2377
|
})
|
|
2283
2378
|
);
|
|
2284
|
-
var providerReleaseSchema =
|
|
2285
|
-
created_at:
|
|
2286
|
-
draft:
|
|
2287
|
-
html_url:
|
|
2288
|
-
id:
|
|
2289
|
-
name:
|
|
2290
|
-
prerelease:
|
|
2291
|
-
published_at:
|
|
2292
|
-
tag_name:
|
|
2293
|
-
target_commitish:
|
|
2379
|
+
var providerReleaseSchema = z14.object({
|
|
2380
|
+
created_at: z14.string(),
|
|
2381
|
+
draft: z14.boolean(),
|
|
2382
|
+
html_url: z14.string(),
|
|
2383
|
+
id: z14.number(),
|
|
2384
|
+
name: z14.string().nullable(),
|
|
2385
|
+
prerelease: z14.boolean(),
|
|
2386
|
+
published_at: z14.string().nullable(),
|
|
2387
|
+
tag_name: z14.string(),
|
|
2388
|
+
target_commitish: z14.string()
|
|
2294
2389
|
}).passthrough();
|
|
2295
2390
|
function mapRelease(providerRelease) {
|
|
2296
2391
|
return {
|
|
@@ -2306,7 +2401,7 @@ function mapRelease(providerRelease) {
|
|
|
2306
2401
|
};
|
|
2307
2402
|
}
|
|
2308
2403
|
function createGitHubGetReleaseTool(ctx) {
|
|
2309
|
-
return
|
|
2404
|
+
return definePluginTool10({
|
|
2310
2405
|
annotations: {
|
|
2311
2406
|
destructiveHint: false,
|
|
2312
2407
|
idempotentHint: true,
|
|
@@ -2314,8 +2409,8 @@ function createGitHubGetReleaseTool(ctx) {
|
|
|
2314
2409
|
readOnlyHint: true
|
|
2315
2410
|
},
|
|
2316
2411
|
description: "Get a GitHub release for an exact repository, optionally limited to one tag. The result remains subscribable when no release exists yet, so use it before waiting for a published release. Omit the tag to watch every published release in the repository.",
|
|
2317
|
-
inputSchema:
|
|
2318
|
-
outputSchema:
|
|
2412
|
+
inputSchema: inputSchema8,
|
|
2413
|
+
outputSchema: outputSchema8,
|
|
2319
2414
|
async execute(input) {
|
|
2320
2415
|
const repo = parseRepo(input.repo);
|
|
2321
2416
|
const tag = input.tag?.trim() || void 0;
|
|
@@ -2368,30 +2463,30 @@ function createGitHubGetReleaseTool(ctx) {
|
|
|
2368
2463
|
|
|
2369
2464
|
// src/tools/get-repository.ts
|
|
2370
2465
|
import {
|
|
2371
|
-
definePluginTool as
|
|
2372
|
-
PluginToolInputError as
|
|
2373
|
-
pluginToolOutputSchema as
|
|
2466
|
+
definePluginTool as definePluginTool11,
|
|
2467
|
+
PluginToolInputError as PluginToolInputError12,
|
|
2468
|
+
pluginToolOutputSchema as pluginToolOutputSchema11,
|
|
2374
2469
|
subscribableResourceSchema as subscribableResourceSchema7
|
|
2375
2470
|
} from "@sentry/junior-plugin-api";
|
|
2376
|
-
import * as
|
|
2377
|
-
var
|
|
2378
|
-
repo:
|
|
2471
|
+
import * as z15 from "zod";
|
|
2472
|
+
var inputSchema9 = z15.object({
|
|
2473
|
+
repo: z15.string().describe('Repository in "owner/name" format.')
|
|
2379
2474
|
}).strict();
|
|
2380
|
-
var repositorySchema =
|
|
2381
|
-
default_branch:
|
|
2382
|
-
description:
|
|
2383
|
-
full_name:
|
|
2384
|
-
private:
|
|
2475
|
+
var repositorySchema = z15.object({
|
|
2476
|
+
default_branch: z15.string(),
|
|
2477
|
+
description: z15.string().nullable(),
|
|
2478
|
+
full_name: z15.string(),
|
|
2479
|
+
private: z15.boolean(),
|
|
2385
2480
|
subscribable: subscribableResourceSchema7.optional(),
|
|
2386
|
-
url:
|
|
2481
|
+
url: z15.string()
|
|
2387
2482
|
});
|
|
2388
|
-
var
|
|
2483
|
+
var outputSchema9 = pluginToolOutputSchema11.merge(
|
|
2389
2484
|
repositorySchema.extend({
|
|
2390
|
-
target:
|
|
2485
|
+
target: z15.literal("getRepository")
|
|
2391
2486
|
})
|
|
2392
2487
|
);
|
|
2393
2488
|
function createGitHubGetRepositoryTool(ctx) {
|
|
2394
|
-
return
|
|
2489
|
+
return definePluginTool11({
|
|
2395
2490
|
annotations: {
|
|
2396
2491
|
destructiveHint: false,
|
|
2397
2492
|
idempotentHint: true,
|
|
@@ -2399,8 +2494,8 @@ function createGitHubGetRepositoryTool(ctx) {
|
|
|
2399
2494
|
readOnlyHint: true
|
|
2400
2495
|
},
|
|
2401
2496
|
description: "Get a GitHub repository. Use this when repository-wide issue activity may need event monitoring; the result includes a subscribable hint when GitHub webhooks are configured.",
|
|
2402
|
-
inputSchema:
|
|
2403
|
-
outputSchema:
|
|
2497
|
+
inputSchema: inputSchema9,
|
|
2498
|
+
outputSchema: outputSchema9,
|
|
2404
2499
|
async execute(input) {
|
|
2405
2500
|
const repo = parseRepo(input.repo);
|
|
2406
2501
|
const response = await githubApi(ctx.egress, {
|
|
@@ -2408,16 +2503,16 @@ function createGitHubGetRepositoryTool(ctx) {
|
|
|
2408
2503
|
path: repoPath(repo)
|
|
2409
2504
|
});
|
|
2410
2505
|
if (!response.ok) {
|
|
2411
|
-
throw new
|
|
2506
|
+
throw new PluginToolInputError12(
|
|
2412
2507
|
`GitHub repository lookup failed with HTTP ${response.status}`
|
|
2413
2508
|
);
|
|
2414
2509
|
}
|
|
2415
|
-
const providerResult =
|
|
2416
|
-
default_branch:
|
|
2417
|
-
description:
|
|
2418
|
-
full_name:
|
|
2419
|
-
html_url:
|
|
2420
|
-
private:
|
|
2510
|
+
const providerResult = z15.object({
|
|
2511
|
+
default_branch: z15.string(),
|
|
2512
|
+
description: z15.string().nullable(),
|
|
2513
|
+
full_name: z15.string(),
|
|
2514
|
+
html_url: z15.string(),
|
|
2515
|
+
private: z15.boolean()
|
|
2421
2516
|
}).parse(response.body);
|
|
2422
2517
|
const subscribable = gitHubRepositorySubscribable({
|
|
2423
2518
|
canSubscribe: ctx.events.canSubscribe,
|
|
@@ -2441,27 +2536,27 @@ function createGitHubGetRepositoryTool(ctx) {
|
|
|
2441
2536
|
|
|
2442
2537
|
// src/tools/get-status.ts
|
|
2443
2538
|
import {
|
|
2444
|
-
definePluginTool as
|
|
2445
|
-
pluginToolOutputSchema as
|
|
2539
|
+
definePluginTool as definePluginTool12,
|
|
2540
|
+
pluginToolOutputSchema as pluginToolOutputSchema12
|
|
2446
2541
|
} from "@sentry/junior-plugin-api";
|
|
2447
|
-
import * as
|
|
2542
|
+
import * as z17 from "zod";
|
|
2448
2543
|
|
|
2449
2544
|
// src/github-status.ts
|
|
2450
|
-
import * as
|
|
2545
|
+
import * as z16 from "zod";
|
|
2451
2546
|
var GITHUB_STATUS_INCIDENTS_URL = "https://www.githubstatus.com/api/v2/incidents.json";
|
|
2452
2547
|
var GITHUB_STATUS_TTL_MS = 60 * 1e3;
|
|
2453
2548
|
var GITHUB_STATUS_TIMEOUT_MS = 5e3;
|
|
2454
|
-
var incidentsResponseSchema =
|
|
2455
|
-
incidents:
|
|
2456
|
-
|
|
2457
|
-
components:
|
|
2458
|
-
created_at:
|
|
2459
|
-
impact:
|
|
2460
|
-
name:
|
|
2461
|
-
resolved_at:
|
|
2462
|
-
shortlink:
|
|
2463
|
-
started_at:
|
|
2464
|
-
status:
|
|
2549
|
+
var incidentsResponseSchema = z16.object({
|
|
2550
|
+
incidents: z16.array(
|
|
2551
|
+
z16.object({
|
|
2552
|
+
components: z16.array(z16.object({ name: z16.string() })).default([]),
|
|
2553
|
+
created_at: z16.string(),
|
|
2554
|
+
impact: z16.string(),
|
|
2555
|
+
name: z16.string(),
|
|
2556
|
+
resolved_at: z16.string().nullable(),
|
|
2557
|
+
shortlink: z16.string(),
|
|
2558
|
+
started_at: z16.string().nullable().optional(),
|
|
2559
|
+
status: z16.string()
|
|
2465
2560
|
})
|
|
2466
2561
|
)
|
|
2467
2562
|
});
|
|
@@ -2503,22 +2598,22 @@ async function loadGitHubStatusIncidents(cache, withinMs) {
|
|
|
2503
2598
|
|
|
2504
2599
|
// src/tools/get-status.ts
|
|
2505
2600
|
var RECENT_INCIDENT_MS = 24 * 60 * 60 * 1e3;
|
|
2506
|
-
var
|
|
2507
|
-
var incidentSchema =
|
|
2508
|
-
components:
|
|
2509
|
-
impact:
|
|
2510
|
-
name:
|
|
2511
|
-
resolved_at:
|
|
2512
|
-
started_at:
|
|
2513
|
-
status:
|
|
2514
|
-
url:
|
|
2601
|
+
var inputSchema10 = z17.object({}).strict();
|
|
2602
|
+
var incidentSchema = z17.object({
|
|
2603
|
+
components: z17.array(z17.string()),
|
|
2604
|
+
impact: z17.string(),
|
|
2605
|
+
name: z17.string(),
|
|
2606
|
+
resolved_at: z17.string().optional(),
|
|
2607
|
+
started_at: z17.string(),
|
|
2608
|
+
status: z17.string(),
|
|
2609
|
+
url: z17.string()
|
|
2515
2610
|
});
|
|
2516
|
-
var
|
|
2517
|
-
target:
|
|
2518
|
-
incidents:
|
|
2611
|
+
var outputSchema10 = pluginToolOutputSchema12.extend({
|
|
2612
|
+
target: z17.literal("getStatus"),
|
|
2613
|
+
incidents: z17.array(incidentSchema)
|
|
2519
2614
|
});
|
|
2520
2615
|
function createGitHubGetStatusTool(ctx) {
|
|
2521
|
-
return
|
|
2616
|
+
return definePluginTool12({
|
|
2522
2617
|
annotations: {
|
|
2523
2618
|
destructiveHint: false,
|
|
2524
2619
|
idempotentHint: true,
|
|
@@ -2526,8 +2621,8 @@ function createGitHubGetStatusTool(ctx) {
|
|
|
2526
2621
|
readOnlyHint: true
|
|
2527
2622
|
},
|
|
2528
2623
|
description: "List GitHub incidents from githubstatus.com that are open or were resolved in the last 24 hours, with their affected components. Use when a GitHub request fails with a 5xx, a timeout, or a dropped connection, or when checks stay queued or fail with no cause in the logs.",
|
|
2529
|
-
inputSchema:
|
|
2530
|
-
outputSchema:
|
|
2624
|
+
inputSchema: inputSchema10,
|
|
2625
|
+
outputSchema: outputSchema10,
|
|
2531
2626
|
async execute() {
|
|
2532
2627
|
const incidents = await loadGitHubStatusIncidents(
|
|
2533
2628
|
ctx.cache,
|
|
@@ -2550,55 +2645,55 @@ function createGitHubGetStatusTool(ctx) {
|
|
|
2550
2645
|
|
|
2551
2646
|
// src/tools/update-issue.ts
|
|
2552
2647
|
import {
|
|
2553
|
-
definePluginTool as
|
|
2554
|
-
PluginToolInputError as
|
|
2555
|
-
pluginToolOutputSchema as
|
|
2648
|
+
definePluginTool as definePluginTool13,
|
|
2649
|
+
PluginToolInputError as PluginToolInputError13,
|
|
2650
|
+
pluginToolOutputSchema as pluginToolOutputSchema13,
|
|
2556
2651
|
subscribableResourceSchema as subscribableResourceSchema8
|
|
2557
2652
|
} from "@sentry/junior-plugin-api";
|
|
2558
|
-
import * as
|
|
2559
|
-
var
|
|
2560
|
-
repo:
|
|
2561
|
-
number:
|
|
2562
|
-
title:
|
|
2563
|
-
body:
|
|
2653
|
+
import * as z18 from "zod";
|
|
2654
|
+
var inputSchema11 = z18.object({
|
|
2655
|
+
repo: z18.string().describe('Repository in "owner/name" format.'),
|
|
2656
|
+
number: z18.number().int().positive().describe("Issue number."),
|
|
2657
|
+
title: z18.string().trim().min(1).optional().describe("Replacement issue title."),
|
|
2658
|
+
body: z18.string().optional().describe(
|
|
2564
2659
|
"Replacement issue body. The runtime appends requester attribution and the conversation footer."
|
|
2565
2660
|
),
|
|
2566
|
-
state:
|
|
2567
|
-
assign_requester:
|
|
2661
|
+
state: z18.enum(["open", "closed"]).optional().describe("Replacement issue state."),
|
|
2662
|
+
assign_requester: z18.boolean().optional().describe(
|
|
2568
2663
|
"Set true to add the requester's linked GitHub account as an assignee. Other assignees stay."
|
|
2569
2664
|
)
|
|
2570
2665
|
}).strict().refine(
|
|
2571
2666
|
({ title, body, state, assign_requester }) => title !== void 0 || body !== void 0 || state !== void 0 || assign_requester === true,
|
|
2572
2667
|
{ message: "At least one issue field must be provided." }
|
|
2573
2668
|
);
|
|
2574
|
-
var issueSchema2 =
|
|
2575
|
-
assignees:
|
|
2576
|
-
body:
|
|
2577
|
-
number:
|
|
2578
|
-
state:
|
|
2669
|
+
var issueSchema2 = z18.object({
|
|
2670
|
+
assignees: z18.array(z18.string()),
|
|
2671
|
+
body: z18.string().nullable(),
|
|
2672
|
+
number: z18.number(),
|
|
2673
|
+
state: z18.string(),
|
|
2579
2674
|
subscribable: subscribableResourceSchema8.optional(),
|
|
2580
|
-
title:
|
|
2581
|
-
url:
|
|
2675
|
+
title: z18.string(),
|
|
2676
|
+
url: z18.string()
|
|
2582
2677
|
});
|
|
2583
|
-
var
|
|
2678
|
+
var outputSchema11 = pluginToolOutputSchema13.merge(
|
|
2584
2679
|
issueSchema2.extend({
|
|
2585
|
-
target:
|
|
2680
|
+
target: z18.literal("updateIssue")
|
|
2586
2681
|
})
|
|
2587
2682
|
);
|
|
2588
|
-
var providerIssueSchema2 =
|
|
2589
|
-
assignees:
|
|
2590
|
-
body:
|
|
2591
|
-
html_url:
|
|
2592
|
-
number:
|
|
2593
|
-
state:
|
|
2594
|
-
title:
|
|
2683
|
+
var providerIssueSchema2 = z18.object({
|
|
2684
|
+
assignees: z18.array(z18.object({ login: z18.string() })).nullish().transform((assignees) => assignees?.map(({ login: login2 }) => login2) ?? []),
|
|
2685
|
+
body: z18.string().nullable().optional().default(null),
|
|
2686
|
+
html_url: z18.string(),
|
|
2687
|
+
number: z18.number(),
|
|
2688
|
+
state: z18.string(),
|
|
2689
|
+
title: z18.string()
|
|
2595
2690
|
});
|
|
2596
2691
|
function nonEmptyString4(value, name) {
|
|
2597
|
-
if (!value?.trim()) throw new
|
|
2692
|
+
if (!value?.trim()) throw new PluginToolInputError13(`${name} is required`);
|
|
2598
2693
|
return value.trim();
|
|
2599
2694
|
}
|
|
2600
2695
|
function createGitHubUpdateIssueTool(ctx) {
|
|
2601
|
-
return
|
|
2696
|
+
return definePluginTool13({
|
|
2602
2697
|
annotations: {
|
|
2603
2698
|
destructiveHint: true,
|
|
2604
2699
|
idempotentHint: true,
|
|
@@ -2606,12 +2701,12 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2606
2701
|
readOnlyHint: false
|
|
2607
2702
|
},
|
|
2608
2703
|
description: "Update an existing GitHub issue's title, body, or open/closed state, or assign it to the requester. Use this instead of raw GitHub API calls when changing issue metadata.",
|
|
2609
|
-
inputSchema:
|
|
2610
|
-
outputSchema:
|
|
2704
|
+
inputSchema: inputSchema11,
|
|
2705
|
+
outputSchema: outputSchema11,
|
|
2611
2706
|
async execute(input) {
|
|
2612
|
-
const parsedInput =
|
|
2707
|
+
const parsedInput = inputSchema11.safeParse(input);
|
|
2613
2708
|
if (!parsedInput.success) {
|
|
2614
|
-
throw new
|
|
2709
|
+
throw new PluginToolInputError13("Invalid GitHub updateIssue input.", {
|
|
2615
2710
|
cause: parsedInput.error
|
|
2616
2711
|
});
|
|
2617
2712
|
}
|
|
@@ -2620,7 +2715,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2620
2715
|
const requester = update.body !== void 0 || update.assign_requester ? await resolveGitHubRequester(ctx) : void 0;
|
|
2621
2716
|
const assignee = update.assign_requester ? linkedGitHubLogin(requester?.user) : void 0;
|
|
2622
2717
|
if (update.assign_requester && !assignee) {
|
|
2623
|
-
throw new
|
|
2718
|
+
throw new PluginToolInputError13(
|
|
2624
2719
|
"The requester has no linked GitHub account, so Junior cannot assign the issue to them."
|
|
2625
2720
|
);
|
|
2626
2721
|
}
|
|
@@ -2639,7 +2734,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2639
2734
|
currentBody
|
|
2640
2735
|
),
|
|
2641
2736
|
nonEmptyString4(ctx.conversationId, "conversationId"),
|
|
2642
|
-
ctx.
|
|
2737
|
+
ctx.conversationLink?.url
|
|
2643
2738
|
)
|
|
2644
2739
|
} : void 0,
|
|
2645
2740
|
...update.state !== void 0 ? { state: update.state } : void 0
|
|
@@ -2670,7 +2765,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2670
2765
|
if (!response.ok) {
|
|
2671
2766
|
const message = `GitHub issue assignment failed with HTTP ${response.status}: ${githubErrorMessage(parsed)}`;
|
|
2672
2767
|
if (response.status === 404 || response.status === 422) {
|
|
2673
|
-
throw new
|
|
2768
|
+
throw new PluginToolInputError13(message);
|
|
2674
2769
|
}
|
|
2675
2770
|
throw new Error(message);
|
|
2676
2771
|
}
|
|
@@ -2679,7 +2774,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2679
2774
|
if (assignee && !providerResult.assignees.some(
|
|
2680
2775
|
(login2) => login2.toLowerCase() === assignee.toLowerCase()
|
|
2681
2776
|
)) {
|
|
2682
|
-
throw new
|
|
2777
|
+
throw new PluginToolInputError13(
|
|
2683
2778
|
`GitHub did not assign @${assignee} to the issue. They may not have access to ${repo.ref}.`
|
|
2684
2779
|
);
|
|
2685
2780
|
}
|
|
@@ -2713,24 +2808,99 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2713
2808
|
});
|
|
2714
2809
|
}
|
|
2715
2810
|
|
|
2811
|
+
// src/tools/update-issue-comment.ts
|
|
2812
|
+
import {
|
|
2813
|
+
definePluginTool as definePluginTool14,
|
|
2814
|
+
PluginToolInputError as PluginToolInputError14,
|
|
2815
|
+
pluginToolOutputSchema as pluginToolOutputSchema14
|
|
2816
|
+
} from "@sentry/junior-plugin-api";
|
|
2817
|
+
import * as z19 from "zod";
|
|
2818
|
+
var inputSchema12 = z19.object({
|
|
2819
|
+
repo: z19.string().describe('Repository in "owner/name" format.'),
|
|
2820
|
+
comment_id: z19.number().int().positive().describe("Issue comment id, as returned by github_commentOnIssue."),
|
|
2821
|
+
body: z19.string().trim().min(1).describe("Replacement comment text.")
|
|
2822
|
+
}).strict();
|
|
2823
|
+
var outputSchema12 = pluginToolOutputSchema14.extend({
|
|
2824
|
+
target: z19.literal("updateIssueComment"),
|
|
2825
|
+
repo: z19.string(),
|
|
2826
|
+
comment_id: z19.number(),
|
|
2827
|
+
url: z19.string()
|
|
2828
|
+
});
|
|
2829
|
+
function createGitHubUpdateIssueCommentTool(egress, botEmail) {
|
|
2830
|
+
return definePluginTool14({
|
|
2831
|
+
annotations: {
|
|
2832
|
+
destructiveHint: true,
|
|
2833
|
+
idempotentHint: true,
|
|
2834
|
+
openWorldHint: true,
|
|
2835
|
+
readOnlyHint: false
|
|
2836
|
+
},
|
|
2837
|
+
description: "Replace the text of a GitHub issue or pull request conversation comment that you posted, for example to update a progress comment. Only works on your own comments.",
|
|
2838
|
+
inputSchema: inputSchema12,
|
|
2839
|
+
outputSchema: outputSchema12,
|
|
2840
|
+
async execute(input) {
|
|
2841
|
+
const repo = parseRepo(input.repo);
|
|
2842
|
+
const botUserId = botUserIdFromEmail(botEmail);
|
|
2843
|
+
if (botUserId === void 0) {
|
|
2844
|
+
throw new Error("GitHub App bot identity is not configured.");
|
|
2845
|
+
}
|
|
2846
|
+
const path = `${repoPath(repo)}/issues/comments/${input.comment_id}`;
|
|
2847
|
+
const lookup = await githubApi(egress, {
|
|
2848
|
+
operation: "github.issue.comment.get",
|
|
2849
|
+
path
|
|
2850
|
+
});
|
|
2851
|
+
if (!lookup.ok) {
|
|
2852
|
+
const message = `GitHub issue comment lookup failed with HTTP ${lookup.status}: ${githubErrorMessage(lookup.body)}`;
|
|
2853
|
+
if (lookup.status === 404) throw new PluginToolInputError14(message);
|
|
2854
|
+
throw new Error(message);
|
|
2855
|
+
}
|
|
2856
|
+
const author = z19.object({ user: z19.object({ id: z19.number() }).nullable() }).safeParse(lookup.body);
|
|
2857
|
+
if (!author.success || author.data.user?.id !== botUserId) {
|
|
2858
|
+
throw new PluginToolInputError14(
|
|
2859
|
+
"This bot can only edit issue comments it posted."
|
|
2860
|
+
);
|
|
2861
|
+
}
|
|
2862
|
+
const response = await githubApi(egress, {
|
|
2863
|
+
operation: "github.issue.comment.update",
|
|
2864
|
+
method: "PATCH",
|
|
2865
|
+
path,
|
|
2866
|
+
body: { body: input.body }
|
|
2867
|
+
});
|
|
2868
|
+
if (!response.ok) {
|
|
2869
|
+
const message = `GitHub issue comment update failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
|
|
2870
|
+
if (response.status === 404 || response.status === 422) {
|
|
2871
|
+
throw new PluginToolInputError14(message);
|
|
2872
|
+
}
|
|
2873
|
+
throw new Error(message);
|
|
2874
|
+
}
|
|
2875
|
+
const comment = z19.object({ id: z19.number(), html_url: z19.string() }).parse(response.body);
|
|
2876
|
+
return {
|
|
2877
|
+
target: "updateIssueComment",
|
|
2878
|
+
repo: repo.ref,
|
|
2879
|
+
comment_id: comment.id,
|
|
2880
|
+
url: comment.html_url
|
|
2881
|
+
};
|
|
2882
|
+
}
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2716
2886
|
// src/tools/update-pull-request.ts
|
|
2717
2887
|
import {
|
|
2718
|
-
definePluginTool as
|
|
2719
|
-
PluginToolInputError as
|
|
2720
|
-
pluginToolOutputSchema as
|
|
2888
|
+
definePluginTool as definePluginTool15,
|
|
2889
|
+
PluginToolInputError as PluginToolInputError15,
|
|
2890
|
+
pluginToolOutputSchema as pluginToolOutputSchema15
|
|
2721
2891
|
} from "@sentry/junior-plugin-api";
|
|
2722
|
-
import * as
|
|
2723
|
-
import { subscribableResourceSchema as subscribableResourceSchema9 } from "@sentry/junior-plugin-api";
|
|
2724
|
-
var
|
|
2725
|
-
repo:
|
|
2726
|
-
number:
|
|
2727
|
-
title:
|
|
2728
|
-
body:
|
|
2892
|
+
import * as z20 from "zod";
|
|
2893
|
+
import { subscribableResourceSchema as subscribableResourceSchema9 } from "@sentry/junior-plugin-api";
|
|
2894
|
+
var inputSchema13 = z20.object({
|
|
2895
|
+
repo: z20.string().describe('Repository in "owner/name" format.'),
|
|
2896
|
+
number: z20.number().int().positive().describe("Pull request number."),
|
|
2897
|
+
title: z20.string().trim().min(1).optional().describe("Replacement pull request title."),
|
|
2898
|
+
body: z20.string().optional().describe(
|
|
2729
2899
|
"Replacement pull request body. The runtime appends requester attribution and the conversation footer."
|
|
2730
2900
|
),
|
|
2731
|
-
base:
|
|
2732
|
-
state:
|
|
2733
|
-
draft:
|
|
2901
|
+
base: z20.string().trim().min(1).optional().describe("Replacement base branch."),
|
|
2902
|
+
state: z20.enum(["open", "closed"]).optional().describe("Replacement pull request state."),
|
|
2903
|
+
draft: z20.boolean().optional().describe(
|
|
2734
2904
|
"Set false to mark a draft pull request ready for review, or true to convert it back to a draft."
|
|
2735
2905
|
)
|
|
2736
2906
|
}).strict().refine(
|
|
@@ -2745,29 +2915,29 @@ var CONVERT_TO_DRAFT = {
|
|
|
2745
2915
|
operationName: "ConvertPullRequestToDraft",
|
|
2746
2916
|
query: "mutation ConvertPullRequestToDraft($id: ID!) { result: convertPullRequestToDraft(input: {pullRequestId: $id}) { pullRequest { isDraft } } }"
|
|
2747
2917
|
};
|
|
2748
|
-
var draftMutationResponseSchema =
|
|
2749
|
-
data:
|
|
2750
|
-
result:
|
|
2918
|
+
var draftMutationResponseSchema = z20.object({
|
|
2919
|
+
data: z20.object({
|
|
2920
|
+
result: z20.object({ pullRequest: z20.object({ isDraft: z20.boolean() }) })
|
|
2751
2921
|
})
|
|
2752
2922
|
});
|
|
2753
|
-
var pullRequestSchema2 =
|
|
2754
|
-
base:
|
|
2755
|
-
body:
|
|
2756
|
-
draft:
|
|
2757
|
-
number:
|
|
2758
|
-
state:
|
|
2923
|
+
var pullRequestSchema2 = z20.object({
|
|
2924
|
+
base: z20.string(),
|
|
2925
|
+
body: z20.string().nullable(),
|
|
2926
|
+
draft: z20.boolean(),
|
|
2927
|
+
number: z20.number(),
|
|
2928
|
+
state: z20.string(),
|
|
2759
2929
|
subscribable: subscribableResourceSchema9.optional(),
|
|
2760
|
-
title:
|
|
2761
|
-
url:
|
|
2930
|
+
title: z20.string(),
|
|
2931
|
+
url: z20.string()
|
|
2762
2932
|
});
|
|
2763
|
-
var
|
|
2933
|
+
var outputSchema13 = pluginToolOutputSchema15.merge(
|
|
2764
2934
|
pullRequestSchema2.extend({
|
|
2765
|
-
target:
|
|
2935
|
+
target: z20.literal("updatePullRequest")
|
|
2766
2936
|
})
|
|
2767
2937
|
);
|
|
2768
2938
|
function nonEmptyString5(value, name) {
|
|
2769
2939
|
if (!value?.trim()) {
|
|
2770
|
-
throw new
|
|
2940
|
+
throw new PluginToolInputError15(`${name} is required`);
|
|
2771
2941
|
}
|
|
2772
2942
|
return value.trim();
|
|
2773
2943
|
}
|
|
@@ -2793,7 +2963,7 @@ async function setPullRequestDraft(input) {
|
|
|
2793
2963
|
return isDraft;
|
|
2794
2964
|
}
|
|
2795
2965
|
function createGitHubUpdatePullRequestTool(ctx) {
|
|
2796
|
-
return
|
|
2966
|
+
return definePluginTool15({
|
|
2797
2967
|
annotations: {
|
|
2798
2968
|
destructiveHint: true,
|
|
2799
2969
|
idempotentHint: true,
|
|
@@ -2801,12 +2971,12 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2801
2971
|
readOnlyHint: false
|
|
2802
2972
|
},
|
|
2803
2973
|
description: "Update an existing GitHub pull request's title, body, base branch, open/closed state, or draft state. Use this instead of raw GitHub API calls when changing PR metadata or marking a PR ready for review.",
|
|
2804
|
-
inputSchema:
|
|
2805
|
-
outputSchema:
|
|
2974
|
+
inputSchema: inputSchema13,
|
|
2975
|
+
outputSchema: outputSchema13,
|
|
2806
2976
|
async execute(input) {
|
|
2807
|
-
const parsedInput =
|
|
2977
|
+
const parsedInput = inputSchema13.safeParse(input);
|
|
2808
2978
|
if (!parsedInput.success) {
|
|
2809
|
-
throw new
|
|
2979
|
+
throw new PluginToolInputError15(
|
|
2810
2980
|
"Invalid GitHub updatePullRequest input.",
|
|
2811
2981
|
{ cause: parsedInput.error }
|
|
2812
2982
|
);
|
|
@@ -2829,7 +2999,7 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2829
2999
|
currentBody
|
|
2830
3000
|
),
|
|
2831
3001
|
nonEmptyString5(ctx.conversationId, "conversationId"),
|
|
2832
|
-
ctx.
|
|
3002
|
+
ctx.conversationLink?.url
|
|
2833
3003
|
)
|
|
2834
3004
|
} : void 0,
|
|
2835
3005
|
...update.base !== void 0 ? { base: update.base } : void 0,
|
|
@@ -2847,16 +3017,16 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2847
3017
|
`GitHub pull request update failed with HTTP ${response.status}: ${githubErrorMessage(parsed)}`
|
|
2848
3018
|
);
|
|
2849
3019
|
}
|
|
2850
|
-
const providerResult =
|
|
2851
|
-
base:
|
|
2852
|
-
body:
|
|
2853
|
-
draft:
|
|
2854
|
-
html_url:
|
|
2855
|
-
merged:
|
|
2856
|
-
node_id:
|
|
2857
|
-
number:
|
|
2858
|
-
state:
|
|
2859
|
-
title:
|
|
3020
|
+
const providerResult = z20.object({
|
|
3021
|
+
base: z20.object({ ref: z20.string() }),
|
|
3022
|
+
body: z20.string().nullable().optional().default(null),
|
|
3023
|
+
draft: z20.boolean(),
|
|
3024
|
+
html_url: z20.string(),
|
|
3025
|
+
merged: z20.boolean(),
|
|
3026
|
+
node_id: z20.string().optional(),
|
|
3027
|
+
number: z20.number(),
|
|
3028
|
+
state: z20.string(),
|
|
3029
|
+
title: z20.string()
|
|
2860
3030
|
}).parse(parsed);
|
|
2861
3031
|
if (update.draft !== void 0 && update.draft !== providerResult.draft) {
|
|
2862
3032
|
if (!providerResult.node_id) {
|
|
@@ -2917,11 +3087,11 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2917
3087
|
|
|
2918
3088
|
// src/tools/update-pull-request-feedback.ts
|
|
2919
3089
|
import {
|
|
2920
|
-
definePluginTool as
|
|
2921
|
-
PluginToolInputError as
|
|
2922
|
-
pluginToolOutputSchema as
|
|
3090
|
+
definePluginTool as definePluginTool16,
|
|
3091
|
+
PluginToolInputError as PluginToolInputError16,
|
|
3092
|
+
pluginToolOutputSchema as pluginToolOutputSchema16
|
|
2923
3093
|
} from "@sentry/junior-plugin-api";
|
|
2924
|
-
import * as
|
|
3094
|
+
import * as z21 from "zod";
|
|
2925
3095
|
var STATUS_TO_REACTION_CONTENT = {
|
|
2926
3096
|
reviewing: "eyes",
|
|
2927
3097
|
addressed: "+1",
|
|
@@ -2941,24 +3111,24 @@ var REST_REACTION_CONTENT = new Map(
|
|
|
2941
3111
|
rest
|
|
2942
3112
|
])
|
|
2943
3113
|
);
|
|
2944
|
-
var
|
|
2945
|
-
repo:
|
|
2946
|
-
comment_kind:
|
|
3114
|
+
var inputSchema14 = z21.object({
|
|
3115
|
+
repo: z21.string().describe('Repository in "owner/name" format.'),
|
|
3116
|
+
comment_kind: z21.enum(["conversation", "review", "review_body"]).describe(
|
|
2947
3117
|
'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment, "review_body" for the body of a submitted review.'
|
|
2948
3118
|
),
|
|
2949
|
-
comment_id:
|
|
3119
|
+
comment_id: z21.number().int().positive().describe(
|
|
2950
3120
|
"GitHub comment id (conversation comment id, inline review comment id, or review id)."
|
|
2951
3121
|
),
|
|
2952
|
-
pull_request:
|
|
2953
|
-
status:
|
|
3122
|
+
pull_request: z21.number().int().positive().describe("Pull request number that the comment is on."),
|
|
3123
|
+
status: z21.enum(["addressed", "declined"]).describe(
|
|
2954
3124
|
"Feedback outcome. Maps to a reaction: addressed -> +1, declined -> -1."
|
|
2955
3125
|
)
|
|
2956
3126
|
}).strict();
|
|
2957
|
-
var
|
|
2958
|
-
target:
|
|
2959
|
-
repo:
|
|
2960
|
-
comment_id:
|
|
2961
|
-
status:
|
|
3127
|
+
var outputSchema14 = pluginToolOutputSchema16.extend({
|
|
3128
|
+
target: z21.literal("updatePullRequestFeedback"),
|
|
3129
|
+
repo: z21.string(),
|
|
3130
|
+
comment_id: z21.number(),
|
|
3131
|
+
status: z21.enum(["addressed", "declined"])
|
|
2962
3132
|
});
|
|
2963
3133
|
function pullRequestCommentPath(input) {
|
|
2964
3134
|
const segment = input.commentKind === "conversation" ? "issues" : "pulls";
|
|
@@ -2970,10 +3140,10 @@ function pullRequestCommentReactionsPath(input) {
|
|
|
2970
3140
|
function pullRequestFeedbackReactionContent(status) {
|
|
2971
3141
|
return STATUS_TO_REACTION_CONTENT[status];
|
|
2972
3142
|
}
|
|
2973
|
-
var reactionSchema =
|
|
2974
|
-
id:
|
|
2975
|
-
content:
|
|
2976
|
-
user:
|
|
3143
|
+
var reactionSchema = z21.object({
|
|
3144
|
+
id: z21.number(),
|
|
3145
|
+
content: z21.string(),
|
|
3146
|
+
user: z21.object({ id: z21.number() }).nullable()
|
|
2977
3147
|
});
|
|
2978
3148
|
async function commentParentNumber(egress, input) {
|
|
2979
3149
|
const commentResponse = await githubApi(egress, {
|
|
@@ -2983,25 +3153,25 @@ async function commentParentNumber(egress, input) {
|
|
|
2983
3153
|
const commentPayload = commentResponse.body;
|
|
2984
3154
|
if (!commentResponse.ok) {
|
|
2985
3155
|
const message = `GitHub comment lookup failed with HTTP ${commentResponse.status}: ${githubErrorMessage(commentPayload)}`;
|
|
2986
|
-
if (commentResponse.status === 404) throw new
|
|
3156
|
+
if (commentResponse.status === 404) throw new PluginToolInputError16(message);
|
|
2987
3157
|
throw new Error(message);
|
|
2988
3158
|
}
|
|
2989
|
-
const comment =
|
|
2990
|
-
issue_url:
|
|
2991
|
-
pull_request_url:
|
|
3159
|
+
const comment = z21.object({
|
|
3160
|
+
issue_url: z21.string().optional(),
|
|
3161
|
+
pull_request_url: z21.string().optional()
|
|
2992
3162
|
}).safeParse(commentPayload);
|
|
2993
3163
|
const parentUrl = comment.success ? input.commentKind === "conversation" ? comment.data.issue_url : comment.data.pull_request_url : void 0;
|
|
2994
|
-
const
|
|
2995
|
-
if (!
|
|
3164
|
+
const number31 = /\/(?:issues|pulls)\/(\d+)$/.exec(parentUrl ?? "")?.[1];
|
|
3165
|
+
if (!number31) {
|
|
2996
3166
|
throw new Error("GitHub comment did not name its issue or pull request.");
|
|
2997
3167
|
}
|
|
2998
|
-
return
|
|
3168
|
+
return number31;
|
|
2999
3169
|
}
|
|
3000
3170
|
async function assertBotAuthoredPullRequest(egress, input) {
|
|
3001
|
-
const { number:
|
|
3171
|
+
const { number: number31 } = input;
|
|
3002
3172
|
const pullResponse = await githubApi(egress, {
|
|
3003
3173
|
operation: "github.pull.get",
|
|
3004
|
-
path: `${repoPath(input)}/pulls/${
|
|
3174
|
+
path: `${repoPath(input)}/pulls/${number31}`
|
|
3005
3175
|
});
|
|
3006
3176
|
const pullPayload = pullResponse.body;
|
|
3007
3177
|
if (!pullResponse.ok && pullResponse.status !== 404) {
|
|
@@ -3009,9 +3179,9 @@ async function assertBotAuthoredPullRequest(egress, input) {
|
|
|
3009
3179
|
`GitHub pull request lookup failed with HTTP ${pullResponse.status}: ${githubErrorMessage(pullPayload)}`
|
|
3010
3180
|
);
|
|
3011
3181
|
}
|
|
3012
|
-
const pull =
|
|
3182
|
+
const pull = z21.object({ user: z21.object({ id: z21.number() }).nullable() }).safeParse(pullPayload);
|
|
3013
3183
|
if (!pullResponse.ok || !pull.success || pull.data.user?.id !== input.botUserId) {
|
|
3014
|
-
throw new
|
|
3184
|
+
throw new PluginToolInputError16(
|
|
3015
3185
|
"This bot can only set feedback status on comments on pull requests it authored."
|
|
3016
3186
|
);
|
|
3017
3187
|
}
|
|
@@ -3042,14 +3212,14 @@ var REVIEW_REACTIONS_QUERY = `query ReviewReactions($subjectId: ID!) {
|
|
|
3042
3212
|
}
|
|
3043
3213
|
}
|
|
3044
3214
|
}`;
|
|
3045
|
-
var reviewReactionsSchema =
|
|
3046
|
-
data:
|
|
3047
|
-
node:
|
|
3048
|
-
reactionGroups:
|
|
3049
|
-
|
|
3050
|
-
content:
|
|
3051
|
-
reactors:
|
|
3052
|
-
nodes:
|
|
3215
|
+
var reviewReactionsSchema = z21.object({
|
|
3216
|
+
data: z21.object({
|
|
3217
|
+
node: z21.object({
|
|
3218
|
+
reactionGroups: z21.array(
|
|
3219
|
+
z21.object({
|
|
3220
|
+
content: z21.string(),
|
|
3221
|
+
reactors: z21.object({
|
|
3222
|
+
nodes: z21.array(z21.object({ databaseId: z21.number().optional() }))
|
|
3053
3223
|
})
|
|
3054
3224
|
})
|
|
3055
3225
|
)
|
|
@@ -3059,7 +3229,7 @@ var reviewReactionsSchema = z19.object({
|
|
|
3059
3229
|
async function commentReactions(egress, input) {
|
|
3060
3230
|
const parentNumber = await commentParentNumber(egress, input);
|
|
3061
3231
|
if (parentNumber !== String(input.pullRequest)) {
|
|
3062
|
-
throw new
|
|
3232
|
+
throw new PluginToolInputError16(
|
|
3063
3233
|
`GitHub comment ${input.commentId} is not on pull request ${input.pullRequest}.`
|
|
3064
3234
|
);
|
|
3065
3235
|
}
|
|
@@ -3069,7 +3239,7 @@ async function commentReactions(egress, input) {
|
|
|
3069
3239
|
operation: "github.pull.comment-reaction.list",
|
|
3070
3240
|
path: `${path}?per_page=100`
|
|
3071
3241
|
}),
|
|
3072
|
-
botReactions: (body) =>
|
|
3242
|
+
botReactions: (body) => z21.array(reactionSchema).parse(body).filter((reaction) => reaction.user?.id === input.botUserId),
|
|
3073
3243
|
remove: (reaction) => githubApi(egress, {
|
|
3074
3244
|
operation: "github.pull.comment-reaction.delete",
|
|
3075
3245
|
method: "DELETE",
|
|
@@ -3090,10 +3260,10 @@ async function reviewBodyReactions(egress, input) {
|
|
|
3090
3260
|
});
|
|
3091
3261
|
if (!reviewResponse.ok) {
|
|
3092
3262
|
const message = `GitHub review lookup failed with HTTP ${reviewResponse.status}: ${githubErrorMessage(reviewResponse.body)}`;
|
|
3093
|
-
if (reviewResponse.status === 404) throw new
|
|
3263
|
+
if (reviewResponse.status === 404) throw new PluginToolInputError16(message);
|
|
3094
3264
|
throw new Error(message);
|
|
3095
3265
|
}
|
|
3096
|
-
const subjectId =
|
|
3266
|
+
const subjectId = z21.object({ node_id: z21.string().min(1) }).parse(reviewResponse.body).node_id;
|
|
3097
3267
|
const graphql = (operation, operationName, query, variables) => githubApi(egress, {
|
|
3098
3268
|
operation,
|
|
3099
3269
|
method: "POST",
|
|
@@ -3130,7 +3300,7 @@ function failed(response) {
|
|
|
3130
3300
|
return !response.ok || Array.isArray(errors) && errors.length > 0;
|
|
3131
3301
|
}
|
|
3132
3302
|
function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
3133
|
-
return
|
|
3303
|
+
return definePluginTool16({
|
|
3134
3304
|
// No action review: the tool checks in code that the bot authored the pull
|
|
3135
3305
|
// request, and it changes only the bot's own reaction, which is reversible.
|
|
3136
3306
|
approvalMode: "approve",
|
|
@@ -3142,12 +3312,12 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3142
3312
|
},
|
|
3143
3313
|
description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1). Use the pull_request, comment_id, and comment_kind from the event after acting on the feedback. Replaces only your prior status reaction on that comment. Only works on pull requests the bot authored.",
|
|
3144
3314
|
exposure: "direct",
|
|
3145
|
-
inputSchema:
|
|
3146
|
-
outputSchema:
|
|
3315
|
+
inputSchema: inputSchema14,
|
|
3316
|
+
outputSchema: outputSchema14,
|
|
3147
3317
|
async execute(input) {
|
|
3148
|
-
const parsedInput =
|
|
3318
|
+
const parsedInput = inputSchema14.safeParse(input);
|
|
3149
3319
|
if (!parsedInput.success) {
|
|
3150
|
-
throw new
|
|
3320
|
+
throw new PluginToolInputError16(
|
|
3151
3321
|
"Invalid GitHub updatePullRequestFeedback input.",
|
|
3152
3322
|
{ cause: parsedInput.error }
|
|
3153
3323
|
);
|
|
@@ -3222,28 +3392,28 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3222
3392
|
|
|
3223
3393
|
// src/tools/resolve-pull-request-review-thread.ts
|
|
3224
3394
|
import {
|
|
3225
|
-
definePluginTool as
|
|
3226
|
-
PluginToolInputError as
|
|
3227
|
-
pluginToolOutputSchema as
|
|
3395
|
+
definePluginTool as definePluginTool17,
|
|
3396
|
+
PluginToolInputError as PluginToolInputError17,
|
|
3397
|
+
pluginToolOutputSchema as pluginToolOutputSchema17
|
|
3228
3398
|
} from "@sentry/junior-plugin-api";
|
|
3229
|
-
import * as
|
|
3230
|
-
var
|
|
3231
|
-
repo:
|
|
3399
|
+
import * as z22 from "zod";
|
|
3400
|
+
var inputSchema15 = z22.object({
|
|
3401
|
+
repo: z22.string().describe(
|
|
3232
3402
|
'Repository in "owner/name" format. Required because GraphQL has no repo path.'
|
|
3233
3403
|
),
|
|
3234
|
-
thread_id:
|
|
3404
|
+
thread_id: z22.string().trim().min(1).describe(
|
|
3235
3405
|
"GitHub pull request review thread node ID (the `threadId` / `id` variable used by `gh api graphql` resolveReviewThread)."
|
|
3236
3406
|
)
|
|
3237
3407
|
}).strict();
|
|
3238
|
-
var
|
|
3239
|
-
target:
|
|
3240
|
-
repo:
|
|
3241
|
-
number:
|
|
3242
|
-
thread_id:
|
|
3243
|
-
resolved:
|
|
3408
|
+
var outputSchema15 = pluginToolOutputSchema17.extend({
|
|
3409
|
+
target: z22.literal("resolvePullRequestReviewThread"),
|
|
3410
|
+
repo: z22.string(),
|
|
3411
|
+
number: z22.number(),
|
|
3412
|
+
thread_id: z22.string(),
|
|
3413
|
+
resolved: z22.boolean()
|
|
3244
3414
|
});
|
|
3245
3415
|
function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
3246
|
-
return
|
|
3416
|
+
return definePluginTool17({
|
|
3247
3417
|
// No action review: the tool checks in code that the bot authored the pull
|
|
3248
3418
|
// request, and it changes only the thread's resolved state, which is
|
|
3249
3419
|
// reversible.
|
|
@@ -3256,12 +3426,12 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3256
3426
|
},
|
|
3257
3427
|
description: "Resolve a GitHub pull request review thread after acting on its feedback. Only works on pull requests the bot authored.",
|
|
3258
3428
|
exposure: "direct",
|
|
3259
|
-
inputSchema:
|
|
3260
|
-
outputSchema:
|
|
3429
|
+
inputSchema: inputSchema15,
|
|
3430
|
+
outputSchema: outputSchema15,
|
|
3261
3431
|
async execute(input) {
|
|
3262
|
-
const parsedInput =
|
|
3432
|
+
const parsedInput = inputSchema15.safeParse(input);
|
|
3263
3433
|
if (!parsedInput.success) {
|
|
3264
|
-
throw new
|
|
3434
|
+
throw new PluginToolInputError17(
|
|
3265
3435
|
"Invalid GitHub resolvePullRequestReviewThread input.",
|
|
3266
3436
|
{ cause: parsedInput.error }
|
|
3267
3437
|
);
|
|
@@ -3300,31 +3470,31 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3300
3470
|
`GitHub review thread lookup failed with HTTP ${lookupResponse.status}: ${githubErrorMessage(lookupPayload)}`
|
|
3301
3471
|
);
|
|
3302
3472
|
}
|
|
3303
|
-
const threadNodeSchema =
|
|
3304
|
-
id:
|
|
3305
|
-
isResolved:
|
|
3306
|
-
pullRequest:
|
|
3307
|
-
author:
|
|
3308
|
-
number:
|
|
3309
|
-
repository:
|
|
3473
|
+
const threadNodeSchema = z22.object({
|
|
3474
|
+
id: z22.string(),
|
|
3475
|
+
isResolved: z22.boolean(),
|
|
3476
|
+
pullRequest: z22.object({
|
|
3477
|
+
author: z22.object({ databaseId: z22.number().optional() }).passthrough().nullable(),
|
|
3478
|
+
number: z22.number(),
|
|
3479
|
+
repository: z22.object({ nameWithOwner: z22.string() }).passthrough()
|
|
3310
3480
|
}).passthrough()
|
|
3311
3481
|
}).passthrough();
|
|
3312
|
-
const lookupResultSchema =
|
|
3313
|
-
data:
|
|
3314
|
-
node:
|
|
3482
|
+
const lookupResultSchema = z22.object({
|
|
3483
|
+
data: z22.object({
|
|
3484
|
+
node: z22.unknown().nullable().optional()
|
|
3315
3485
|
}).passthrough()
|
|
3316
3486
|
}).passthrough();
|
|
3317
3487
|
const lookupResult = lookupResultSchema.safeParse(lookupPayload);
|
|
3318
3488
|
const rawNode = lookupResult.success ? lookupResult.data.data.node : void 0;
|
|
3319
3489
|
const parsedNode = rawNode == null ? void 0 : threadNodeSchema.safeParse(rawNode);
|
|
3320
3490
|
if (!parsedNode?.success) {
|
|
3321
|
-
throw new
|
|
3491
|
+
throw new PluginToolInputError17("GitHub review thread was not found.");
|
|
3322
3492
|
}
|
|
3323
3493
|
const thread = parsedNode.data;
|
|
3324
3494
|
const pullRequest = thread.pullRequest;
|
|
3325
3495
|
const ownsPullRequest = pullRequest.repository.nameWithOwner.toLowerCase() === repo.ref.toLowerCase() && pullRequest.author?.databaseId === botUserId;
|
|
3326
3496
|
if (!ownsPullRequest) {
|
|
3327
|
-
throw new
|
|
3497
|
+
throw new PluginToolInputError17(
|
|
3328
3498
|
"This bot can only resolve review threads on pull requests it authored."
|
|
3329
3499
|
);
|
|
3330
3500
|
}
|
|
@@ -3358,10 +3528,10 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3358
3528
|
`GitHub review thread resolution failed with HTTP ${resolveResponse.status}: ${githubErrorMessage(resolvePayload)}`
|
|
3359
3529
|
);
|
|
3360
3530
|
}
|
|
3361
|
-
const resolveResultSchema =
|
|
3362
|
-
data:
|
|
3363
|
-
resolveReviewThread:
|
|
3364
|
-
thread:
|
|
3531
|
+
const resolveResultSchema = z22.object({
|
|
3532
|
+
data: z22.object({
|
|
3533
|
+
resolveReviewThread: z22.object({
|
|
3534
|
+
thread: z22.object({ id: z22.string(), isResolved: z22.boolean() }).passthrough()
|
|
3365
3535
|
}).passthrough()
|
|
3366
3536
|
}).passthrough()
|
|
3367
3537
|
}).passthrough();
|
|
@@ -3389,46 +3559,46 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3389
3559
|
|
|
3390
3560
|
// src/tools/submit-pull-request-review.ts
|
|
3391
3561
|
import {
|
|
3392
|
-
definePluginTool as
|
|
3393
|
-
PluginToolInputError as
|
|
3394
|
-
pluginToolOutputSchema as
|
|
3562
|
+
definePluginTool as definePluginTool18,
|
|
3563
|
+
PluginToolInputError as PluginToolInputError18,
|
|
3564
|
+
pluginToolOutputSchema as pluginToolOutputSchema18
|
|
3395
3565
|
} from "@sentry/junior-plugin-api";
|
|
3396
|
-
import * as
|
|
3397
|
-
var reviewCommentSchema =
|
|
3398
|
-
path:
|
|
3399
|
-
body:
|
|
3400
|
-
line:
|
|
3401
|
-
side:
|
|
3402
|
-
start_line:
|
|
3403
|
-
start_side:
|
|
3566
|
+
import * as z23 from "zod";
|
|
3567
|
+
var reviewCommentSchema = z23.object({
|
|
3568
|
+
path: z23.string().trim().min(1).describe("File path in the pull request."),
|
|
3569
|
+
body: z23.string().trim().min(1).describe("Inline review comment."),
|
|
3570
|
+
line: z23.number().int().positive().describe("Line in the pull request diff."),
|
|
3571
|
+
side: z23.enum(["LEFT", "RIGHT"]).describe("Side of the pull request diff."),
|
|
3572
|
+
start_line: z23.number().int().positive().optional().describe("First line of a multi-line comment."),
|
|
3573
|
+
start_side: z23.enum(["LEFT", "RIGHT"]).optional().describe("First side of a multi-line comment.")
|
|
3404
3574
|
}).strict().refine(
|
|
3405
3575
|
({ start_line, start_side }) => start_line === void 0 === (start_side === void 0),
|
|
3406
3576
|
{ message: "start_line and start_side must be provided together." }
|
|
3407
3577
|
);
|
|
3408
|
-
var
|
|
3409
|
-
repo:
|
|
3410
|
-
number:
|
|
3411
|
-
event:
|
|
3412
|
-
body:
|
|
3413
|
-
comments:
|
|
3578
|
+
var inputSchema16 = z23.object({
|
|
3579
|
+
repo: z23.string().describe('Repository in "owner/name" format.'),
|
|
3580
|
+
number: z23.number().int().positive().describe("Pull request number."),
|
|
3581
|
+
event: z23.enum(["COMMENT", "REQUEST_CHANGES"]).describe("Review result. You cannot approve pull requests."),
|
|
3582
|
+
body: z23.string().trim().min(1).describe("Review summary."),
|
|
3583
|
+
comments: z23.array(reviewCommentSchema).optional().describe("Optional inline review comments.")
|
|
3414
3584
|
}).strict();
|
|
3415
|
-
var
|
|
3416
|
-
target:
|
|
3417
|
-
repo:
|
|
3418
|
-
number:
|
|
3419
|
-
review_id:
|
|
3420
|
-
state:
|
|
3421
|
-
url:
|
|
3585
|
+
var outputSchema16 = pluginToolOutputSchema18.extend({
|
|
3586
|
+
target: z23.literal("submitPullRequestReview"),
|
|
3587
|
+
repo: z23.string(),
|
|
3588
|
+
number: z23.number(),
|
|
3589
|
+
review_id: z23.number(),
|
|
3590
|
+
state: z23.string(),
|
|
3591
|
+
url: z23.string()
|
|
3422
3592
|
});
|
|
3423
3593
|
function throwReviewError(status, body) {
|
|
3424
3594
|
const message = `GitHub pull request review failed with HTTP ${status}: ${githubErrorMessage(body)}`;
|
|
3425
3595
|
if (status === 404 || status === 422) {
|
|
3426
|
-
throw new
|
|
3596
|
+
throw new PluginToolInputError18(message);
|
|
3427
3597
|
}
|
|
3428
3598
|
throw new Error(message);
|
|
3429
3599
|
}
|
|
3430
3600
|
function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
3431
|
-
return
|
|
3601
|
+
return definePluginTool18({
|
|
3432
3602
|
annotations: {
|
|
3433
3603
|
destructiveHint: true,
|
|
3434
3604
|
idempotentHint: false,
|
|
@@ -3436,8 +3606,8 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
3436
3606
|
readOnlyHint: false
|
|
3437
3607
|
},
|
|
3438
3608
|
description: "Submit a GitHub pull request review as a comment or change request. Use this instead of `gh pr review`, GraphQL, or direct REST calls. You cannot approve pull requests.",
|
|
3439
|
-
inputSchema:
|
|
3440
|
-
outputSchema:
|
|
3609
|
+
inputSchema: inputSchema16,
|
|
3610
|
+
outputSchema: outputSchema16,
|
|
3441
3611
|
async execute(review) {
|
|
3442
3612
|
const repo = parseRepo(review.repo);
|
|
3443
3613
|
const comments = review.comments?.map((comment) => ({
|
|
@@ -3461,7 +3631,7 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
3461
3631
|
if (!response.ok) {
|
|
3462
3632
|
throwReviewError(response.status, response.body);
|
|
3463
3633
|
}
|
|
3464
|
-
const providerResult =
|
|
3634
|
+
const providerResult = z23.object({ id: z23.number(), html_url: z23.string(), state: z23.string() }).parse(response.body);
|
|
3465
3635
|
return {
|
|
3466
3636
|
target: "submitPullRequestReview",
|
|
3467
3637
|
repo: repo.ref,
|
|
@@ -3478,6 +3648,7 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
3478
3648
|
// src/tools.ts
|
|
3479
3649
|
function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
3480
3650
|
return {
|
|
3651
|
+
reactToIssue: createGitHubReactToIssueTool(ctx.egress),
|
|
3481
3652
|
cloneRepository: createGitHubCloneRepositoryTool(ctx),
|
|
3482
3653
|
commentOnIssue: createGitHubCommentOnIssueTool(ctx.egress),
|
|
3483
3654
|
commentOnPullRequest: createGitHubCommentOnPullRequestTool(ctx.egress),
|
|
@@ -3497,6 +3668,10 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
|
3497
3668
|
ctx.egress
|
|
3498
3669
|
),
|
|
3499
3670
|
updateIssue: createGitHubUpdateIssueTool(ctx),
|
|
3671
|
+
updateIssueComment: createGitHubUpdateIssueCommentTool(
|
|
3672
|
+
ctx.egress,
|
|
3673
|
+
botEmail
|
|
3674
|
+
),
|
|
3500
3675
|
updatePullRequest: createGitHubUpdatePullRequestTool(ctx),
|
|
3501
3676
|
updatePullRequestFeedback: createGitHubUpdatePullRequestFeedbackTool(
|
|
3502
3677
|
ctx,
|
|
@@ -3507,26 +3682,26 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
|
3507
3682
|
|
|
3508
3683
|
// src/webhooks/handler.ts
|
|
3509
3684
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
3510
|
-
import * as
|
|
3685
|
+
import * as z37 from "zod";
|
|
3511
3686
|
|
|
3512
3687
|
// src/issue-outcomes/store.ts
|
|
3513
3688
|
import { and as and2, eq as eq2, lte, sql as sql2 } from "drizzle-orm";
|
|
3514
|
-
import * as
|
|
3515
|
-
var githubIssueOutcomeInputSchema =
|
|
3516
|
-
candidateOwned:
|
|
3517
|
-
closedAt:
|
|
3518
|
-
issueId:
|
|
3519
|
-
number:
|
|
3520
|
-
openedAt:
|
|
3521
|
-
repositoryFullName:
|
|
3522
|
-
repositoryId:
|
|
3689
|
+
import * as z24 from "zod";
|
|
3690
|
+
var githubIssueOutcomeInputSchema = z24.object({
|
|
3691
|
+
candidateOwned: z24.boolean(),
|
|
3692
|
+
closedAt: z24.date().optional(),
|
|
3693
|
+
issueId: z24.string().min(1),
|
|
3694
|
+
number: z24.number().int().positive(),
|
|
3695
|
+
openedAt: z24.date(),
|
|
3696
|
+
repositoryFullName: z24.string().min(1),
|
|
3697
|
+
repositoryId: z24.string().min(1),
|
|
3523
3698
|
state: githubIssueStateSchema,
|
|
3524
3699
|
stateReason: githubIssueStateReasonSchema.optional(),
|
|
3525
|
-
updatedAt:
|
|
3700
|
+
updatedAt: z24.date()
|
|
3526
3701
|
}).strict();
|
|
3527
|
-
var githubIssueConversationsInputSchema =
|
|
3528
|
-
conversationIds:
|
|
3529
|
-
issueId:
|
|
3702
|
+
var githubIssueConversationsInputSchema = z24.object({
|
|
3703
|
+
conversationIds: z24.array(z24.string().min(1)).min(1),
|
|
3704
|
+
issueId: z24.string().min(1)
|
|
3530
3705
|
}).strict();
|
|
3531
3706
|
function projectionValues(input) {
|
|
3532
3707
|
return {
|
|
@@ -3589,34 +3764,34 @@ async function recordGitHubIssueConversations(db, input) {
|
|
|
3589
3764
|
}
|
|
3590
3765
|
|
|
3591
3766
|
// src/pull-request-outcomes/store.ts
|
|
3592
|
-
import { and as and3, eq as eq3, lte as lte2, ne, sql as sql3 } from "drizzle-orm";
|
|
3593
|
-
import * as
|
|
3594
|
-
var githubPullRequestOutcomeInputSchema =
|
|
3595
|
-
candidateOwned:
|
|
3596
|
-
closedAt:
|
|
3767
|
+
import { and as and3, eq as eq3, lt as lt2, lte as lte2, ne, sql as sql3 } from "drizzle-orm";
|
|
3768
|
+
import * as z25 from "zod";
|
|
3769
|
+
var githubPullRequestOutcomeInputSchema = z25.object({
|
|
3770
|
+
candidateOwned: z25.boolean(),
|
|
3771
|
+
closedAt: z25.date().optional(),
|
|
3597
3772
|
commitComposition: githubPullRequestCommitCompositionSchema.optional(),
|
|
3598
|
-
mergedAt:
|
|
3599
|
-
number:
|
|
3600
|
-
openedAt:
|
|
3601
|
-
pullRequestId:
|
|
3602
|
-
repositoryFullName:
|
|
3603
|
-
repositoryId:
|
|
3773
|
+
mergedAt: z25.date().optional(),
|
|
3774
|
+
number: z25.number().int().positive(),
|
|
3775
|
+
openedAt: z25.date(),
|
|
3776
|
+
pullRequestId: z25.string().min(1),
|
|
3777
|
+
repositoryFullName: z25.string().min(1),
|
|
3778
|
+
repositoryId: z25.string().min(1),
|
|
3604
3779
|
state: githubPullRequestStateSchema,
|
|
3605
|
-
title:
|
|
3606
|
-
updatedAt:
|
|
3780
|
+
title: z25.string().min(1).optional(),
|
|
3781
|
+
updatedAt: z25.date()
|
|
3607
3782
|
}).strict();
|
|
3608
|
-
var githubPullRequestConversationsInputSchema =
|
|
3609
|
-
conversationIds:
|
|
3610
|
-
pullRequestId:
|
|
3783
|
+
var githubPullRequestConversationsInputSchema = z25.object({
|
|
3784
|
+
conversationIds: z25.array(z25.string().min(1)).min(1),
|
|
3785
|
+
pullRequestId: z25.string().min(1)
|
|
3611
3786
|
}).strict();
|
|
3612
|
-
var githubPullRequestLinkedIssuesInputSchema =
|
|
3613
|
-
linkedIssues:
|
|
3614
|
-
|
|
3615
|
-
number:
|
|
3616
|
-
repositoryFullName:
|
|
3787
|
+
var githubPullRequestLinkedIssuesInputSchema = z25.object({
|
|
3788
|
+
linkedIssues: z25.array(
|
|
3789
|
+
z25.object({
|
|
3790
|
+
number: z25.number().int().positive(),
|
|
3791
|
+
repositoryFullName: z25.string().min(1)
|
|
3617
3792
|
}).strict()
|
|
3618
3793
|
).min(1),
|
|
3619
|
-
pullRequestId:
|
|
3794
|
+
pullRequestId: z25.string().min(1)
|
|
3620
3795
|
}).strict();
|
|
3621
3796
|
function projectionValues2(input) {
|
|
3622
3797
|
return {
|
|
@@ -3726,6 +3901,10 @@ async function listGitHubFinishedWork(db, conversationIds) {
|
|
|
3726
3901
|
})
|
|
3727
3902
|
);
|
|
3728
3903
|
}
|
|
3904
|
+
async function listGitHubStaleOpenPullRequests(db, before) {
|
|
3905
|
+
const t = juniorGitHubPullRequests;
|
|
3906
|
+
return await db.select({ number: t.number, repositoryFullName: t.repositoryFullName }).from(t).where(and3(eq3(t.state, "open"), lt2(t.updatedAt, before))).orderBy(t.updatedAt);
|
|
3907
|
+
}
|
|
3729
3908
|
async function listGitHubAssignedWork(db, conversationIds) {
|
|
3730
3909
|
if (conversationIds.length === 0) return [];
|
|
3731
3910
|
const values = sql3.join(
|
|
@@ -3820,40 +3999,83 @@ async function releaseGitHubPullRequestReadySync(db, target, claim) {
|
|
|
3820
3999
|
return row?.requests;
|
|
3821
4000
|
}
|
|
3822
4001
|
|
|
4002
|
+
// src/pull-request-outcomes/apply.ts
|
|
4003
|
+
function githubCodeChange(outcome, conversationIds) {
|
|
4004
|
+
return {
|
|
4005
|
+
closedAt: outcome.closedAt,
|
|
4006
|
+
conversationIds,
|
|
4007
|
+
mergedAt: outcome.mergedAt,
|
|
4008
|
+
number: outcome.number,
|
|
4009
|
+
openedAt: outcome.openedAt,
|
|
4010
|
+
providerId: outcome.pullRequestId,
|
|
4011
|
+
repository: {
|
|
4012
|
+
name: outcome.repositoryFullName,
|
|
4013
|
+
providerId: outcome.repositoryId,
|
|
4014
|
+
url: `https://github.com/${outcome.repositoryFullName}`
|
|
4015
|
+
},
|
|
4016
|
+
state: outcome.state === "closed_unmerged" ? "closed" : outcome.state,
|
|
4017
|
+
title: outcome.title,
|
|
4018
|
+
updatedAt: outcome.updatedAt,
|
|
4019
|
+
url: `https://github.com/${outcome.repositoryFullName}/pull/${outcome.number}`
|
|
4020
|
+
};
|
|
4021
|
+
}
|
|
4022
|
+
async function applyGitHubPullRequestOutcome(args) {
|
|
4023
|
+
const { outcome } = args;
|
|
4024
|
+
const recorded = await recordGitHubPullRequestOutcome(args.db, outcome);
|
|
4025
|
+
if (!recorded.applied) return recorded;
|
|
4026
|
+
await args.codeChanges.record(
|
|
4027
|
+
githubCodeChange(outcome, recorded.conversationIds)
|
|
4028
|
+
);
|
|
4029
|
+
if (outcome.state !== "open") {
|
|
4030
|
+
await updateGitHubAnnotations({
|
|
4031
|
+
annotations: args.annotations,
|
|
4032
|
+
conversationIds: recorded.conversationIds,
|
|
4033
|
+
log: args.log,
|
|
4034
|
+
update: {
|
|
4035
|
+
repo: outcome.repositoryFullName,
|
|
4036
|
+
number: outcome.number,
|
|
4037
|
+
objectType: "code_change",
|
|
4038
|
+
status: outcome.state === "merged" ? "merged" : "closed"
|
|
4039
|
+
}
|
|
4040
|
+
});
|
|
4041
|
+
}
|
|
4042
|
+
return recorded;
|
|
4043
|
+
}
|
|
4044
|
+
|
|
3823
4045
|
// src/webhooks/issue-outcome.ts
|
|
3824
|
-
import * as
|
|
3825
|
-
var canonicalIssueOutcomeSchema =
|
|
3826
|
-
action:
|
|
3827
|
-
issue:
|
|
3828
|
-
body:
|
|
3829
|
-
closed_at:
|
|
3830
|
-
created_at:
|
|
3831
|
-
id:
|
|
3832
|
-
number:
|
|
4046
|
+
import * as z26 from "zod";
|
|
4047
|
+
var canonicalIssueOutcomeSchema = z26.object({
|
|
4048
|
+
action: z26.enum(["opened", "closed", "reopened"]),
|
|
4049
|
+
issue: z26.object({
|
|
4050
|
+
body: z26.string().nullable().optional(),
|
|
4051
|
+
closed_at: z26.string().nullable().optional(),
|
|
4052
|
+
created_at: z26.string(),
|
|
4053
|
+
id: z26.number().int().positive(),
|
|
4054
|
+
number: z26.number().int().positive(),
|
|
3833
4055
|
state_reason: githubIssueStateReasonSchema.nullable().optional(),
|
|
3834
|
-
updated_at:
|
|
3835
|
-
user:
|
|
4056
|
+
updated_at: z26.string(),
|
|
4057
|
+
user: z26.object({ login: z26.string().min(1) }).strict()
|
|
3836
4058
|
}).strict(),
|
|
3837
|
-
repository:
|
|
3838
|
-
full_name:
|
|
3839
|
-
id:
|
|
4059
|
+
repository: z26.object({
|
|
4060
|
+
full_name: z26.string().min(1),
|
|
4061
|
+
id: z26.number().int().positive()
|
|
3840
4062
|
}).strict()
|
|
3841
4063
|
}).strict();
|
|
3842
|
-
var issueOutcomeSchema =
|
|
3843
|
-
action:
|
|
3844
|
-
issue:
|
|
3845
|
-
body:
|
|
3846
|
-
closed_at:
|
|
3847
|
-
created_at:
|
|
3848
|
-
id:
|
|
3849
|
-
number:
|
|
4064
|
+
var issueOutcomeSchema = z26.object({
|
|
4065
|
+
action: z26.enum(["opened", "closed", "reopened"]),
|
|
4066
|
+
issue: z26.object({
|
|
4067
|
+
body: z26.string().nullable().optional(),
|
|
4068
|
+
closed_at: z26.string().nullable().optional(),
|
|
4069
|
+
created_at: z26.string(),
|
|
4070
|
+
id: z26.number().int().positive(),
|
|
4071
|
+
number: z26.number().int().positive(),
|
|
3850
4072
|
state_reason: githubIssueStateReasonSchema.nullable().optional(),
|
|
3851
|
-
updated_at:
|
|
3852
|
-
user:
|
|
4073
|
+
updated_at: z26.string(),
|
|
4074
|
+
user: z26.object({ login: z26.string().min(1) }).passthrough()
|
|
3853
4075
|
}).passthrough(),
|
|
3854
|
-
repository:
|
|
3855
|
-
full_name:
|
|
3856
|
-
id:
|
|
4076
|
+
repository: z26.object({
|
|
4077
|
+
full_name: z26.string().min(1),
|
|
4078
|
+
id: z26.number().int().positive()
|
|
3857
4079
|
}).passthrough()
|
|
3858
4080
|
}).passthrough().transform(
|
|
3859
4081
|
(provider) => canonicalIssueOutcomeSchema.parse({
|
|
@@ -3874,7 +4096,7 @@ var issueOutcomeSchema = z24.object({
|
|
|
3874
4096
|
}
|
|
3875
4097
|
})
|
|
3876
4098
|
);
|
|
3877
|
-
var issueLifecycleActionSchema =
|
|
4099
|
+
var issueLifecycleActionSchema = z26.object({ action: z26.string() }).passthrough();
|
|
3878
4100
|
function timestamp2(value) {
|
|
3879
4101
|
if (!value) return void 0;
|
|
3880
4102
|
const parsed = new Date(value);
|
|
@@ -3918,21 +4140,21 @@ function normalizeGitHubIssueOutcome(args) {
|
|
|
3918
4140
|
updatedAt
|
|
3919
4141
|
};
|
|
3920
4142
|
}
|
|
3921
|
-
var canonicalIssueConversationSchema =
|
|
3922
|
-
issue:
|
|
3923
|
-
body:
|
|
3924
|
-
id:
|
|
3925
|
-
user:
|
|
4143
|
+
var canonicalIssueConversationSchema = z26.object({
|
|
4144
|
+
issue: z26.object({
|
|
4145
|
+
body: z26.string().nullable().optional(),
|
|
4146
|
+
id: z26.number().int().positive(),
|
|
4147
|
+
user: z26.object({ login: z26.string().min(1) }).strict()
|
|
3926
4148
|
}).strict(),
|
|
3927
|
-
sender:
|
|
4149
|
+
sender: z26.object({ login: z26.string().min(1) }).strict().optional()
|
|
3928
4150
|
}).strict();
|
|
3929
|
-
var issueConversationSchema =
|
|
3930
|
-
issue:
|
|
3931
|
-
body:
|
|
3932
|
-
id:
|
|
3933
|
-
user:
|
|
4151
|
+
var issueConversationSchema = z26.object({
|
|
4152
|
+
issue: z26.object({
|
|
4153
|
+
body: z26.string().nullable().optional(),
|
|
4154
|
+
id: z26.number().int().positive(),
|
|
4155
|
+
user: z26.object({ login: z26.string().min(1) }).passthrough()
|
|
3934
4156
|
}).passthrough(),
|
|
3935
|
-
sender:
|
|
4157
|
+
sender: z26.object({ login: z26.string().min(1) }).passthrough().optional()
|
|
3936
4158
|
}).passthrough().transform(
|
|
3937
4159
|
(provider) => canonicalIssueConversationSchema.parse({
|
|
3938
4160
|
issue: {
|
|
@@ -3959,43 +4181,43 @@ function normalizeGitHubIssueConversations(args) {
|
|
|
3959
4181
|
}
|
|
3960
4182
|
|
|
3961
4183
|
// src/webhooks/pull-request-outcome.ts
|
|
3962
|
-
import * as
|
|
3963
|
-
var canonicalPullRequestOutcomeSchema =
|
|
3964
|
-
action:
|
|
3965
|
-
pull_request:
|
|
3966
|
-
body:
|
|
3967
|
-
closed_at:
|
|
3968
|
-
created_at:
|
|
3969
|
-
id:
|
|
3970
|
-
merged:
|
|
3971
|
-
merged_at:
|
|
3972
|
-
number:
|
|
3973
|
-
title:
|
|
3974
|
-
updated_at:
|
|
3975
|
-
user:
|
|
4184
|
+
import * as z27 from "zod";
|
|
4185
|
+
var canonicalPullRequestOutcomeSchema = z27.object({
|
|
4186
|
+
action: z27.enum(["opened", "closed", "reopened"]),
|
|
4187
|
+
pull_request: z27.object({
|
|
4188
|
+
body: z27.string().nullable().optional(),
|
|
4189
|
+
closed_at: z27.string().nullable().optional(),
|
|
4190
|
+
created_at: z27.string(),
|
|
4191
|
+
id: z27.number().int().positive(),
|
|
4192
|
+
merged: z27.boolean(),
|
|
4193
|
+
merged_at: z27.string().nullable().optional(),
|
|
4194
|
+
number: z27.number().int().positive(),
|
|
4195
|
+
title: z27.string().min(1).optional(),
|
|
4196
|
+
updated_at: z27.string(),
|
|
4197
|
+
user: z27.object({ login: z27.string().min(1) }).strict()
|
|
3976
4198
|
}).strict(),
|
|
3977
|
-
repository:
|
|
3978
|
-
full_name:
|
|
3979
|
-
id:
|
|
4199
|
+
repository: z27.object({
|
|
4200
|
+
full_name: z27.string().min(1),
|
|
4201
|
+
id: z27.number().int().positive()
|
|
3980
4202
|
}).strict()
|
|
3981
4203
|
}).strict();
|
|
3982
|
-
var pullRequestOutcomeSchema =
|
|
3983
|
-
action:
|
|
3984
|
-
pull_request:
|
|
3985
|
-
body:
|
|
3986
|
-
closed_at:
|
|
3987
|
-
created_at:
|
|
3988
|
-
id:
|
|
3989
|
-
merged:
|
|
3990
|
-
merged_at:
|
|
3991
|
-
number:
|
|
3992
|
-
title:
|
|
3993
|
-
updated_at:
|
|
3994
|
-
user:
|
|
4204
|
+
var pullRequestOutcomeSchema = z27.object({
|
|
4205
|
+
action: z27.enum(["opened", "closed", "reopened"]),
|
|
4206
|
+
pull_request: z27.object({
|
|
4207
|
+
body: z27.string().nullable().optional(),
|
|
4208
|
+
closed_at: z27.string().nullable().optional(),
|
|
4209
|
+
created_at: z27.string(),
|
|
4210
|
+
id: z27.number().int().positive(),
|
|
4211
|
+
merged: z27.boolean(),
|
|
4212
|
+
merged_at: z27.string().nullable().optional(),
|
|
4213
|
+
number: z27.number().int().positive(),
|
|
4214
|
+
title: z27.string().min(1).optional(),
|
|
4215
|
+
updated_at: z27.string(),
|
|
4216
|
+
user: z27.object({ login: z27.string().min(1) }).passthrough()
|
|
3995
4217
|
}).passthrough(),
|
|
3996
|
-
repository:
|
|
3997
|
-
full_name:
|
|
3998
|
-
id:
|
|
4218
|
+
repository: z27.object({
|
|
4219
|
+
full_name: z27.string().min(1),
|
|
4220
|
+
id: z27.number().int().positive()
|
|
3999
4221
|
}).passthrough()
|
|
4000
4222
|
}).passthrough().transform(
|
|
4001
4223
|
(provider) => canonicalPullRequestOutcomeSchema.parse({
|
|
@@ -4018,24 +4240,24 @@ var pullRequestOutcomeSchema = z25.object({
|
|
|
4018
4240
|
}
|
|
4019
4241
|
})
|
|
4020
4242
|
);
|
|
4021
|
-
var pullRequestLifecycleActionSchema =
|
|
4022
|
-
var canonicalPullRequestConversationSchema =
|
|
4023
|
-
pull_request:
|
|
4024
|
-
body:
|
|
4025
|
-
id:
|
|
4026
|
-
user:
|
|
4243
|
+
var pullRequestLifecycleActionSchema = z27.object({ action: z27.string() }).passthrough();
|
|
4244
|
+
var canonicalPullRequestConversationSchema = z27.object({
|
|
4245
|
+
pull_request: z27.object({
|
|
4246
|
+
body: z27.string().nullable().optional(),
|
|
4247
|
+
id: z27.number().int().positive(),
|
|
4248
|
+
user: z27.object({ login: z27.string().min(1) }).strict()
|
|
4027
4249
|
}).strict(),
|
|
4028
|
-
repository:
|
|
4029
|
-
sender:
|
|
4250
|
+
repository: z27.object({ full_name: z27.string().min(1) }).strict(),
|
|
4251
|
+
sender: z27.object({ login: z27.string().min(1) }).strict()
|
|
4030
4252
|
}).strict();
|
|
4031
|
-
var pullRequestConversationSchema =
|
|
4032
|
-
pull_request:
|
|
4033
|
-
body:
|
|
4034
|
-
id:
|
|
4035
|
-
user:
|
|
4253
|
+
var pullRequestConversationSchema = z27.object({
|
|
4254
|
+
pull_request: z27.object({
|
|
4255
|
+
body: z27.string().nullable().optional(),
|
|
4256
|
+
id: z27.number().int().positive(),
|
|
4257
|
+
user: z27.object({ login: z27.string().min(1) }).passthrough()
|
|
4036
4258
|
}).passthrough(),
|
|
4037
|
-
repository:
|
|
4038
|
-
sender:
|
|
4259
|
+
repository: z27.object({ full_name: z27.string().min(1) }).passthrough(),
|
|
4260
|
+
sender: z27.object({ login: z27.string().min(1) }).passthrough()
|
|
4039
4261
|
}).passthrough().transform(
|
|
4040
4262
|
(provider) => canonicalPullRequestConversationSchema.parse({
|
|
4041
4263
|
pull_request: {
|
|
@@ -4074,11 +4296,9 @@ function normalizeGitHubPullRequestOutcome(args) {
|
|
|
4074
4296
|
);
|
|
4075
4297
|
const candidateOwned = hasOwnershipMarker && (parsed.action === "opened" || parsed.action === "closed");
|
|
4076
4298
|
const state = parsed.action !== "closed" ? "open" : pullRequest.merged ? "merged" : "closed_unmerged";
|
|
4077
|
-
const
|
|
4078
|
-
const
|
|
4079
|
-
|
|
4080
|
-
throw new Error("GitHub pull request terminal timestamp is invalid");
|
|
4081
|
-
}
|
|
4299
|
+
const closed = parsed.action === "closed";
|
|
4300
|
+
const closedAt = timestamp3(pullRequest.closed_at) ?? (closed ? updatedAt : void 0);
|
|
4301
|
+
const mergedAt = timestamp3(pullRequest.merged_at) ?? (closed && pullRequest.merged ? updatedAt : void 0);
|
|
4082
4302
|
return {
|
|
4083
4303
|
candidateOwned,
|
|
4084
4304
|
closedAt,
|
|
@@ -4121,21 +4341,88 @@ function normalizeGitHubPullRequestLinkedIssues(args) {
|
|
|
4121
4341
|
} : void 0;
|
|
4122
4342
|
}
|
|
4123
4343
|
|
|
4344
|
+
// src/webhooks/pull-request-activity.ts
|
|
4345
|
+
import * as z28 from "zod";
|
|
4346
|
+
var timestampSchema = z28.iso.datetime({ offset: true });
|
|
4347
|
+
var numberSchema = z28.number().int().positive();
|
|
4348
|
+
var repositorySchema2 = z28.object({ id: numberSchema });
|
|
4349
|
+
var senderSchema = z28.object({ type: z28.string() });
|
|
4350
|
+
var activitySchemas = {
|
|
4351
|
+
issue_comment: z28.object({
|
|
4352
|
+
action: z28.literal("created"),
|
|
4353
|
+
comment: z28.object({ created_at: timestampSchema }),
|
|
4354
|
+
// Only comments on a pull request carry `issue.pull_request`.
|
|
4355
|
+
issue: z28.object({ number: numberSchema, pull_request: z28.object({}) }),
|
|
4356
|
+
repository: repositorySchema2,
|
|
4357
|
+
sender: senderSchema
|
|
4358
|
+
}).transform((event) => ({
|
|
4359
|
+
at: new Date(event.comment.created_at),
|
|
4360
|
+
number: event.issue.number,
|
|
4361
|
+
repositoryProviderId: String(event.repository.id),
|
|
4362
|
+
senderType: event.sender.type
|
|
4363
|
+
})),
|
|
4364
|
+
pull_request: z28.object({
|
|
4365
|
+
action: z28.literal("synchronize"),
|
|
4366
|
+
pull_request: z28.object({
|
|
4367
|
+
number: numberSchema,
|
|
4368
|
+
updated_at: timestampSchema
|
|
4369
|
+
}),
|
|
4370
|
+
repository: repositorySchema2,
|
|
4371
|
+
sender: senderSchema
|
|
4372
|
+
}).transform((event) => ({
|
|
4373
|
+
at: new Date(event.pull_request.updated_at),
|
|
4374
|
+
number: event.pull_request.number,
|
|
4375
|
+
repositoryProviderId: String(event.repository.id),
|
|
4376
|
+
senderType: event.sender.type
|
|
4377
|
+
})),
|
|
4378
|
+
pull_request_review: z28.object({
|
|
4379
|
+
action: z28.literal("submitted"),
|
|
4380
|
+
pull_request: z28.object({ number: numberSchema }),
|
|
4381
|
+
repository: repositorySchema2,
|
|
4382
|
+
review: z28.object({ submitted_at: timestampSchema }),
|
|
4383
|
+
sender: senderSchema
|
|
4384
|
+
}).transform((event) => ({
|
|
4385
|
+
at: new Date(event.review.submitted_at),
|
|
4386
|
+
number: event.pull_request.number,
|
|
4387
|
+
repositoryProviderId: String(event.repository.id),
|
|
4388
|
+
senderType: event.sender.type
|
|
4389
|
+
})),
|
|
4390
|
+
pull_request_review_comment: z28.object({
|
|
4391
|
+
action: z28.literal("created"),
|
|
4392
|
+
comment: z28.object({ created_at: timestampSchema }),
|
|
4393
|
+
pull_request: z28.object({ number: numberSchema }),
|
|
4394
|
+
repository: repositorySchema2,
|
|
4395
|
+
sender: senderSchema
|
|
4396
|
+
}).transform((event) => ({
|
|
4397
|
+
at: new Date(event.comment.created_at),
|
|
4398
|
+
number: event.pull_request.number,
|
|
4399
|
+
repositoryProviderId: String(event.repository.id),
|
|
4400
|
+
senderType: event.sender.type
|
|
4401
|
+
}))
|
|
4402
|
+
};
|
|
4403
|
+
function normalizeGitHubPullRequestActivity(input) {
|
|
4404
|
+
const schema = Object.hasOwn(activitySchemas, input.eventName) ? activitySchemas[input.eventName] : void 0;
|
|
4405
|
+
const parsed = schema?.safeParse(input.body);
|
|
4406
|
+
if (!parsed?.success) return void 0;
|
|
4407
|
+
const { senderType, ...activity } = parsed.data;
|
|
4408
|
+
return senderType === "Bot" ? void 0 : activity;
|
|
4409
|
+
}
|
|
4410
|
+
|
|
4124
4411
|
// src/webhooks/merge-conflict.ts
|
|
4125
|
-
import * as
|
|
4412
|
+
import * as z29 from "zod";
|
|
4126
4413
|
var EVENT_TYPE = "pull_request.merge_conflict";
|
|
4127
4414
|
var CLOSED_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
4128
4415
|
"pull_request.closed_unmerged",
|
|
4129
4416
|
"pull_request.merged"
|
|
4130
4417
|
]);
|
|
4131
|
-
var pullRequestSchema3 =
|
|
4132
|
-
base:
|
|
4133
|
-
number:
|
|
4134
|
-
head:
|
|
4135
|
-
html_url:
|
|
4136
|
-
mergeable:
|
|
4137
|
-
mergeable_state:
|
|
4138
|
-
state:
|
|
4418
|
+
var pullRequestSchema3 = z29.object({
|
|
4419
|
+
base: z29.object({ ref: z29.string().min(1) }),
|
|
4420
|
+
number: z29.number().int().positive().optional(),
|
|
4421
|
+
head: z29.object({ sha: z29.string().min(1) }),
|
|
4422
|
+
html_url: z29.string().min(1).optional(),
|
|
4423
|
+
mergeable: z29.boolean().nullable().optional(),
|
|
4424
|
+
mergeable_state: z29.string().optional(),
|
|
4425
|
+
state: z29.string()
|
|
4139
4426
|
});
|
|
4140
4427
|
function gitHubMergeConflictEvents(input) {
|
|
4141
4428
|
const { conflict } = input;
|
|
@@ -4169,7 +4456,7 @@ function pullRequestRefs(events) {
|
|
|
4169
4456
|
return [...refs.values()];
|
|
4170
4457
|
}
|
|
4171
4458
|
function deliveredPullRequest(payload, ref) {
|
|
4172
|
-
const parsed =
|
|
4459
|
+
const parsed = z29.object({ pull_request: pullRequestSchema3 }).safeParse(payload);
|
|
4173
4460
|
const pullRequest = parsed.success ? parsed.data.pull_request : void 0;
|
|
4174
4461
|
return pullRequest?.number === ref.number && typeof pullRequest.mergeable === "boolean" ? pullRequest : void 0;
|
|
4175
4462
|
}
|
|
@@ -4207,16 +4494,16 @@ async function loadGitHubMergeConflictEvents(args) {
|
|
|
4207
4494
|
}
|
|
4208
4495
|
|
|
4209
4496
|
// src/merge-conflict-checks/webhooks.ts
|
|
4210
|
-
import * as
|
|
4497
|
+
import * as z31 from "zod";
|
|
4211
4498
|
|
|
4212
4499
|
// src/merge-conflict-checks/store.ts
|
|
4213
4500
|
import { and as and4, eq as eq4 } from "drizzle-orm";
|
|
4214
|
-
import * as
|
|
4501
|
+
import * as z30 from "zod";
|
|
4215
4502
|
var CHECK_TTL_MS = 30 * 6e4;
|
|
4216
|
-
var repeatSchema =
|
|
4503
|
+
var repeatSchema = z30.object({
|
|
4217
4504
|
/** Checks since the last push that ended with an unknown answer. */
|
|
4218
|
-
attempts:
|
|
4219
|
-
dueAtMs:
|
|
4505
|
+
attempts: z30.number().int().positive(),
|
|
4506
|
+
dueAtMs: z30.number()
|
|
4220
4507
|
});
|
|
4221
4508
|
function pushKey(repositoryFullName) {
|
|
4222
4509
|
return `merge-conflict-check:push:${repositoryFullName}`;
|
|
@@ -4284,12 +4571,12 @@ async function settleGitHubConflictCheck(state, check, retryAtMs) {
|
|
|
4284
4571
|
|
|
4285
4572
|
// src/merge-conflict-checks/webhooks.ts
|
|
4286
4573
|
var CONFLICT_CHECK_DELAY_MS = 2 * 6e4;
|
|
4287
|
-
var pushSchema =
|
|
4288
|
-
deleted:
|
|
4289
|
-
ref:
|
|
4290
|
-
repository:
|
|
4291
|
-
default_branch:
|
|
4292
|
-
full_name:
|
|
4574
|
+
var pushSchema = z31.object({
|
|
4575
|
+
deleted: z31.boolean().optional(),
|
|
4576
|
+
ref: z31.string(),
|
|
4577
|
+
repository: z31.object({
|
|
4578
|
+
default_branch: z31.string().min(1),
|
|
4579
|
+
full_name: z31.string().min(1)
|
|
4293
4580
|
})
|
|
4294
4581
|
});
|
|
4295
4582
|
async function scheduleGitHubPushConflictCheck(args) {
|
|
@@ -4306,10 +4593,10 @@ async function scheduleGitHubPushConflictCheck(args) {
|
|
|
4306
4593
|
}
|
|
4307
4594
|
|
|
4308
4595
|
// src/webhooks/pull-request-ready.ts
|
|
4309
|
-
import * as
|
|
4596
|
+
import * as z33 from "zod";
|
|
4310
4597
|
|
|
4311
4598
|
// src/webhooks/installation-requests.ts
|
|
4312
|
-
import * as
|
|
4599
|
+
import * as z32 from "zod";
|
|
4313
4600
|
function splitRepository(fullName, label) {
|
|
4314
4601
|
const [owner, name, ...extra] = fullName.split("/");
|
|
4315
4602
|
if (!owner || !name || extra.length > 0) {
|
|
@@ -4349,6 +4636,35 @@ async function loadPullRequest(env, pullRequest) {
|
|
|
4349
4636
|
{ token: token.token }
|
|
4350
4637
|
);
|
|
4351
4638
|
}
|
|
4639
|
+
async function loadPullRequestLifecycles(env, input) {
|
|
4640
|
+
const { owner, name } = splitRepository(
|
|
4641
|
+
input.repositoryFullName,
|
|
4642
|
+
"pull request lifecycle"
|
|
4643
|
+
);
|
|
4644
|
+
const token = await issueInstallationToken({
|
|
4645
|
+
...env,
|
|
4646
|
+
permissions: { pull_requests: "read" },
|
|
4647
|
+
repositories: [name]
|
|
4648
|
+
});
|
|
4649
|
+
const variables = input.numbers.map((_, index2) => `$n${index2}: Int!`);
|
|
4650
|
+
const pullRequests = input.numbers.map(
|
|
4651
|
+
(_, index2) => `pr${index2}: pullRequest(number: $n${index2}) { ...lifecycle }`
|
|
4652
|
+
);
|
|
4653
|
+
return await githubRequest("https://api.github.com", "/graphql", {
|
|
4654
|
+
body: {
|
|
4655
|
+
query: `query($owner: String!, $name: String!, ${variables.join(", ")}) { repository(owner: $owner, name: $name) { databaseId nameWithOwner ${pullRequests.join(" ")} } } fragment lifecycle on PullRequest { assignees(first: 20) { nodes { login } } author { __typename login } closedAt createdAt databaseId headRefName isDraft merged mergedAt number state title updatedAt }`,
|
|
4656
|
+
variables: {
|
|
4657
|
+
name,
|
|
4658
|
+
owner,
|
|
4659
|
+
...Object.fromEntries(
|
|
4660
|
+
input.numbers.map((number31, index2) => [`n${index2}`, number31])
|
|
4661
|
+
)
|
|
4662
|
+
}
|
|
4663
|
+
},
|
|
4664
|
+
method: "POST",
|
|
4665
|
+
token: token.token
|
|
4666
|
+
});
|
|
4667
|
+
}
|
|
4352
4668
|
async function searchOpenPullRequestMergeability(env, input) {
|
|
4353
4669
|
const { name } = splitRepository(
|
|
4354
4670
|
input.repositoryFullName,
|
|
@@ -4379,7 +4695,7 @@ async function markPullRequestFeedbackReviewing(env, target) {
|
|
|
4379
4695
|
});
|
|
4380
4696
|
const content = pullRequestFeedbackReactionContent("reviewing");
|
|
4381
4697
|
if (target.commentKind === "review_body") {
|
|
4382
|
-
const review =
|
|
4698
|
+
const review = z32.object({ node_id: z32.string().min(1) }).parse(
|
|
4383
4699
|
await githubRequest(
|
|
4384
4700
|
"https://api.github.com",
|
|
4385
4701
|
pullRequestReviewPath({
|
|
@@ -4391,7 +4707,7 @@ async function markPullRequestFeedbackReviewing(env, target) {
|
|
|
4391
4707
|
{ token: token.token }
|
|
4392
4708
|
)
|
|
4393
4709
|
);
|
|
4394
|
-
const result =
|
|
4710
|
+
const result = z32.object({ errors: z32.array(z32.unknown()).optional() }).parse(
|
|
4395
4711
|
await githubRequest("https://api.github.com", "/graphql", {
|
|
4396
4712
|
body: {
|
|
4397
4713
|
operationName: "AddReviewReaction",
|
|
@@ -4427,9 +4743,9 @@ async function markPullRequestFeedbackReviewing(env, target) {
|
|
|
4427
4743
|
}
|
|
4428
4744
|
);
|
|
4429
4745
|
}
|
|
4430
|
-
var repositoryPermissionSchema =
|
|
4431
|
-
permission:
|
|
4432
|
-
role_name:
|
|
4746
|
+
var repositoryPermissionSchema = z32.object({
|
|
4747
|
+
permission: z32.string().min(1),
|
|
4748
|
+
role_name: z32.string().optional()
|
|
4433
4749
|
});
|
|
4434
4750
|
var REPOSITORY_ROLE_TTL_MS = 10 * 60 * 1e3;
|
|
4435
4751
|
async function loadRepositoryRole(env, cache, target) {
|
|
@@ -4459,19 +4775,19 @@ async function loadRepositoryRole(env, cache, target) {
|
|
|
4459
4775
|
}
|
|
4460
4776
|
);
|
|
4461
4777
|
}
|
|
4462
|
-
var pullRequestSchema4 =
|
|
4463
|
-
auto_merge:
|
|
4464
|
-
draft:
|
|
4465
|
-
html_url:
|
|
4466
|
-
mergeable_state:
|
|
4467
|
-
merged:
|
|
4468
|
-
state:
|
|
4469
|
-
title:
|
|
4778
|
+
var pullRequestSchema4 = z32.object({
|
|
4779
|
+
auto_merge: z32.object({}).nullable().optional(),
|
|
4780
|
+
draft: z32.boolean().optional(),
|
|
4781
|
+
html_url: z32.string().url(),
|
|
4782
|
+
mergeable_state: z32.string().nullable().optional(),
|
|
4783
|
+
merged: z32.boolean(),
|
|
4784
|
+
state: z32.enum(["open", "closed"]),
|
|
4785
|
+
title: z32.string()
|
|
4470
4786
|
});
|
|
4471
|
-
var reviewsSchema =
|
|
4472
|
-
|
|
4473
|
-
state:
|
|
4474
|
-
user:
|
|
4787
|
+
var reviewsSchema = z32.array(
|
|
4788
|
+
z32.object({
|
|
4789
|
+
state: z32.string(),
|
|
4790
|
+
user: z32.object({ login: z32.string() }).nullable()
|
|
4475
4791
|
})
|
|
4476
4792
|
);
|
|
4477
4793
|
async function loadPullRequestMergeState(env, pullRequest) {
|
|
@@ -4539,10 +4855,10 @@ var READY_ACTIONS = {
|
|
|
4539
4855
|
]),
|
|
4540
4856
|
pull_request_review: /* @__PURE__ */ new Set(["dismissed", "submitted"])
|
|
4541
4857
|
};
|
|
4542
|
-
var pullRequestWebhookSchema =
|
|
4543
|
-
action:
|
|
4544
|
-
pull_request:
|
|
4545
|
-
repository:
|
|
4858
|
+
var pullRequestWebhookSchema = z33.object({
|
|
4859
|
+
action: z33.string(),
|
|
4860
|
+
pull_request: z33.object({ number: z33.number().int().positive() }),
|
|
4861
|
+
repository: z33.object({ full_name: z33.string().min(1) })
|
|
4546
4862
|
});
|
|
4547
4863
|
function pullRequestReadyTargets(eventName, body) {
|
|
4548
4864
|
if (eventName === "check_suite") return checkSuitePullRequests(body);
|
|
@@ -4641,32 +4957,32 @@ async function syncGitHubPullRequestReadyNotices(args) {
|
|
|
4641
4957
|
}
|
|
4642
4958
|
|
|
4643
4959
|
// src/webhooks/pull-request-review-request.ts
|
|
4644
|
-
import * as
|
|
4645
|
-
var login =
|
|
4646
|
-
var pullRequestEventSchema =
|
|
4647
|
-
action:
|
|
4960
|
+
import * as z34 from "zod";
|
|
4961
|
+
var login = z34.object({ login: z34.string().min(1) });
|
|
4962
|
+
var pullRequestEventSchema = z34.object({
|
|
4963
|
+
action: z34.enum([
|
|
4648
4964
|
"closed",
|
|
4649
4965
|
"reopened",
|
|
4650
4966
|
"review_request_removed",
|
|
4651
4967
|
"review_requested"
|
|
4652
4968
|
]),
|
|
4653
|
-
pull_request:
|
|
4654
|
-
html_url:
|
|
4655
|
-
merged:
|
|
4656
|
-
number:
|
|
4969
|
+
pull_request: z34.object({
|
|
4970
|
+
html_url: z34.string().url(),
|
|
4971
|
+
merged: z34.boolean().optional(),
|
|
4972
|
+
number: z34.number().int().positive(),
|
|
4657
4973
|
// The people whose review is still requested. Teams are listed apart.
|
|
4658
|
-
requested_reviewers:
|
|
4659
|
-
title:
|
|
4974
|
+
requested_reviewers: z34.array(login).optional(),
|
|
4975
|
+
title: z34.string()
|
|
4660
4976
|
}),
|
|
4661
|
-
repository:
|
|
4977
|
+
repository: z34.object({ full_name: z34.string().min(1) }),
|
|
4662
4978
|
// A team request has `requested_team` instead.
|
|
4663
4979
|
requested_reviewer: login.optional()
|
|
4664
4980
|
});
|
|
4665
|
-
var reviewEventSchema =
|
|
4666
|
-
action:
|
|
4667
|
-
pull_request:
|
|
4668
|
-
repository:
|
|
4669
|
-
review:
|
|
4981
|
+
var reviewEventSchema = z34.object({
|
|
4982
|
+
action: z34.literal("submitted"),
|
|
4983
|
+
pull_request: z34.object({ number: z34.number().int().positive() }),
|
|
4984
|
+
repository: z34.object({ full_name: z34.string().min(1) }),
|
|
4985
|
+
review: z34.object({ user: login })
|
|
4670
4986
|
});
|
|
4671
4987
|
function reviewRequestChange(eventName, body) {
|
|
4672
4988
|
if (eventName === "pull_request_review") {
|
|
@@ -4747,14 +5063,14 @@ function sameLogin(left, right) {
|
|
|
4747
5063
|
async function syncGitHubPullRequestReviewRequest(args) {
|
|
4748
5064
|
const parsed = reviewRequestChange(args.eventName, args.body);
|
|
4749
5065
|
if (!parsed) return;
|
|
4750
|
-
const { change, number:
|
|
5066
|
+
const { change, number: number31, repository: repository2 } = parsed;
|
|
4751
5067
|
try {
|
|
4752
5068
|
const opener = (await listGitHubPullRequestOpeners(args.db, {
|
|
4753
|
-
numbers: [
|
|
5069
|
+
numbers: [number31],
|
|
4754
5070
|
repositoryFullName: repository2
|
|
4755
|
-
})).get(
|
|
5071
|
+
})).get(number31);
|
|
4756
5072
|
if (!opener?.conversationId) return;
|
|
4757
|
-
const name = `${repository2}#${
|
|
5073
|
+
const name = `${repository2}#${number31}`;
|
|
4758
5074
|
const dedupeKey = `pull-request-review-requested:${name.toLowerCase()}`;
|
|
4759
5075
|
const items = args.reviewItems.forConversation(opener.conversationId);
|
|
4760
5076
|
const reviewers = change.kind === "requested" ? change.reviewers : change.reviewer === void 0 ? void 0 : [change.reviewer];
|
|
@@ -4777,21 +5093,21 @@ async function syncGitHubPullRequestReviewRequest(args) {
|
|
|
4777
5093
|
body: `GitHub asks you to review **${change.title}**: ${change.url}`,
|
|
4778
5094
|
dedupeKey,
|
|
4779
5095
|
subject: { id: change.url, title: name, url: change.url },
|
|
4780
|
-
title: `Review requested \xB7 #${
|
|
5096
|
+
title: `Review requested \xB7 #${number31}`,
|
|
4781
5097
|
waitsOnAssignees: true
|
|
4782
5098
|
});
|
|
4783
5099
|
} catch (error) {
|
|
4784
5100
|
args.log?.error("GitHub pull request review request failed", {
|
|
4785
5101
|
deliveryId: args.deliveryId,
|
|
4786
5102
|
errorType: error instanceof Error ? error.name : "UnknownError",
|
|
4787
|
-
number:
|
|
5103
|
+
number: number31,
|
|
4788
5104
|
repository: repository2
|
|
4789
5105
|
});
|
|
4790
5106
|
}
|
|
4791
5107
|
}
|
|
4792
5108
|
|
|
4793
5109
|
// src/webhooks/pull-request-match-data.ts
|
|
4794
|
-
import * as
|
|
5110
|
+
import * as z35 from "zod";
|
|
4795
5111
|
var LOOKUPS_BY_MATCH_KEY = {
|
|
4796
5112
|
authors: ["authors"],
|
|
4797
5113
|
openerEmail: ["opener"],
|
|
@@ -4799,22 +5115,22 @@ var LOOKUPS_BY_MATCH_KEY = {
|
|
|
4799
5115
|
openerUsername: ["opener"]
|
|
4800
5116
|
};
|
|
4801
5117
|
var ALL_LOOKUPS = ["authors", "opener", "openerRole"];
|
|
4802
|
-
var lookupDataSchema =
|
|
4803
|
-
authors:
|
|
4804
|
-
openerRole:
|
|
4805
|
-
openerUsername:
|
|
5118
|
+
var lookupDataSchema = z35.object({
|
|
5119
|
+
authors: z35.array(z35.string().min(1)).min(1).optional(),
|
|
5120
|
+
openerRole: z35.string().min(1).optional(),
|
|
5121
|
+
openerUsername: z35.string().min(1).optional()
|
|
4806
5122
|
}).strict();
|
|
4807
5123
|
function lookupData(input) {
|
|
4808
5124
|
return lookupDataSchema.parse(definedValues(input));
|
|
4809
5125
|
}
|
|
4810
|
-
var webhookSchema =
|
|
4811
|
-
repository:
|
|
5126
|
+
var webhookSchema = z35.object({
|
|
5127
|
+
repository: z35.object({ full_name: z35.string().min(1) })
|
|
4812
5128
|
});
|
|
4813
5129
|
function pullRequestNumbers(events) {
|
|
4814
5130
|
const numbers = /* @__PURE__ */ new Map();
|
|
4815
5131
|
for (const event of events) {
|
|
4816
|
-
const
|
|
4817
|
-
if (typeof
|
|
5132
|
+
const number31 = event.data?.pullRequest;
|
|
5133
|
+
if (typeof number31 === "number") numbers.set(event.eventKey, number31);
|
|
4818
5134
|
}
|
|
4819
5135
|
return numbers;
|
|
4820
5136
|
}
|
|
@@ -4828,8 +5144,8 @@ function logFailure(context, lookup, error) {
|
|
|
4828
5144
|
}
|
|
4829
5145
|
async function withJuniorOpeners(context, events) {
|
|
4830
5146
|
const botNumber = (event) => {
|
|
4831
|
-
const
|
|
4832
|
-
return
|
|
5147
|
+
const number31 = context.numbers.get(event.eventKey);
|
|
5148
|
+
return number31 !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number31 : void 0;
|
|
4833
5149
|
};
|
|
4834
5150
|
const numbers = events.flatMap((event) => botNumber(event) ?? []);
|
|
4835
5151
|
if (numbers.length === 0) return events;
|
|
@@ -4848,9 +5164,9 @@ async function withJuniorOpeners(context, events) {
|
|
|
4848
5164
|
}
|
|
4849
5165
|
}
|
|
4850
5166
|
return events.map((event) => {
|
|
4851
|
-
const
|
|
4852
|
-
if (
|
|
4853
|
-
const identityId = openers.get(
|
|
5167
|
+
const number31 = botNumber(event);
|
|
5168
|
+
if (number31 === void 0) return event;
|
|
5169
|
+
const identityId = openers.get(number31)?.identityId;
|
|
4854
5170
|
const login2 = identityId ? logins.get(identityId) : void 0;
|
|
4855
5171
|
const {
|
|
4856
5172
|
openerEmail: _email,
|
|
@@ -4872,8 +5188,8 @@ async function withRolesAndAuthors(context, events, lookups) {
|
|
|
4872
5188
|
if (!loadRole && !loadAuthors) return events;
|
|
4873
5189
|
return await Promise.all(
|
|
4874
5190
|
events.map(async (event) => {
|
|
4875
|
-
const
|
|
4876
|
-
if (
|
|
5191
|
+
const number31 = context.numbers.get(event.eventKey);
|
|
5192
|
+
if (number31 === void 0) return event;
|
|
4877
5193
|
const login2 = event.data?.openerUsername;
|
|
4878
5194
|
if (loadRole && typeof login2 === "string" && !roles.has(login2)) {
|
|
4879
5195
|
roles.set(
|
|
@@ -4883,16 +5199,16 @@ async function withRolesAndAuthors(context, events, lookups) {
|
|
|
4883
5199
|
)
|
|
4884
5200
|
);
|
|
4885
5201
|
}
|
|
4886
|
-
if (loadAuthors && !authors.has(
|
|
5202
|
+
if (loadAuthors && !authors.has(number31)) {
|
|
4887
5203
|
authors.set(
|
|
4888
|
-
|
|
4889
|
-
loadAuthors({ number:
|
|
5204
|
+
number31,
|
|
5205
|
+
loadAuthors({ number: number31, repositoryFullName }).catch(
|
|
4890
5206
|
(error) => logFailure(context, "authors", error)
|
|
4891
5207
|
)
|
|
4892
5208
|
);
|
|
4893
5209
|
}
|
|
4894
5210
|
const role = loadRole && typeof login2 === "string" ? await roles.get(login2) : void 0;
|
|
4895
|
-
const logins = loadAuthors ? await authors.get(
|
|
5211
|
+
const logins = loadAuthors ? await authors.get(number31) : void 0;
|
|
4896
5212
|
if (!role && !logins?.length) return event;
|
|
4897
5213
|
return {
|
|
4898
5214
|
...event,
|
|
@@ -4949,7 +5265,7 @@ async function withGitHubPullRequestMatchData(args) {
|
|
|
4949
5265
|
}
|
|
4950
5266
|
|
|
4951
5267
|
// src/webhooks/pull-request-people.ts
|
|
4952
|
-
import * as
|
|
5268
|
+
import * as z36 from "zod";
|
|
4953
5269
|
var PEOPLE_EVENTS = /* @__PURE__ */ new Set([
|
|
4954
5270
|
"pull_request.review.approved",
|
|
4955
5271
|
"pull_request.merged"
|
|
@@ -4959,18 +5275,18 @@ var PAGE_SIZE = 100;
|
|
|
4959
5275
|
var MAX_PAGES = 3;
|
|
4960
5276
|
var CO_AUTHOR_TRAILER = /^co-authored-by:[^<\n]*<([^>\s]+@[^>\s]+)>\s*$/gim;
|
|
4961
5277
|
var GITHUB_NOREPLY_EMAIL = /^(?:\d+\+)?(?<login>[^@+]+)@users\.noreply\.github\.com$/i;
|
|
4962
|
-
var webhookSchema2 =
|
|
4963
|
-
pull_request:
|
|
4964
|
-
assignees:
|
|
4965
|
-
number:
|
|
4966
|
-
user:
|
|
5278
|
+
var webhookSchema2 = z36.object({
|
|
5279
|
+
pull_request: z36.object({
|
|
5280
|
+
assignees: z36.array(z36.object({ login: z36.string().min(1) })).nullish(),
|
|
5281
|
+
number: z36.number(),
|
|
5282
|
+
user: z36.object({ login: z36.string().min(1) }).nullish()
|
|
4967
5283
|
}),
|
|
4968
|
-
repository:
|
|
5284
|
+
repository: z36.object({ full_name: z36.string().min(1) })
|
|
4969
5285
|
});
|
|
4970
|
-
var commitPageSchema =
|
|
4971
|
-
|
|
4972
|
-
author:
|
|
4973
|
-
commit:
|
|
5286
|
+
var commitPageSchema = z36.array(
|
|
5287
|
+
z36.object({
|
|
5288
|
+
author: z36.object({ login: z36.string().min(1) }).nullish(),
|
|
5289
|
+
commit: z36.object({ message: z36.string() })
|
|
4974
5290
|
})
|
|
4975
5291
|
);
|
|
4976
5292
|
function shareCommitPages(load) {
|
|
@@ -5112,11 +5428,11 @@ function webhookInstallationId(body) {
|
|
|
5112
5428
|
}
|
|
5113
5429
|
return parseInstallationId(installation.id);
|
|
5114
5430
|
}
|
|
5115
|
-
var feedbackTargetSchema =
|
|
5116
|
-
commentId:
|
|
5117
|
-
commentKind:
|
|
5118
|
-
pullRequest:
|
|
5119
|
-
repo:
|
|
5431
|
+
var feedbackTargetSchema = z37.object({
|
|
5432
|
+
commentId: z37.number(),
|
|
5433
|
+
commentKind: z37.enum(["conversation", "review", "review_body"]),
|
|
5434
|
+
pullRequest: z37.number(),
|
|
5435
|
+
repo: z37.string().min(1)
|
|
5120
5436
|
});
|
|
5121
5437
|
function pullRequestFeedbackTarget(events) {
|
|
5122
5438
|
for (const event of events) {
|
|
@@ -5126,25 +5442,6 @@ function pullRequestFeedbackTarget(events) {
|
|
|
5126
5442
|
}
|
|
5127
5443
|
return void 0;
|
|
5128
5444
|
}
|
|
5129
|
-
function githubCodeChange(outcome, conversationIds) {
|
|
5130
|
-
return {
|
|
5131
|
-
closedAt: outcome.closedAt,
|
|
5132
|
-
conversationIds,
|
|
5133
|
-
mergedAt: outcome.mergedAt,
|
|
5134
|
-
number: outcome.number,
|
|
5135
|
-
openedAt: outcome.openedAt,
|
|
5136
|
-
providerId: outcome.pullRequestId,
|
|
5137
|
-
repository: {
|
|
5138
|
-
name: outcome.repositoryFullName,
|
|
5139
|
-
providerId: outcome.repositoryId,
|
|
5140
|
-
url: `https://github.com/${outcome.repositoryFullName}`
|
|
5141
|
-
},
|
|
5142
|
-
state: outcome.state === "closed_unmerged" ? "closed" : outcome.state,
|
|
5143
|
-
title: outcome.title,
|
|
5144
|
-
updatedAt: outcome.updatedAt,
|
|
5145
|
-
url: `https://github.com/${outcome.repositoryFullName}/pull/${outcome.number}`
|
|
5146
|
-
};
|
|
5147
|
-
}
|
|
5148
5445
|
function createGitHubWebhookRoute(args) {
|
|
5149
5446
|
return {
|
|
5150
5447
|
method: "POST",
|
|
@@ -5188,34 +5485,13 @@ function createGitHubWebhookRoute(args) {
|
|
|
5188
5485
|
const pullRequestConversations = eventName === "pull_request" ? normalizeGitHubPullRequestConversations({ body, botEmail }) : void 0;
|
|
5189
5486
|
const pullRequestLinkedIssues = eventName === "pull_request" ? normalizeGitHubPullRequestLinkedIssues({ body, botEmail }) : void 0;
|
|
5190
5487
|
if (pullRequestOutcome) {
|
|
5191
|
-
const recordedOutcome = await
|
|
5192
|
-
args.
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
pullRequestOutcome,
|
|
5199
|
-
recordedOutcome.conversationIds
|
|
5200
|
-
)
|
|
5201
|
-
);
|
|
5202
|
-
}
|
|
5203
|
-
if (recordedOutcome.applied && pullRequestOutcome.state !== "open") {
|
|
5204
|
-
const status = pullRequestOutcome.state === "merged" ? "merged" : "closed";
|
|
5205
|
-
await Promise.all(
|
|
5206
|
-
recordedOutcome.conversationIds.map(
|
|
5207
|
-
(conversationId) => updateGitHubAnnotation(
|
|
5208
|
-
args.annotations.forConversation(conversationId),
|
|
5209
|
-
{
|
|
5210
|
-
repo: pullRequestOutcome.repositoryFullName,
|
|
5211
|
-
number: pullRequestOutcome.number,
|
|
5212
|
-
objectType: "code_change",
|
|
5213
|
-
status
|
|
5214
|
-
}
|
|
5215
|
-
)
|
|
5216
|
-
)
|
|
5217
|
-
);
|
|
5218
|
-
}
|
|
5488
|
+
const recordedOutcome = await applyGitHubPullRequestOutcome({
|
|
5489
|
+
annotations: args.annotations,
|
|
5490
|
+
codeChanges: args.codeChanges,
|
|
5491
|
+
db: args.db,
|
|
5492
|
+
log: args.log,
|
|
5493
|
+
outcome: pullRequestOutcome
|
|
5494
|
+
});
|
|
5219
5495
|
if (recordedOutcome.applied && !recordedOutcome.commitComposition && pullRequestOutcome.state === "merged" && args.classifyPullRequestCommits) {
|
|
5220
5496
|
let commitComposition;
|
|
5221
5497
|
try {
|
|
@@ -5245,19 +5521,17 @@ function createGitHubWebhookRoute(args) {
|
|
|
5245
5521
|
issueOutcome
|
|
5246
5522
|
);
|
|
5247
5523
|
if (recordedOutcome.applied && issueOutcome.state === "closed") {
|
|
5248
|
-
await
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
)
|
|
5260
|
-
);
|
|
5524
|
+
await updateGitHubAnnotations({
|
|
5525
|
+
annotations: args.annotations,
|
|
5526
|
+
conversationIds: recordedOutcome.conversationIds,
|
|
5527
|
+
log: args.log,
|
|
5528
|
+
update: {
|
|
5529
|
+
repo: issueOutcome.repositoryFullName,
|
|
5530
|
+
number: issueOutcome.number,
|
|
5531
|
+
objectType: "task",
|
|
5532
|
+
status: "closed"
|
|
5533
|
+
}
|
|
5534
|
+
});
|
|
5261
5535
|
}
|
|
5262
5536
|
}
|
|
5263
5537
|
const recordedIssueConversations = issueConversations ? await recordGitHubIssueConversations(args.db, issueConversations) : false;
|
|
@@ -5271,6 +5545,13 @@ function createGitHubWebhookRoute(args) {
|
|
|
5271
5545
|
providerId: pullRequestConversations.pullRequestId
|
|
5272
5546
|
});
|
|
5273
5547
|
}
|
|
5548
|
+
const pullRequestActivity = normalizeGitHubPullRequestActivity({
|
|
5549
|
+
body,
|
|
5550
|
+
eventName
|
|
5551
|
+
});
|
|
5552
|
+
if (pullRequestActivity) {
|
|
5553
|
+
await args.codeChanges.recordActivity(pullRequestActivity);
|
|
5554
|
+
}
|
|
5274
5555
|
const recordedPullRequestLinkedIssues = pullRequestLinkedIssues ? await recordGitHubPullRequestLinkedIssues(
|
|
5275
5556
|
args.db,
|
|
5276
5557
|
pullRequestLinkedIssues
|
|
@@ -5383,30 +5664,30 @@ function createGitHubWebhookRoute(args) {
|
|
|
5383
5664
|
}
|
|
5384
5665
|
|
|
5385
5666
|
// src/merge-conflict-checks/heartbeat.ts
|
|
5386
|
-
import * as
|
|
5667
|
+
import * as z38 from "zod";
|
|
5387
5668
|
var CHECK_LIMIT = 10;
|
|
5388
5669
|
var MAX_PAGES2 = 5;
|
|
5389
5670
|
var CLAIM_MS = 5 * 6e4;
|
|
5390
5671
|
var UNKNOWN_RETRY_MS = 6e4;
|
|
5391
5672
|
var MAX_ATTEMPTS = 5;
|
|
5392
|
-
var searchNodeSchema =
|
|
5393
|
-
|
|
5394
|
-
baseRefName:
|
|
5395
|
-
headRefOid:
|
|
5396
|
-
mergeable:
|
|
5397
|
-
number:
|
|
5398
|
-
state:
|
|
5399
|
-
url:
|
|
5673
|
+
var searchNodeSchema = z38.union([
|
|
5674
|
+
z38.object({
|
|
5675
|
+
baseRefName: z38.string().min(1),
|
|
5676
|
+
headRefOid: z38.string().min(1),
|
|
5677
|
+
mergeable: z38.enum(["CONFLICTING", "MERGEABLE", "UNKNOWN"]),
|
|
5678
|
+
number: z38.number().int().positive(),
|
|
5679
|
+
state: z38.string(),
|
|
5680
|
+
url: z38.string().min(1)
|
|
5400
5681
|
}),
|
|
5401
|
-
|
|
5682
|
+
z38.object({}).strict()
|
|
5402
5683
|
]);
|
|
5403
|
-
var searchResponseSchema =
|
|
5404
|
-
data:
|
|
5405
|
-
search:
|
|
5406
|
-
nodes:
|
|
5407
|
-
pageInfo:
|
|
5408
|
-
endCursor:
|
|
5409
|
-
hasNextPage:
|
|
5684
|
+
var searchResponseSchema = z38.object({
|
|
5685
|
+
data: z38.object({
|
|
5686
|
+
search: z38.object({
|
|
5687
|
+
nodes: z38.array(searchNodeSchema.nullable()),
|
|
5688
|
+
pageInfo: z38.object({
|
|
5689
|
+
endCursor: z38.string().nullable(),
|
|
5690
|
+
hasNextPage: z38.boolean()
|
|
5410
5691
|
})
|
|
5411
5692
|
})
|
|
5412
5693
|
})
|
|
@@ -5479,6 +5760,139 @@ async function runGitHubConflictChecks(args) {
|
|
|
5479
5760
|
}
|
|
5480
5761
|
}
|
|
5481
5762
|
|
|
5763
|
+
// src/pull-request-outcomes/reconcile.ts
|
|
5764
|
+
import * as z39 from "zod";
|
|
5765
|
+
var RECONCILE_MS = 24 * 60 * 6e4;
|
|
5766
|
+
var REPOSITORY_LIMIT = 1;
|
|
5767
|
+
var PULL_REQUESTS_PER_QUERY = 100;
|
|
5768
|
+
var lifecycleSchema = z39.object({
|
|
5769
|
+
assignees: z39.object({
|
|
5770
|
+
nodes: z39.array(z39.object({ login: z39.string().min(1) }).nullable())
|
|
5771
|
+
}),
|
|
5772
|
+
// GraphQL omits the `[bot]` suffix that REST and webhooks give an app.
|
|
5773
|
+
author: z39.object({ __typename: z39.string(), login: z39.string().min(1) }).nullable(),
|
|
5774
|
+
closedAt: z39.string().nullable(),
|
|
5775
|
+
createdAt: z39.string(),
|
|
5776
|
+
databaseId: z39.number().int().positive(),
|
|
5777
|
+
headRefName: z39.string(),
|
|
5778
|
+
isDraft: z39.boolean(),
|
|
5779
|
+
merged: z39.boolean(),
|
|
5780
|
+
mergedAt: z39.string().nullable(),
|
|
5781
|
+
number: z39.number().int().positive(),
|
|
5782
|
+
state: z39.enum(["OPEN", "CLOSED", "MERGED"]),
|
|
5783
|
+
title: z39.string(),
|
|
5784
|
+
updatedAt: z39.string()
|
|
5785
|
+
});
|
|
5786
|
+
var lifecyclesResponseSchema = z39.object({
|
|
5787
|
+
data: z39.object({
|
|
5788
|
+
repository: z39.object({
|
|
5789
|
+
databaseId: z39.number().int().positive(),
|
|
5790
|
+
nameWithOwner: z39.string().min(1)
|
|
5791
|
+
}).catchall(lifecycleSchema.nullable())
|
|
5792
|
+
})
|
|
5793
|
+
});
|
|
5794
|
+
function closedWebhookBody(repository2, pullRequest) {
|
|
5795
|
+
const login2 = pullRequest.author?.login ?? "ghost";
|
|
5796
|
+
return {
|
|
5797
|
+
action: "closed",
|
|
5798
|
+
pull_request: {
|
|
5799
|
+
assignees: pullRequest.assignees.nodes.flatMap(
|
|
5800
|
+
(assignee) => assignee ? [{ login: assignee.login }] : []
|
|
5801
|
+
),
|
|
5802
|
+
closed_at: pullRequest.closedAt,
|
|
5803
|
+
created_at: pullRequest.createdAt,
|
|
5804
|
+
draft: pullRequest.isDraft,
|
|
5805
|
+
head: { ref: pullRequest.headRefName },
|
|
5806
|
+
id: pullRequest.databaseId,
|
|
5807
|
+
merged: pullRequest.merged,
|
|
5808
|
+
merged_at: pullRequest.mergedAt,
|
|
5809
|
+
number: pullRequest.number,
|
|
5810
|
+
title: pullRequest.title,
|
|
5811
|
+
updated_at: pullRequest.updatedAt,
|
|
5812
|
+
user: {
|
|
5813
|
+
login: pullRequest.author?.__typename === "Bot" ? `${login2}[bot]` : login2
|
|
5814
|
+
}
|
|
5815
|
+
},
|
|
5816
|
+
repository: {
|
|
5817
|
+
full_name: repository2.nameWithOwner,
|
|
5818
|
+
id: repository2.databaseId
|
|
5819
|
+
}
|
|
5820
|
+
};
|
|
5821
|
+
}
|
|
5822
|
+
async function reconcileRepository(args, repositoryFullName, numbers) {
|
|
5823
|
+
for (let start = 0; start < numbers.length; start += PULL_REQUESTS_PER_QUERY) {
|
|
5824
|
+
const { databaseId, nameWithOwner, ...pullRequests } = lifecyclesResponseSchema.parse(
|
|
5825
|
+
await args.loadLifecycles({
|
|
5826
|
+
numbers: numbers.slice(start, start + PULL_REQUESTS_PER_QUERY),
|
|
5827
|
+
repositoryFullName
|
|
5828
|
+
})
|
|
5829
|
+
).data.repository;
|
|
5830
|
+
for (const pullRequest of Object.values(pullRequests)) {
|
|
5831
|
+
if (!pullRequest || pullRequest.state === "OPEN") continue;
|
|
5832
|
+
const body = closedWebhookBody(
|
|
5833
|
+
{ databaseId, nameWithOwner },
|
|
5834
|
+
pullRequest
|
|
5835
|
+
);
|
|
5836
|
+
const outcome = normalizeGitHubPullRequestOutcome({
|
|
5837
|
+
body,
|
|
5838
|
+
botEmail: args.botEmail
|
|
5839
|
+
});
|
|
5840
|
+
if (!outcome) continue;
|
|
5841
|
+
const events = await withGitHubPullRequestPeople({
|
|
5842
|
+
body,
|
|
5843
|
+
deliveryId: "reconcile",
|
|
5844
|
+
events: gitHubPullRequestTerminalEvents(body),
|
|
5845
|
+
hasMatch: args.events.hasMatch,
|
|
5846
|
+
load: async (target) => await loadGitHubPullRequestPeople({
|
|
5847
|
+
logins: target.logins,
|
|
5848
|
+
loadPage: await args.loadCommitPages(target)
|
|
5849
|
+
}),
|
|
5850
|
+
log: args.log
|
|
5851
|
+
});
|
|
5852
|
+
for (const event of events) {
|
|
5853
|
+
await args.events.publish({ ...event, objectType: "code_change" });
|
|
5854
|
+
}
|
|
5855
|
+
await applyGitHubPullRequestOutcome({
|
|
5856
|
+
annotations: args.annotations,
|
|
5857
|
+
codeChanges: args.codeChanges,
|
|
5858
|
+
db: args.db,
|
|
5859
|
+
log: args.log,
|
|
5860
|
+
outcome
|
|
5861
|
+
});
|
|
5862
|
+
}
|
|
5863
|
+
}
|
|
5864
|
+
}
|
|
5865
|
+
async function reconcileGitHubPullRequests(args) {
|
|
5866
|
+
const numbersByRepository = /* @__PURE__ */ new Map();
|
|
5867
|
+
for (const row of await listGitHubStaleOpenPullRequests(
|
|
5868
|
+
args.db,
|
|
5869
|
+
new Date(args.nowMs - RECONCILE_MS)
|
|
5870
|
+
)) {
|
|
5871
|
+
const numbers = numbersByRepository.get(row.repositoryFullName) ?? [];
|
|
5872
|
+
numbers.push(row.number);
|
|
5873
|
+
numbersByRepository.set(row.repositoryFullName, numbers);
|
|
5874
|
+
}
|
|
5875
|
+
let reconciled = 0;
|
|
5876
|
+
for (const [repositoryFullName, numbers] of numbersByRepository) {
|
|
5877
|
+
if (reconciled >= REPOSITORY_LIMIT) break;
|
|
5878
|
+
const claimed = await args.state.setIfNotExists(
|
|
5879
|
+
`pull-request-reconcile:${repositoryFullName}`,
|
|
5880
|
+
args.nowMs,
|
|
5881
|
+
RECONCILE_MS
|
|
5882
|
+
);
|
|
5883
|
+
if (!claimed) continue;
|
|
5884
|
+
reconciled += 1;
|
|
5885
|
+
try {
|
|
5886
|
+
await reconcileRepository(args, repositoryFullName, numbers);
|
|
5887
|
+
} catch (error) {
|
|
5888
|
+
args.log.error("GitHub pull request reconcile failed", {
|
|
5889
|
+
errorType: error instanceof Error ? error.name : "UnknownError",
|
|
5890
|
+
repository: repositoryFullName
|
|
5891
|
+
});
|
|
5892
|
+
}
|
|
5893
|
+
}
|
|
5894
|
+
}
|
|
5895
|
+
|
|
5482
5896
|
// src/events/declarations.ts
|
|
5483
5897
|
var NEEDS_REPO = { anyOf: ["repo"] };
|
|
5484
5898
|
function gitHubEventDeclarations(pullRequestGuidance) {
|
|
@@ -5503,30 +5917,30 @@ function gitHubResourceUrl(input) {
|
|
|
5503
5917
|
if (input.resourceType === "repository") {
|
|
5504
5918
|
return `https://github.com/${input.identifier}`;
|
|
5505
5919
|
}
|
|
5506
|
-
const [repo,
|
|
5507
|
-
if (!repo || !
|
|
5920
|
+
const [repo, number31] = input.identifier.split("#");
|
|
5921
|
+
if (!repo || !number31) return void 0;
|
|
5508
5922
|
if (input.resourceType === "pull_request") {
|
|
5509
|
-
return `https://github.com/${repo}/pull/${
|
|
5923
|
+
return `https://github.com/${repo}/pull/${number31}`;
|
|
5510
5924
|
}
|
|
5511
5925
|
if (input.resourceType === "issue") {
|
|
5512
|
-
return `https://github.com/${repo}/issues/${
|
|
5926
|
+
return `https://github.com/${repo}/issues/${number31}`;
|
|
5513
5927
|
}
|
|
5514
5928
|
return void 0;
|
|
5515
5929
|
}
|
|
5516
5930
|
|
|
5517
5931
|
// src/pull-request-outcomes/commit-composition.ts
|
|
5518
|
-
import * as
|
|
5519
|
-
var canonicalCommitSchema =
|
|
5520
|
-
authorEmail:
|
|
5521
|
-
authorLogin:
|
|
5932
|
+
import * as z40 from "zod";
|
|
5933
|
+
var canonicalCommitSchema = z40.object({
|
|
5934
|
+
authorEmail: z40.string().nullable(),
|
|
5935
|
+
authorLogin: z40.string().nullable()
|
|
5522
5936
|
}).strict();
|
|
5523
|
-
var providerCommitSchema =
|
|
5524
|
-
author:
|
|
5525
|
-
commit:
|
|
5526
|
-
author:
|
|
5937
|
+
var providerCommitSchema = z40.object({
|
|
5938
|
+
author: z40.object({ login: z40.string() }).passthrough().nullable(),
|
|
5939
|
+
commit: z40.object({
|
|
5940
|
+
author: z40.object({ email: z40.string() }).passthrough().nullable()
|
|
5527
5941
|
}).passthrough()
|
|
5528
5942
|
}).passthrough();
|
|
5529
|
-
var commitPageSchema2 =
|
|
5943
|
+
var commitPageSchema2 = z40.array(providerCommitSchema).transform(
|
|
5530
5944
|
(commits) => commits.map(
|
|
5531
5945
|
(commit) => canonicalCommitSchema.parse({
|
|
5532
5946
|
authorEmail: commit.commit.author?.email ?? null,
|
|
@@ -6033,8 +6447,8 @@ function linkifyLine(line) {
|
|
|
6033
6447
|
if (isReferenceBoundary(index2 === 0 ? void 0 : line[index2 - 1])) {
|
|
6034
6448
|
const match = GITHUB_ISSUE_REFERENCE_PATTERN.exec(line.slice(index2));
|
|
6035
6449
|
if (match) {
|
|
6036
|
-
const [reference, owner, repository2,
|
|
6037
|
-
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${
|
|
6450
|
+
const [reference, owner, repository2, number31] = match;
|
|
6451
|
+
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number31})`;
|
|
6038
6452
|
index2 += reference.length;
|
|
6039
6453
|
continue;
|
|
6040
6454
|
}
|
|
@@ -6176,9 +6590,9 @@ function parseGitHubReferences(text2, config) {
|
|
|
6176
6590
|
}
|
|
6177
6591
|
return [...references.values()];
|
|
6178
6592
|
}
|
|
6179
|
-
function objectTitle(kind,
|
|
6180
|
-
if (!isRecord(
|
|
6181
|
-
const raw = kind === "commit" ? isRecord(
|
|
6593
|
+
function objectTitle(kind, object41) {
|
|
6594
|
+
if (!isRecord(object41)) return void 0;
|
|
6595
|
+
const raw = kind === "commit" ? isRecord(object41.commit) && typeof object41.commit.message === "string" ? object41.commit.message.split("\n")[0] : void 0 : typeof object41.title === "string" ? object41.title : void 0;
|
|
6182
6596
|
return raw?.replace(/\s+/g, " ").trim() || void 0;
|
|
6183
6597
|
}
|
|
6184
6598
|
async function loadGitHubConversationTitleContext(args) {
|
|
@@ -6457,9 +6871,9 @@ import {
|
|
|
6457
6871
|
} from "@sentry/junior-plugin-api";
|
|
6458
6872
|
|
|
6459
6873
|
// src/default-branch.ts
|
|
6460
|
-
import * as
|
|
6874
|
+
import * as z41 from "zod";
|
|
6461
6875
|
var DEFAULT_BRANCH_TTL_MS = 10 * 60 * 1e3;
|
|
6462
|
-
var
|
|
6876
|
+
var repositorySchema3 = z41.object({ default_branch: z41.string().min(1) });
|
|
6463
6877
|
async function loadDefaultBranch(env, cache, repository2) {
|
|
6464
6878
|
const { owner, name } = repository2;
|
|
6465
6879
|
return await cache.getOrLoad(
|
|
@@ -6470,7 +6884,7 @@ async function loadDefaultBranch(env, cache, repository2) {
|
|
|
6470
6884
|
permissions: { metadata: "read" },
|
|
6471
6885
|
repositories: [name]
|
|
6472
6886
|
});
|
|
6473
|
-
const response =
|
|
6887
|
+
const response = repositorySchema3.parse(
|
|
6474
6888
|
await githubRequest(
|
|
6475
6889
|
"https://api.github.com",
|
|
6476
6890
|
`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`,
|
|
@@ -6682,6 +7096,27 @@ function isGitHubIssueRead(input) {
|
|
|
6682
7096
|
return isGitHubApiUrl(input.upstreamUrl) && HTTP_READ_METHODS.has(input.method) && ISSUE_PATH.test(input.upstreamUrl.pathname.toLowerCase());
|
|
6683
7097
|
}
|
|
6684
7098
|
var PULL_REQUEST_COMMENT_REACTIONS_PATH = /^\/repos\/[^/]+\/[^/]+\/(issues|pulls)\/comments\/[^/]+\/reactions(?:\/[^/]+)?$/;
|
|
7099
|
+
var TOOL_ONLY_REST_WRITES = [
|
|
7100
|
+
{
|
|
7101
|
+
denialMessage: "GitHub issue comment edits must use the github_updateIssueComment tool, which only edits comments the bot posted.",
|
|
7102
|
+
method: "PATCH",
|
|
7103
|
+
operation: "github.issue.comment.update",
|
|
7104
|
+
restPath: /^\/repos\/[^/]+\/[^/]+\/issues\/comments\/\d+$/
|
|
7105
|
+
},
|
|
7106
|
+
{
|
|
7107
|
+
denialMessage: "Reactions on a GitHub issue or pull request must use the github_reactToIssue tool.",
|
|
7108
|
+
method: "POST",
|
|
7109
|
+
operation: "github.issue.reaction.create",
|
|
7110
|
+
restPath: /^\/repos\/[^/]+\/[^/]+\/issues\/\d+\/reactions$/
|
|
7111
|
+
}
|
|
7112
|
+
];
|
|
7113
|
+
function toolOnlyRestWrite(method, upstreamUrl) {
|
|
7114
|
+
if (!isGitHubApiUrl(upstreamUrl)) return void 0;
|
|
7115
|
+
const pathname = upstreamUrl.pathname.toLowerCase();
|
|
7116
|
+
return TOOL_ONLY_REST_WRITES.find(
|
|
7117
|
+
(write) => write.method === method && write.restPath.test(pathname)
|
|
7118
|
+
);
|
|
7119
|
+
}
|
|
6685
7120
|
var GITHUB_BODY_WRITES = [
|
|
6686
7121
|
{
|
|
6687
7122
|
denialMessage: `GitHub issue creation must use the github_createIssue tool, which owns idempotency and the conversation footer. ${CREATE_TOOL_ROUTING_GUIDANCE}`,
|
|
@@ -6776,6 +7211,9 @@ function githubApiWriteGrantName(method, upstreamUrl) {
|
|
|
6776
7211
|
if ((method === "POST" || method === "DELETE") && PULL_REQUEST_COMMENT_REACTIONS_PATH.test(pathname)) {
|
|
6777
7212
|
return "installation-write";
|
|
6778
7213
|
}
|
|
7214
|
+
if (toolOnlyRestWrite(method, upstreamUrl)) {
|
|
7215
|
+
return "installation-write";
|
|
7216
|
+
}
|
|
6779
7217
|
return void 0;
|
|
6780
7218
|
}
|
|
6781
7219
|
var HOST_GRAPHQL_MUTATIONS = [
|
|
@@ -6839,6 +7277,13 @@ function applyGitHubEgressPolicy(input) {
|
|
|
6839
7277
|
denialMessage: "GitHub pull request feedback reactions must use the github_updatePullRequestFeedback tool."
|
|
6840
7278
|
});
|
|
6841
7279
|
}
|
|
7280
|
+
const toolOnlyWrite = toolOnlyRestWrite(input.method, input.upstreamUrl);
|
|
7281
|
+
if (toolOnlyWrite) {
|
|
7282
|
+
enforceEgressPolicy({
|
|
7283
|
+
allowed: input.operation === toolOnlyWrite.operation,
|
|
7284
|
+
denialMessage: toolOnlyWrite.denialMessage
|
|
7285
|
+
});
|
|
7286
|
+
}
|
|
6842
7287
|
if (isGitHubIssueRead(input)) {
|
|
6843
7288
|
enforceEgressPolicy({
|
|
6844
7289
|
allowed: input.operation === "github.issue.get",
|
|
@@ -7152,8 +7597,10 @@ function githubPlugin(options = {}) {
|
|
|
7152
7597
|
return linkifyGitHubReferences(text2);
|
|
7153
7598
|
},
|
|
7154
7599
|
async heartbeat(ctx) {
|
|
7600
|
+
const db = ctx.db;
|
|
7601
|
+
const installationEnv = { appIdEnv, installationIdEnv, privateKeyEnv };
|
|
7155
7602
|
await runGitHubConflictChecks({
|
|
7156
|
-
db
|
|
7603
|
+
db,
|
|
7157
7604
|
events: ctx.events,
|
|
7158
7605
|
log: ctx.log,
|
|
7159
7606
|
now: new Date(ctx.nowMs),
|
|
@@ -7162,13 +7609,25 @@ function githubPlugin(options = {}) {
|
|
|
7162
7609
|
if (!login2) {
|
|
7163
7610
|
throw new Error(`${botEmailEnv} is not a GitHub bot address`);
|
|
7164
7611
|
}
|
|
7165
|
-
return await searchOpenPullRequestMergeability(
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
);
|
|
7612
|
+
return await searchOpenPullRequestMergeability(installationEnv, {
|
|
7613
|
+
...input,
|
|
7614
|
+
author: `app/${login2.replace(/\[bot\]$/, "")}`
|
|
7615
|
+
});
|
|
7169
7616
|
},
|
|
7170
7617
|
state: ctx.state
|
|
7171
7618
|
});
|
|
7619
|
+
await reconcileGitHubPullRequests({
|
|
7620
|
+
annotations: ctx.annotations,
|
|
7621
|
+
botEmail: readEnv(botEmailEnv),
|
|
7622
|
+
codeChanges: ctx.codeChanges,
|
|
7623
|
+
db,
|
|
7624
|
+
events: ctx.events,
|
|
7625
|
+
loadCommitPages: async (target) => await loadPullRequestCommitPages(installationEnv, target),
|
|
7626
|
+
loadLifecycles: async (input) => await loadPullRequestLifecycles(installationEnv, input),
|
|
7627
|
+
log: ctx.log,
|
|
7628
|
+
nowMs: ctx.nowMs,
|
|
7629
|
+
state: ctx.state
|
|
7630
|
+
});
|
|
7172
7631
|
},
|
|
7173
7632
|
async unfinishedWork(ctx) {
|
|
7174
7633
|
const db = ctx.db;
|
|
@@ -7233,7 +7692,9 @@ function githubPlugin(options = {}) {
|
|
|
7233
7692
|
return createGitHubTools(
|
|
7234
7693
|
ctx,
|
|
7235
7694
|
readEnv(botEmailEnv),
|
|
7236
|
-
|
|
7695
|
+
gitHubPullRequestSubscription(
|
|
7696
|
+
options.pullRequestEvents?.subscribeAfterCreate
|
|
7697
|
+
)
|
|
7237
7698
|
);
|
|
7238
7699
|
},
|
|
7239
7700
|
workspacePrepare: prepareWorkspace,
|