@sentry/junior-github 0.264.0 → 0.265.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/README.md +51 -0
- package/dist/{chunk-KWVC6CU5.js → chunk-4RYMEHIK.js} +102 -90
- package/dist/credential-support.d.ts +1 -1
- package/dist/db/schema.d.ts +192 -0
- package/dist/events/deployment.d.ts +13 -2
- package/dist/events/issue.d.ts +11 -3
- package/dist/events/pull-request.d.ts +14 -2
- package/dist/events/release.d.ts +6 -1
- package/dist/events/repository.d.ts +10 -1
- package/dist/index.js +795 -532
- package/dist/plugin.d.ts +0 -5
- package/dist/pull-request-requesters/store.d.ts +34 -0
- package/dist/testing.js +1 -1
- package/dist/tool-support/attribution.d.ts +22 -11
- package/dist/tools/update-pull-request.d.ts +1 -0
- package/dist/webhooks/check-suite.d.ts +4 -4
- package/dist/webhooks/event-targets.d.ts +12 -0
- package/dist/webhooks/handler.d.ts +12 -7
- package/dist/webhooks/pull-request-match-data.d.ts +31 -0
- package/dist/webhooks/pull-request-people.d.ts +25 -5
- package/migrations/0009_nostalgic_thing.sql +8 -0
- package/migrations/meta/0009_snapshot.json +404 -0
- package/migrations/meta/_journal.json +8 -1
- package/package.json +2 -2
- package/dist/webhooks/pull-request-author-role.d.ts +0 -20
package/dist/index.js
CHANGED
|
@@ -21,7 +21,9 @@ import {
|
|
|
21
21
|
GITHUB_RELEASE_EVENTS,
|
|
22
22
|
GITHUB_RELEASE_SOURCE_IDENTIFIER,
|
|
23
23
|
GITHUB_RELEASE_SUGGESTED_EVENTS,
|
|
24
|
+
GITHUB_REPOSITORY_EVENTS,
|
|
24
25
|
GITHUB_REPOSITORY_IDENTIFIER,
|
|
26
|
+
GITHUB_REPOSITORY_SUGGESTED_EVENTS,
|
|
25
27
|
HTTP_READ_METHODS,
|
|
26
28
|
USER_WRITE_REQUIREMENTS,
|
|
27
29
|
botLoginFromEmail,
|
|
@@ -51,11 +53,118 @@ import {
|
|
|
51
53
|
readGrantPermissions,
|
|
52
54
|
requireEnv,
|
|
53
55
|
resolveUserAccount
|
|
54
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-4RYMEHIK.js";
|
|
57
|
+
|
|
58
|
+
// src/tool-support/attribution.ts
|
|
59
|
+
var GITHUB_REQUEST_ATTRIBUTION_START = "<!-- junior-request-attribution:start -->";
|
|
60
|
+
var GITHUB_REQUEST_ATTRIBUTION_END = "<!-- junior-request-attribution:end -->";
|
|
61
|
+
var SLACK_USER_ID_DISPLAY_PATTERN = /^[UW][A-Z0-9]{5,}$/;
|
|
62
|
+
var GITHUB_LOGIN_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/;
|
|
63
|
+
function linkedGitHubLogin(user) {
|
|
64
|
+
const login = user?.identities.find((identity) => identity.provider === "github")?.handle?.trim().replace(/^@/, "");
|
|
65
|
+
return login && GITHUB_LOGIN_PATTERN.test(login) ? login : void 0;
|
|
66
|
+
}
|
|
67
|
+
function cleanDisplayValue(value, userId) {
|
|
68
|
+
const cleaned = value?.replace(/[\r\n<>]/g, " ").trim();
|
|
69
|
+
if (!cleaned) {
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
if (cleaned.toLowerCase() === "unknown") {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
if (userId && cleaned === userId) {
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
if (SLACK_USER_ID_DISPLAY_PATTERN.test(cleaned)) {
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
return cleaned;
|
|
82
|
+
}
|
|
83
|
+
function automationLabel(source, automationUrl) {
|
|
84
|
+
if (source?.kind !== "event_automation" && source?.kind !== "scheduled_automation" || !source.automationId) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
const automation = `automation \`${source.automationId}\``;
|
|
88
|
+
const label = automationUrl ? `[${automation}](${automationUrl})` : automation;
|
|
89
|
+
return source.automationRunId ? `${label} \xB7 Run ID \`${source.automationRunId}\`` : label;
|
|
90
|
+
}
|
|
91
|
+
function requesterLabel(args) {
|
|
92
|
+
const { actor, identity, user } = args;
|
|
93
|
+
const automation = automationLabel(args.source, args.automationUrl);
|
|
94
|
+
if (automation) {
|
|
95
|
+
return automation;
|
|
96
|
+
}
|
|
97
|
+
if (!actor || actor.platform === "system") {
|
|
98
|
+
return void 0;
|
|
99
|
+
}
|
|
100
|
+
const login = linkedGitHubLogin(user);
|
|
101
|
+
if (login) {
|
|
102
|
+
return `@${login}`;
|
|
103
|
+
}
|
|
104
|
+
const userId = actor.userId;
|
|
105
|
+
const display = cleanDisplayValue(user?.displayName, userId) ?? cleanDisplayValue(identity?.displayName, userId) ?? cleanDisplayValue(identity?.handle, userId) ?? cleanDisplayValue(actor.fullName, userId) ?? cleanDisplayValue(actor.userName, userId);
|
|
106
|
+
return display ? `**${display.replaceAll("*", "\\*")}**` : void 0;
|
|
107
|
+
}
|
|
108
|
+
function parseExistingLabels(blockContents) {
|
|
109
|
+
const trimmed = blockContents.trim().replace(/\.$/, "");
|
|
110
|
+
if (!trimmed) {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
const withoutLeadIn = trimmed.replace(/^(?:Requested by|via)\s+/i, "");
|
|
114
|
+
return withoutLeadIn.split(/,\s*(?=\*\*|@|\[?automation `|Junior system actor `|via\s)/i).map((entry) => entry.trim().replace(/^via\s+/i, "")).filter(Boolean);
|
|
115
|
+
}
|
|
116
|
+
function formatAttributionBlock(labels) {
|
|
117
|
+
return `${GITHUB_REQUEST_ATTRIBUTION_START}
|
|
118
|
+
via ${labels.join(", ")}.
|
|
119
|
+
${GITHUB_REQUEST_ATTRIBUTION_END}`;
|
|
120
|
+
}
|
|
121
|
+
function applyAttribution(body, label) {
|
|
122
|
+
const normalizedBody = body.trimEnd();
|
|
123
|
+
const existing = new RegExp(
|
|
124
|
+
`${GITHUB_REQUEST_ATTRIBUTION_START}([\\s\\S]*?)${GITHUB_REQUEST_ATTRIBUTION_END}`
|
|
125
|
+
);
|
|
126
|
+
const existingMatch = normalizedBody.match(existing);
|
|
127
|
+
const existingLabels = existingMatch?.[1] !== void 0 ? parseExistingLabels(existingMatch[1]) : [];
|
|
128
|
+
const labels = label && !existingLabels.includes(label) ? [...existingLabels, label] : existingLabels;
|
|
129
|
+
const attribution = labels.length ? formatAttributionBlock(labels) : void 0;
|
|
130
|
+
if (existingMatch) {
|
|
131
|
+
return attribution ? normalizedBody.replace(existing, attribution) : normalizedBody.replace(existing, "").trimEnd();
|
|
132
|
+
}
|
|
133
|
+
if (!attribution) {
|
|
134
|
+
return normalizedBody;
|
|
135
|
+
}
|
|
136
|
+
return normalizedBody ? `${normalizedBody}
|
|
137
|
+
|
|
138
|
+
${attribution}` : attribution;
|
|
139
|
+
}
|
|
140
|
+
async function resolveGitHubRequester(ctx) {
|
|
141
|
+
if (!ctx.actor || ctx.actor.platform === "system") return void 0;
|
|
142
|
+
try {
|
|
143
|
+
return await ctx.users.resolveActor();
|
|
144
|
+
} catch (error) {
|
|
145
|
+
ctx.log.warn("github.requester.resolve_actor.failed", {
|
|
146
|
+
"exception.message": error instanceof Error ? error.message : String(error)
|
|
147
|
+
});
|
|
148
|
+
return void 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function appendGitHubRequesterAttribution(body, ctx, requester) {
|
|
152
|
+
return applyAttribution(
|
|
153
|
+
body,
|
|
154
|
+
requesterLabel({
|
|
155
|
+
actor: ctx.actor,
|
|
156
|
+
automationUrl: ctx.automationLink?.url,
|
|
157
|
+
identity: requester?.identity,
|
|
158
|
+
source: ctx.source,
|
|
159
|
+
user: requester?.user
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
}
|
|
55
163
|
|
|
56
164
|
// src/plugin.ts
|
|
57
165
|
import {
|
|
58
|
-
defineJuniorPlugin
|
|
166
|
+
defineJuniorPlugin,
|
|
167
|
+
mergeEventMatchFields
|
|
59
168
|
} from "@sentry/junior-plugin-api";
|
|
60
169
|
|
|
61
170
|
// src/tools/clone-repository.ts
|
|
@@ -458,7 +567,7 @@ function githubConversationFooter(conversationId, dashboardUrl) {
|
|
|
458
567
|
const id = nonEmptyString(conversationId, "conversationId");
|
|
459
568
|
const normalizedDashboardUrl = dashboardUrl?.trim();
|
|
460
569
|
const sentryUrl = sentryConversationUrl(id);
|
|
461
|
-
const sessionLinks = normalizedDashboardUrl ? `[View
|
|
570
|
+
const sessionLinks = normalizedDashboardUrl ? `[View Session](${normalizedDashboardUrl})${sentryUrl ? ` [[Sentry]](${sentryUrl})` : ""}` : sentryUrl ? `[View Session in Sentry](${sentryUrl})` : void 0;
|
|
462
571
|
if (!sessionLinks) {
|
|
463
572
|
return void 0;
|
|
464
573
|
}
|
|
@@ -534,111 +643,6 @@ function appendGitHubFooter(body, conversationId, dashboardUrl) {
|
|
|
534
643
|
${footer}` : footer;
|
|
535
644
|
}
|
|
536
645
|
|
|
537
|
-
// src/tool-support/attribution.ts
|
|
538
|
-
var GITHUB_REQUEST_ATTRIBUTION_START = "<!-- junior-request-attribution:start -->";
|
|
539
|
-
var GITHUB_REQUEST_ATTRIBUTION_END = "<!-- junior-request-attribution:end -->";
|
|
540
|
-
var SLACK_USER_ID_DISPLAY_PATTERN = /^[UW][A-Z0-9]{5,}$/;
|
|
541
|
-
var GITHUB_LOGIN_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/;
|
|
542
|
-
function linkedGitHubLogin(user) {
|
|
543
|
-
const login = user?.identities.find((identity) => identity.provider === "github")?.handle?.trim().replace(/^@/, "");
|
|
544
|
-
return login && GITHUB_LOGIN_PATTERN.test(login) ? login : void 0;
|
|
545
|
-
}
|
|
546
|
-
function cleanDisplayValue(value, userId) {
|
|
547
|
-
const cleaned = value?.replace(/[\r\n<>]/g, " ").trim();
|
|
548
|
-
if (!cleaned) {
|
|
549
|
-
return void 0;
|
|
550
|
-
}
|
|
551
|
-
if (cleaned.toLowerCase() === "unknown") {
|
|
552
|
-
return void 0;
|
|
553
|
-
}
|
|
554
|
-
if (userId && cleaned === userId) {
|
|
555
|
-
return void 0;
|
|
556
|
-
}
|
|
557
|
-
if (SLACK_USER_ID_DISPLAY_PATTERN.test(cleaned)) {
|
|
558
|
-
return void 0;
|
|
559
|
-
}
|
|
560
|
-
return cleaned;
|
|
561
|
-
}
|
|
562
|
-
function automationLabel(source, automationUrl) {
|
|
563
|
-
if (source?.kind !== "event_automation" && source?.kind !== "scheduled_automation" || !source.automationId) {
|
|
564
|
-
return void 0;
|
|
565
|
-
}
|
|
566
|
-
const automation = `automation \`${source.automationId}\``;
|
|
567
|
-
const label = automationUrl ? `[${automation}](${automationUrl})` : automation;
|
|
568
|
-
return source.automationRunId ? `${label} \xB7 Run ID \`${source.automationRunId}\`` : label;
|
|
569
|
-
}
|
|
570
|
-
function requesterLabel(args) {
|
|
571
|
-
const { actor, identity, user } = args;
|
|
572
|
-
const automation = automationLabel(args.source, args.automationUrl);
|
|
573
|
-
if (automation) {
|
|
574
|
-
return automation;
|
|
575
|
-
}
|
|
576
|
-
if (!actor || actor.platform === "system") {
|
|
577
|
-
return void 0;
|
|
578
|
-
}
|
|
579
|
-
const login = linkedGitHubLogin(user);
|
|
580
|
-
if (login) {
|
|
581
|
-
return `@${login}`;
|
|
582
|
-
}
|
|
583
|
-
const userId = actor.userId;
|
|
584
|
-
const display = cleanDisplayValue(user?.displayName, userId) ?? cleanDisplayValue(identity?.displayName, userId) ?? cleanDisplayValue(identity?.handle, userId) ?? cleanDisplayValue(actor.fullName, userId) ?? cleanDisplayValue(actor.userName, userId);
|
|
585
|
-
return display ? `**${display.replaceAll("*", "\\*")}**` : void 0;
|
|
586
|
-
}
|
|
587
|
-
function parseExistingLabels(blockContents) {
|
|
588
|
-
const trimmed = blockContents.trim().replace(/\.$/, "");
|
|
589
|
-
if (!trimmed) {
|
|
590
|
-
return [];
|
|
591
|
-
}
|
|
592
|
-
const withoutLeadIn = trimmed.replace(/^(?:Requested by|via)\s+/i, "");
|
|
593
|
-
return withoutLeadIn.split(/,\s*(?=\*\*|@|\[?automation `|Junior system actor `|via\s)/i).map((entry) => entry.trim().replace(/^via\s+/i, "")).filter(Boolean);
|
|
594
|
-
}
|
|
595
|
-
function formatAttributionBlock(labels) {
|
|
596
|
-
return `${GITHUB_REQUEST_ATTRIBUTION_START}
|
|
597
|
-
via ${labels.join(", ")}.
|
|
598
|
-
${GITHUB_REQUEST_ATTRIBUTION_END}`;
|
|
599
|
-
}
|
|
600
|
-
function applyAttribution(body, label) {
|
|
601
|
-
const normalizedBody = body.trimEnd();
|
|
602
|
-
const existing = new RegExp(
|
|
603
|
-
`${GITHUB_REQUEST_ATTRIBUTION_START}([\\s\\S]*?)${GITHUB_REQUEST_ATTRIBUTION_END}`
|
|
604
|
-
);
|
|
605
|
-
const existingMatch = normalizedBody.match(existing);
|
|
606
|
-
const existingLabels = existingMatch?.[1] !== void 0 ? parseExistingLabels(existingMatch[1]) : [];
|
|
607
|
-
const labels = label && !existingLabels.includes(label) ? [...existingLabels, label] : existingLabels;
|
|
608
|
-
const attribution = labels.length ? formatAttributionBlock(labels) : void 0;
|
|
609
|
-
if (existingMatch) {
|
|
610
|
-
return attribution ? normalizedBody.replace(existing, attribution) : normalizedBody.replace(existing, "").trimEnd();
|
|
611
|
-
}
|
|
612
|
-
if (!attribution) {
|
|
613
|
-
return normalizedBody;
|
|
614
|
-
}
|
|
615
|
-
return normalizedBody ? `${normalizedBody}
|
|
616
|
-
|
|
617
|
-
${attribution}` : attribution;
|
|
618
|
-
}
|
|
619
|
-
async function appendGitHubRequesterAttribution(body, ctx) {
|
|
620
|
-
let resolved;
|
|
621
|
-
if (ctx.actor) {
|
|
622
|
-
try {
|
|
623
|
-
resolved = await ctx.users.resolveActor();
|
|
624
|
-
} catch (error) {
|
|
625
|
-
ctx.log.warn("github.requester_attribution.resolve_actor.failed", {
|
|
626
|
-
"exception.message": error instanceof Error ? error.message : String(error)
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
return applyAttribution(
|
|
631
|
-
body,
|
|
632
|
-
requesterLabel({
|
|
633
|
-
actor: ctx.actor,
|
|
634
|
-
automationUrl: ctx.automationLink?.url,
|
|
635
|
-
identity: resolved?.identity,
|
|
636
|
-
source: ctx.source,
|
|
637
|
-
user: resolved?.user
|
|
638
|
-
})
|
|
639
|
-
);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
646
|
// src/tools/create-issue.ts
|
|
643
647
|
var GITHUB_ISSUE_CREATE_IDEMPOTENCY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
644
648
|
var GITHUB_ISSUE_CREATE_LOCK_TTL_MS = 6e4;
|
|
@@ -712,10 +716,11 @@ var gitHubIssueOutputSchema = pluginToolOutputSchema2.merge(
|
|
|
712
716
|
);
|
|
713
717
|
function gitHubIssueToolResult(input, result, canSubscribe) {
|
|
714
718
|
const repo = parseRepo2(input.repo);
|
|
715
|
-
const subscribable =
|
|
719
|
+
const subscribable = gitHubIssueSubscribable({
|
|
720
|
+
canSubscribe,
|
|
716
721
|
number: result.number,
|
|
717
722
|
repo: `${repo.owner}/${repo.name}`
|
|
718
|
-
})
|
|
723
|
+
});
|
|
719
724
|
const data = {
|
|
720
725
|
number: result.number,
|
|
721
726
|
url: result.url,
|
|
@@ -817,7 +822,11 @@ async function createGitHubIssueRequest(conversationId, input, ctx, dashboardUrl
|
|
|
817
822
|
const payload = {
|
|
818
823
|
title: nonEmptyString2(input.title, "title"),
|
|
819
824
|
body: appendGitHubFooter(
|
|
820
|
-
|
|
825
|
+
appendGitHubRequesterAttribution(
|
|
826
|
+
input.body ?? "",
|
|
827
|
+
ctx,
|
|
828
|
+
await resolveGitHubRequester(ctx)
|
|
829
|
+
),
|
|
821
830
|
conversationId,
|
|
822
831
|
dashboardUrl
|
|
823
832
|
),
|
|
@@ -1140,11 +1149,12 @@ function createGitHubGetDeploymentTool(ctx) {
|
|
|
1140
1149
|
url: `https://github.com/${repo.ref}/deployments`
|
|
1141
1150
|
};
|
|
1142
1151
|
}
|
|
1143
|
-
const subscribable =
|
|
1152
|
+
const subscribable = gitHubDeploymentSourceSubscribable({
|
|
1153
|
+
canSubscribe: ctx.events.canSubscribe,
|
|
1144
1154
|
commitSha,
|
|
1145
1155
|
environment: input.environment,
|
|
1146
1156
|
repo: repo.ref
|
|
1147
|
-
})
|
|
1157
|
+
});
|
|
1148
1158
|
const data = {
|
|
1149
1159
|
commitSha,
|
|
1150
1160
|
deployment,
|
|
@@ -1161,18 +1171,180 @@ function createGitHubGetDeploymentTool(ctx) {
|
|
|
1161
1171
|
}
|
|
1162
1172
|
|
|
1163
1173
|
// src/tools/create-pull-request.ts
|
|
1164
|
-
import {
|
|
1165
|
-
objectFactsSchema as objectFactsSchema2,
|
|
1166
|
-
definePluginTool as definePluginTool4,
|
|
1167
|
-
EgressAuthRequired as EgressAuthRequired2,
|
|
1168
|
-
PluginToolInputError as PluginToolInputError5,
|
|
1169
|
-
pluginToolOutputSchema as pluginToolOutputSchema4,
|
|
1170
|
-
watchResultSchema,
|
|
1171
|
-
subscribableResourceSchema as subscribableResourceSchema3
|
|
1172
|
-
} from "@sentry/junior-plugin-api";
|
|
1173
|
-
import { Type as Type2 } from "@sinclair/typebox";
|
|
1174
|
-
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
1175
|
-
import { z as
|
|
1174
|
+
import {
|
|
1175
|
+
objectFactsSchema as objectFactsSchema2,
|
|
1176
|
+
definePluginTool as definePluginTool4,
|
|
1177
|
+
EgressAuthRequired as EgressAuthRequired2,
|
|
1178
|
+
PluginToolInputError as PluginToolInputError5,
|
|
1179
|
+
pluginToolOutputSchema as pluginToolOutputSchema4,
|
|
1180
|
+
watchResultSchema,
|
|
1181
|
+
subscribableResourceSchema as subscribableResourceSchema3
|
|
1182
|
+
} from "@sentry/junior-plugin-api";
|
|
1183
|
+
import { Type as Type2 } from "@sinclair/typebox";
|
|
1184
|
+
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
1185
|
+
import { z as z6 } from "zod";
|
|
1186
|
+
|
|
1187
|
+
// src/pull-request-requesters/store.ts
|
|
1188
|
+
import { and, asc, eq, inArray, lt } from "drizzle-orm";
|
|
1189
|
+
|
|
1190
|
+
// src/db/schema.ts
|
|
1191
|
+
import { sql } from "drizzle-orm";
|
|
1192
|
+
import {
|
|
1193
|
+
index,
|
|
1194
|
+
integer,
|
|
1195
|
+
pgTable,
|
|
1196
|
+
primaryKey,
|
|
1197
|
+
text,
|
|
1198
|
+
timestamp
|
|
1199
|
+
} from "drizzle-orm/pg-core";
|
|
1200
|
+
import { z as z5 } from "zod";
|
|
1201
|
+
var githubPullRequestStateSchema = z5.enum([
|
|
1202
|
+
"closed_unmerged",
|
|
1203
|
+
"merged",
|
|
1204
|
+
"open"
|
|
1205
|
+
]);
|
|
1206
|
+
var githubPullRequestCommitCompositionSchema = z5.enum([
|
|
1207
|
+
"junior_only",
|
|
1208
|
+
"mixed"
|
|
1209
|
+
]);
|
|
1210
|
+
var githubIssueStateSchema = z5.enum(["closed", "open"]);
|
|
1211
|
+
var githubIssueStateReasonSchema = z5.enum([
|
|
1212
|
+
"completed",
|
|
1213
|
+
"duplicate",
|
|
1214
|
+
"not_planned",
|
|
1215
|
+
"reopened"
|
|
1216
|
+
]);
|
|
1217
|
+
var juniorGitHubIssues = pgTable(
|
|
1218
|
+
"junior_github_issues",
|
|
1219
|
+
{
|
|
1220
|
+
issueId: text("issue_id").primaryKey(),
|
|
1221
|
+
repositoryId: text("repository_id").notNull(),
|
|
1222
|
+
repositoryFullName: text("repository_full_name").notNull(),
|
|
1223
|
+
number: integer("number").notNull(),
|
|
1224
|
+
state: text("state").$type().notNull(),
|
|
1225
|
+
stateReason: text("state_reason").$type(),
|
|
1226
|
+
conversationIds: text("conversation_ids").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
1227
|
+
openedAt: timestamp("opened_at", { withTimezone: true }).notNull(),
|
|
1228
|
+
closedAt: timestamp("closed_at", { withTimezone: true }),
|
|
1229
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
1230
|
+
},
|
|
1231
|
+
(table2) => [
|
|
1232
|
+
index("junior_github_issues_opened_at_idx").on(table2.openedAt),
|
|
1233
|
+
index("junior_github_issues_closed_at_idx").on(table2.closedAt),
|
|
1234
|
+
index("junior_github_issues_open_idx").on(table2.issueId).where(sql`${table2.state} = 'open'`)
|
|
1235
|
+
]
|
|
1236
|
+
);
|
|
1237
|
+
var juniorGitHubPullRequests = pgTable(
|
|
1238
|
+
"junior_github_pull_requests",
|
|
1239
|
+
{
|
|
1240
|
+
pullRequestId: text("pull_request_id").primaryKey(),
|
|
1241
|
+
repositoryId: text("repository_id").notNull(),
|
|
1242
|
+
repositoryFullName: text("repository_full_name").notNull(),
|
|
1243
|
+
number: integer("number").notNull(),
|
|
1244
|
+
state: text("state").$type().notNull(),
|
|
1245
|
+
commitComposition: text("commit_composition").$type(),
|
|
1246
|
+
conversationIds: text("conversation_ids").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
1247
|
+
openedAt: timestamp("opened_at", { withTimezone: true }).notNull(),
|
|
1248
|
+
mergedAt: timestamp("merged_at", { withTimezone: true }),
|
|
1249
|
+
closedAt: timestamp("closed_at", { withTimezone: true }),
|
|
1250
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
1251
|
+
},
|
|
1252
|
+
(table2) => [
|
|
1253
|
+
index("junior_github_pull_requests_opened_at_idx").on(table2.openedAt),
|
|
1254
|
+
index("junior_github_pull_requests_merged_at_idx").on(table2.mergedAt),
|
|
1255
|
+
index("junior_github_pull_requests_closed_at_idx").on(table2.closedAt),
|
|
1256
|
+
index("junior_github_pull_requests_open_idx").on(table2.pullRequestId).where(sql`${table2.state} = 'open'`),
|
|
1257
|
+
index("junior_github_pull_requests_unmerged_conversations_idx").using("gin", table2.conversationIds).where(sql`${table2.state} <> 'merged'`)
|
|
1258
|
+
]
|
|
1259
|
+
);
|
|
1260
|
+
var juniorGitHubPullRequestIssues = pgTable(
|
|
1261
|
+
"junior_github_pull_request_issues",
|
|
1262
|
+
{
|
|
1263
|
+
pullRequestId: text("pull_request_id").notNull().references(() => juniorGitHubPullRequests.pullRequestId, {
|
|
1264
|
+
onDelete: "cascade"
|
|
1265
|
+
}),
|
|
1266
|
+
issueRepositoryFullName: text("issue_repository_full_name").notNull(),
|
|
1267
|
+
issueNumber: integer("issue_number").notNull()
|
|
1268
|
+
},
|
|
1269
|
+
(table2) => [
|
|
1270
|
+
primaryKey({
|
|
1271
|
+
columns: [
|
|
1272
|
+
table2.pullRequestId,
|
|
1273
|
+
table2.issueRepositoryFullName,
|
|
1274
|
+
table2.issueNumber
|
|
1275
|
+
]
|
|
1276
|
+
})
|
|
1277
|
+
]
|
|
1278
|
+
);
|
|
1279
|
+
var juniorGitHubPullRequestRequesters = pgTable(
|
|
1280
|
+
"junior_github_pull_request_requesters",
|
|
1281
|
+
{
|
|
1282
|
+
/** Lowercase `owner/name`. */
|
|
1283
|
+
repositoryFullName: text("repository_full_name").notNull(),
|
|
1284
|
+
number: integer("number").notNull(),
|
|
1285
|
+
/** Core `junior_identities.id` of the person who acted. */
|
|
1286
|
+
identityId: text("identity_id").notNull(),
|
|
1287
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
1288
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
1289
|
+
},
|
|
1290
|
+
(table2) => [
|
|
1291
|
+
primaryKey({
|
|
1292
|
+
columns: [table2.repositoryFullName, table2.number, table2.identityId]
|
|
1293
|
+
})
|
|
1294
|
+
]
|
|
1295
|
+
);
|
|
1296
|
+
|
|
1297
|
+
// src/pull-request-requesters/store.ts
|
|
1298
|
+
var table = juniorGitHubPullRequestRequesters;
|
|
1299
|
+
async function recordGitHubPullRequestOpener(db, input) {
|
|
1300
|
+
const repositoryFullName = input.repositoryFullName.toLowerCase();
|
|
1301
|
+
await db.insert(table).values({
|
|
1302
|
+
createdAt: input.createdAt,
|
|
1303
|
+
identityId: input.identityId,
|
|
1304
|
+
number: input.number,
|
|
1305
|
+
repositoryFullName,
|
|
1306
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1307
|
+
}).onConflictDoUpdate({
|
|
1308
|
+
target: [table.repositoryFullName, table.number, table.identityId],
|
|
1309
|
+
set: { createdAt: input.createdAt }
|
|
1310
|
+
});
|
|
1311
|
+
await db.delete(table).where(
|
|
1312
|
+
and(
|
|
1313
|
+
eq(table.repositoryFullName, repositoryFullName),
|
|
1314
|
+
eq(table.number, input.number),
|
|
1315
|
+
lt(table.createdAt, input.createdAt)
|
|
1316
|
+
)
|
|
1317
|
+
);
|
|
1318
|
+
}
|
|
1319
|
+
async function recordGitHubPullRequestRequester(db, input) {
|
|
1320
|
+
const now = /* @__PURE__ */ new Date();
|
|
1321
|
+
await db.insert(table).values({
|
|
1322
|
+
createdAt: now,
|
|
1323
|
+
identityId: input.identityId,
|
|
1324
|
+
number: input.number,
|
|
1325
|
+
repositoryFullName: input.repositoryFullName.toLowerCase(),
|
|
1326
|
+
updatedAt: now
|
|
1327
|
+
}).onConflictDoUpdate({
|
|
1328
|
+
target: [table.repositoryFullName, table.number, table.identityId],
|
|
1329
|
+
set: { updatedAt: now }
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
async function listGitHubPullRequestOpeners(db, input) {
|
|
1333
|
+
const openers = /* @__PURE__ */ new Map();
|
|
1334
|
+
if (input.numbers.length === 0) return openers;
|
|
1335
|
+
const rows = await db.select().from(table).where(
|
|
1336
|
+
and(
|
|
1337
|
+
eq(table.repositoryFullName, input.repositoryFullName.toLowerCase()),
|
|
1338
|
+
inArray(table.number, [...new Set(input.numbers)])
|
|
1339
|
+
)
|
|
1340
|
+
).orderBy(asc(table.createdAt));
|
|
1341
|
+
for (const row of rows) {
|
|
1342
|
+
if (!openers.has(row.number)) openers.set(row.number, row.identityId);
|
|
1343
|
+
}
|
|
1344
|
+
return openers;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
// src/tools/create-pull-request.ts
|
|
1176
1348
|
var GITHUB_PULL_REQUEST_CREATE_IDEMPOTENCY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1177
1349
|
var GITHUB_PULL_REQUEST_CREATE_LOCK_TTL_MS = 6e4;
|
|
1178
1350
|
var GitHubPullRequestCreateRejectedError = class extends Error {
|
|
@@ -1210,15 +1382,15 @@ var createPullRequestInputSchema = Type2.Object(
|
|
|
1210
1382
|
},
|
|
1211
1383
|
{ additionalProperties: false }
|
|
1212
1384
|
);
|
|
1213
|
-
var createPullRequestToolInputSchema =
|
|
1214
|
-
repo:
|
|
1215
|
-
title:
|
|
1216
|
-
head:
|
|
1217
|
-
base:
|
|
1218
|
-
body:
|
|
1385
|
+
var createPullRequestToolInputSchema = z6.object({
|
|
1386
|
+
repo: z6.string().describe('Repository in "owner/name" format.'),
|
|
1387
|
+
title: z6.string().describe("Pull request title."),
|
|
1388
|
+
head: z6.string().describe("Head branch or owner:branch ref."),
|
|
1389
|
+
base: z6.string().describe("Base branch."),
|
|
1390
|
+
body: z6.string().describe(
|
|
1219
1391
|
"Pull request body. The runtime appends the conversation footer."
|
|
1220
1392
|
).optional(),
|
|
1221
|
-
draft:
|
|
1393
|
+
draft: z6.boolean().describe("Whether to open the pull request as a draft.").optional()
|
|
1222
1394
|
}).strict();
|
|
1223
1395
|
var createPullRequestStateSchema = Type2.Union([
|
|
1224
1396
|
Type2.Object(
|
|
@@ -1243,15 +1415,15 @@ var createPullRequestStateSchema = Type2.Union([
|
|
|
1243
1415
|
{ additionalProperties: false }
|
|
1244
1416
|
)
|
|
1245
1417
|
]);
|
|
1246
|
-
var gitHubPullRequestDataSchema =
|
|
1247
|
-
number:
|
|
1248
|
-
url:
|
|
1418
|
+
var gitHubPullRequestDataSchema = z6.object({
|
|
1419
|
+
number: z6.number(),
|
|
1420
|
+
url: z6.string(),
|
|
1249
1421
|
subscribable: subscribableResourceSchema3.optional(),
|
|
1250
1422
|
subscription: watchResultSchema.optional()
|
|
1251
1423
|
});
|
|
1252
1424
|
var gitHubPullRequestOutputSchema = pluginToolOutputSchema4.merge(
|
|
1253
1425
|
gitHubPullRequestDataSchema.extend({
|
|
1254
|
-
target:
|
|
1426
|
+
target: z6.literal("createPullRequest")
|
|
1255
1427
|
})
|
|
1256
1428
|
);
|
|
1257
1429
|
function parseCreatePullRequestInput(input) {
|
|
@@ -1343,14 +1515,14 @@ function isDefinitiveGitHubPullRequestCreateRejection(error) {
|
|
|
1343
1515
|
}
|
|
1344
1516
|
return [400, 401, 404, 410, 422].includes(error.status);
|
|
1345
1517
|
}
|
|
1346
|
-
|
|
1518
|
+
function createGitHubPullRequestRequest(conversationId, input, ctx, requester, dashboardUrl) {
|
|
1347
1519
|
const repo = parseRepo4(input.repo);
|
|
1348
1520
|
const payload = {
|
|
1349
1521
|
title: nonEmptyString3(input.title, "title"),
|
|
1350
1522
|
head: nonEmptyString3(input.head, "head"),
|
|
1351
1523
|
base: nonEmptyString3(input.base, "base"),
|
|
1352
1524
|
body: appendGitHubFooter(
|
|
1353
|
-
|
|
1525
|
+
appendGitHubRequesterAttribution(input.body ?? "", ctx, requester),
|
|
1354
1526
|
conversationId,
|
|
1355
1527
|
dashboardUrl
|
|
1356
1528
|
),
|
|
@@ -1403,12 +1575,20 @@ async function createGitHubPullRequest(ctx, request) {
|
|
|
1403
1575
|
url: pullRequest.html_url
|
|
1404
1576
|
};
|
|
1405
1577
|
}
|
|
1406
|
-
async function
|
|
1407
|
-
if (!
|
|
1578
|
+
async function recordOpener(ctx, input, state, identityId) {
|
|
1579
|
+
if (!identityId) return;
|
|
1580
|
+
const repo = parseRepo4(input.repo);
|
|
1581
|
+
await recordGitHubPullRequestOpener(ctx.db, {
|
|
1582
|
+
createdAt: new Date(state.createdAtMs),
|
|
1583
|
+
identityId,
|
|
1584
|
+
number: state.number,
|
|
1585
|
+
repositoryFullName: `${repo.owner}/${repo.name}`
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
async function assignPullRequestRequester(ctx, input, result, requester) {
|
|
1589
|
+
const assignee = linkedGitHubLogin(requester?.user);
|
|
1590
|
+
if (!assignee) return;
|
|
1408
1591
|
try {
|
|
1409
|
-
const requester = await ctx.users.resolveActor();
|
|
1410
|
-
const assignee = linkedGitHubLogin(requester?.user);
|
|
1411
|
-
if (!assignee) return;
|
|
1412
1592
|
const repo = parseRepo4(input.repo);
|
|
1413
1593
|
const response = await ctx.egress.fetch({
|
|
1414
1594
|
provider: "github",
|
|
@@ -1443,11 +1623,12 @@ async function assignPullRequestRequester(ctx, input, result) {
|
|
|
1443
1623
|
}
|
|
1444
1624
|
function gitHubPullRequestToolResult(input, result, canSubscribe, omitSuggestedEvents) {
|
|
1445
1625
|
const repo = parseRepo4(input.repo);
|
|
1446
|
-
const subscribable =
|
|
1626
|
+
const subscribable = gitHubPullRequestSubscribable({
|
|
1627
|
+
canSubscribe,
|
|
1447
1628
|
number: result.number,
|
|
1448
1629
|
repo: `${repo.owner}/${repo.name}`,
|
|
1449
1630
|
...omitSuggestedEvents ? { omitSuggestedEvents } : void 0
|
|
1450
|
-
})
|
|
1631
|
+
});
|
|
1451
1632
|
return {
|
|
1452
1633
|
number: result.number,
|
|
1453
1634
|
url: result.url,
|
|
@@ -1538,6 +1719,12 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
1538
1719
|
const state = createPullRequestState(await ctx.state.get(key));
|
|
1539
1720
|
if (state?.status === "completed") {
|
|
1540
1721
|
const completedInput = state.input ?? parsedInput;
|
|
1722
|
+
await recordOpener(
|
|
1723
|
+
ctx,
|
|
1724
|
+
completedInput,
|
|
1725
|
+
state,
|
|
1726
|
+
(await resolveGitHubRequester(ctx))?.identity?.id
|
|
1727
|
+
);
|
|
1541
1728
|
const completedResult = {
|
|
1542
1729
|
facts: state.facts === void 0 ? void 0 : objectFactsSchema2.parse(state.facts),
|
|
1543
1730
|
sourceUpdatedAt: state.sourceUpdatedAt,
|
|
@@ -1557,10 +1744,13 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
1557
1744
|
"GitHub pull request creation for this tool call has an uncertain pending result; refusing to create a duplicate pull request."
|
|
1558
1745
|
);
|
|
1559
1746
|
}
|
|
1560
|
-
const
|
|
1747
|
+
const requester = await resolveGitHubRequester(ctx);
|
|
1748
|
+
const identityId = requester?.identity?.id;
|
|
1749
|
+
const request = createGitHubPullRequestRequest(
|
|
1561
1750
|
conversationId,
|
|
1562
1751
|
parsedInput,
|
|
1563
1752
|
ctx,
|
|
1753
|
+
requester,
|
|
1564
1754
|
ctx.slack?.conversationLink?.url
|
|
1565
1755
|
);
|
|
1566
1756
|
const pendingState = {
|
|
@@ -1599,7 +1789,8 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
1599
1789
|
{ cause: error }
|
|
1600
1790
|
);
|
|
1601
1791
|
}
|
|
1602
|
-
await
|
|
1792
|
+
await recordOpener(ctx, parsedInput, completedState, identityId);
|
|
1793
|
+
await assignPullRequestRequester(ctx, parsedInput, result, requester);
|
|
1603
1794
|
return await gitHubPullRequestStructuredResult(
|
|
1604
1795
|
ctx,
|
|
1605
1796
|
parsedInput,
|
|
@@ -1618,28 +1809,28 @@ import {
|
|
|
1618
1809
|
PluginToolInputError as PluginToolInputError6,
|
|
1619
1810
|
pluginToolOutputSchema as pluginToolOutputSchema5
|
|
1620
1811
|
} from "@sentry/junior-plugin-api";
|
|
1621
|
-
import { z as
|
|
1812
|
+
import { z as z7 } from "zod";
|
|
1622
1813
|
import { subscribableResourceSchema as subscribableResourceSchema4 } from "@sentry/junior-plugin-api";
|
|
1623
|
-
var commitShaSchema2 =
|
|
1624
|
-
var inputSchema3 =
|
|
1625
|
-
repo:
|
|
1626
|
-
number:
|
|
1814
|
+
var commitShaSchema2 = z7.string().regex(/^[0-9a-f]{40}$/i);
|
|
1815
|
+
var inputSchema3 = z7.object({
|
|
1816
|
+
repo: z7.string().describe('Repository in "owner/name" format.'),
|
|
1817
|
+
number: z7.number().int().positive().describe("Pull request number.")
|
|
1627
1818
|
}).strict();
|
|
1628
|
-
var pullRequestSchema =
|
|
1629
|
-
base:
|
|
1630
|
-
draft:
|
|
1631
|
-
head:
|
|
1819
|
+
var pullRequestSchema = z7.object({
|
|
1820
|
+
base: z7.string(),
|
|
1821
|
+
draft: z7.boolean(),
|
|
1822
|
+
head: z7.string(),
|
|
1632
1823
|
headSha: commitShaSchema2,
|
|
1633
|
-
merged:
|
|
1634
|
-
number:
|
|
1635
|
-
state:
|
|
1824
|
+
merged: z7.boolean(),
|
|
1825
|
+
number: z7.number(),
|
|
1826
|
+
state: z7.string(),
|
|
1636
1827
|
subscribable: subscribableResourceSchema4.optional(),
|
|
1637
|
-
title:
|
|
1638
|
-
url:
|
|
1828
|
+
title: z7.string(),
|
|
1829
|
+
url: z7.string()
|
|
1639
1830
|
});
|
|
1640
1831
|
var outputSchema3 = pluginToolOutputSchema5.merge(
|
|
1641
1832
|
pullRequestSchema.extend({
|
|
1642
|
-
target:
|
|
1833
|
+
target: z7.literal("getPullRequest")
|
|
1643
1834
|
})
|
|
1644
1835
|
);
|
|
1645
1836
|
function parseRepo5(value) {
|
|
@@ -1692,20 +1883,21 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
1692
1883
|
}
|
|
1693
1884
|
throw new Error(message);
|
|
1694
1885
|
}
|
|
1695
|
-
const providerResult =
|
|
1696
|
-
base:
|
|
1697
|
-
draft:
|
|
1698
|
-
head:
|
|
1699
|
-
html_url:
|
|
1700
|
-
merged:
|
|
1701
|
-
number:
|
|
1702
|
-
state:
|
|
1703
|
-
title:
|
|
1886
|
+
const providerResult = z7.object({
|
|
1887
|
+
base: z7.object({ ref: z7.string() }),
|
|
1888
|
+
draft: z7.boolean(),
|
|
1889
|
+
head: z7.object({ ref: z7.string(), sha: commitShaSchema2 }),
|
|
1890
|
+
html_url: z7.string(),
|
|
1891
|
+
merged: z7.boolean().optional().default(false),
|
|
1892
|
+
number: z7.number(),
|
|
1893
|
+
state: z7.string(),
|
|
1894
|
+
title: z7.string()
|
|
1704
1895
|
}).parse(parsed);
|
|
1705
|
-
const subscribable =
|
|
1896
|
+
const subscribable = gitHubPullRequestSubscribable({
|
|
1897
|
+
canSubscribe: ctx.events.canSubscribe,
|
|
1706
1898
|
number: providerResult.number,
|
|
1707
1899
|
repo: repo.ref
|
|
1708
|
-
})
|
|
1900
|
+
});
|
|
1709
1901
|
const data = {
|
|
1710
1902
|
base: providerResult.base.ref,
|
|
1711
1903
|
draft: providerResult.draft,
|
|
@@ -1744,45 +1936,45 @@ import {
|
|
|
1744
1936
|
pluginToolOutputSchema as pluginToolOutputSchema6,
|
|
1745
1937
|
subscribableResourceSchema as subscribableResourceSchema5
|
|
1746
1938
|
} from "@sentry/junior-plugin-api";
|
|
1747
|
-
import { z as
|
|
1748
|
-
var inputSchema4 =
|
|
1749
|
-
repo:
|
|
1750
|
-
tag:
|
|
1939
|
+
import { z as z8 } from "zod";
|
|
1940
|
+
var inputSchema4 = z8.object({
|
|
1941
|
+
repo: z8.string().describe('Repository in "owner/name" format.'),
|
|
1942
|
+
tag: z8.string().trim().min(1).describe(
|
|
1751
1943
|
"Optional release tag name. Omit to inspect and watch every published release in the repository."
|
|
1752
1944
|
).optional()
|
|
1753
1945
|
}).strict();
|
|
1754
|
-
var releaseSchema =
|
|
1755
|
-
createdAt:
|
|
1756
|
-
draft:
|
|
1757
|
-
htmlUrl:
|
|
1758
|
-
id:
|
|
1759
|
-
name:
|
|
1760
|
-
prerelease:
|
|
1761
|
-
publishedAt:
|
|
1762
|
-
tagName:
|
|
1763
|
-
targetCommitish:
|
|
1946
|
+
var releaseSchema = z8.object({
|
|
1947
|
+
createdAt: z8.string(),
|
|
1948
|
+
draft: z8.boolean(),
|
|
1949
|
+
htmlUrl: z8.string(),
|
|
1950
|
+
id: z8.number(),
|
|
1951
|
+
name: z8.string().nullable(),
|
|
1952
|
+
prerelease: z8.boolean(),
|
|
1953
|
+
publishedAt: z8.string().nullable(),
|
|
1954
|
+
tagName: z8.string(),
|
|
1955
|
+
targetCommitish: z8.string()
|
|
1764
1956
|
}).strict();
|
|
1765
|
-
var releaseSourceSchema =
|
|
1957
|
+
var releaseSourceSchema = z8.object({
|
|
1766
1958
|
release: releaseSchema.nullable(),
|
|
1767
|
-
repo:
|
|
1959
|
+
repo: z8.string(),
|
|
1768
1960
|
subscribable: subscribableResourceSchema5.optional(),
|
|
1769
|
-
tag:
|
|
1961
|
+
tag: z8.string().nullable()
|
|
1770
1962
|
}).strict();
|
|
1771
1963
|
var outputSchema4 = pluginToolOutputSchema6.merge(
|
|
1772
1964
|
releaseSourceSchema.extend({
|
|
1773
|
-
target:
|
|
1965
|
+
target: z8.literal("getRelease")
|
|
1774
1966
|
})
|
|
1775
1967
|
);
|
|
1776
|
-
var providerReleaseSchema =
|
|
1777
|
-
created_at:
|
|
1778
|
-
draft:
|
|
1779
|
-
html_url:
|
|
1780
|
-
id:
|
|
1781
|
-
name:
|
|
1782
|
-
prerelease:
|
|
1783
|
-
published_at:
|
|
1784
|
-
tag_name:
|
|
1785
|
-
target_commitish:
|
|
1968
|
+
var providerReleaseSchema = z8.object({
|
|
1969
|
+
created_at: z8.string(),
|
|
1970
|
+
draft: z8.boolean(),
|
|
1971
|
+
html_url: z8.string(),
|
|
1972
|
+
id: z8.number(),
|
|
1973
|
+
name: z8.string().nullable(),
|
|
1974
|
+
prerelease: z8.boolean(),
|
|
1975
|
+
published_at: z8.string().nullable(),
|
|
1976
|
+
tag_name: z8.string(),
|
|
1977
|
+
target_commitish: z8.string()
|
|
1786
1978
|
}).passthrough();
|
|
1787
1979
|
function parseRepo6(value) {
|
|
1788
1980
|
const parts = value.split("/").map((part) => part.trim());
|
|
@@ -1875,10 +2067,11 @@ function createGitHubGetReleaseTool(ctx) {
|
|
|
1875
2067
|
);
|
|
1876
2068
|
}
|
|
1877
2069
|
}
|
|
1878
|
-
const subscribable =
|
|
2070
|
+
const subscribable = gitHubReleaseSourceSubscribable({
|
|
2071
|
+
canSubscribe: ctx.events.canSubscribe,
|
|
1879
2072
|
repo: repo.ref,
|
|
1880
2073
|
tag
|
|
1881
|
-
})
|
|
2074
|
+
});
|
|
1882
2075
|
const data = {
|
|
1883
2076
|
release,
|
|
1884
2077
|
repo: repo.ref,
|
|
@@ -1900,21 +2093,21 @@ import {
|
|
|
1900
2093
|
pluginToolOutputSchema as pluginToolOutputSchema7,
|
|
1901
2094
|
subscribableResourceSchema as subscribableResourceSchema6
|
|
1902
2095
|
} from "@sentry/junior-plugin-api";
|
|
1903
|
-
import { z as
|
|
1904
|
-
var inputSchema5 =
|
|
1905
|
-
repo:
|
|
2096
|
+
import { z as z9 } from "zod";
|
|
2097
|
+
var inputSchema5 = z9.object({
|
|
2098
|
+
repo: z9.string().describe('Repository in "owner/name" format.')
|
|
1906
2099
|
}).strict();
|
|
1907
|
-
var repositorySchema =
|
|
1908
|
-
defaultBranch:
|
|
1909
|
-
description:
|
|
1910
|
-
fullName:
|
|
1911
|
-
private:
|
|
2100
|
+
var repositorySchema = z9.object({
|
|
2101
|
+
defaultBranch: z9.string(),
|
|
2102
|
+
description: z9.string().nullable(),
|
|
2103
|
+
fullName: z9.string(),
|
|
2104
|
+
private: z9.boolean(),
|
|
1912
2105
|
subscribable: subscribableResourceSchema6.optional(),
|
|
1913
|
-
url:
|
|
2106
|
+
url: z9.string()
|
|
1914
2107
|
});
|
|
1915
2108
|
var outputSchema5 = pluginToolOutputSchema7.merge(
|
|
1916
2109
|
repositorySchema.extend({
|
|
1917
|
-
target:
|
|
2110
|
+
target: z9.literal("getRepository")
|
|
1918
2111
|
})
|
|
1919
2112
|
);
|
|
1920
2113
|
function parseRepo7(value) {
|
|
@@ -1965,16 +2158,17 @@ function createGitHubGetRepositoryTool(ctx) {
|
|
|
1965
2158
|
`GitHub repository lookup failed with HTTP ${response.status}`
|
|
1966
2159
|
);
|
|
1967
2160
|
}
|
|
1968
|
-
const providerResult =
|
|
1969
|
-
default_branch:
|
|
1970
|
-
description:
|
|
1971
|
-
full_name:
|
|
1972
|
-
html_url:
|
|
1973
|
-
private:
|
|
2161
|
+
const providerResult = z9.object({
|
|
2162
|
+
default_branch: z9.string(),
|
|
2163
|
+
description: z9.string().nullable(),
|
|
2164
|
+
full_name: z9.string(),
|
|
2165
|
+
html_url: z9.string(),
|
|
2166
|
+
private: z9.boolean()
|
|
1974
2167
|
}).parse(parsed);
|
|
1975
|
-
const subscribable =
|
|
2168
|
+
const subscribable = gitHubRepositorySubscribable({
|
|
2169
|
+
canSubscribe: ctx.events.canSubscribe,
|
|
1976
2170
|
repo: providerResult.full_name
|
|
1977
|
-
})
|
|
2171
|
+
});
|
|
1978
2172
|
const data = {
|
|
1979
2173
|
defaultBranch: providerResult.default_branch,
|
|
1980
2174
|
description: providerResult.description,
|
|
@@ -1998,30 +2192,30 @@ import {
|
|
|
1998
2192
|
pluginToolOutputSchema as pluginToolOutputSchema8,
|
|
1999
2193
|
subscribableResourceSchema as subscribableResourceSchema7
|
|
2000
2194
|
} from "@sentry/junior-plugin-api";
|
|
2001
|
-
import { z as
|
|
2002
|
-
var inputSchema6 =
|
|
2003
|
-
repo:
|
|
2004
|
-
number:
|
|
2005
|
-
title:
|
|
2006
|
-
body:
|
|
2195
|
+
import { z as z10 } from "zod";
|
|
2196
|
+
var inputSchema6 = z10.object({
|
|
2197
|
+
repo: z10.string().describe('Repository in "owner/name" format.'),
|
|
2198
|
+
number: z10.number().int().positive().describe("Issue number."),
|
|
2199
|
+
title: z10.string().trim().min(1).optional().describe("Replacement issue title."),
|
|
2200
|
+
body: z10.string().optional().describe(
|
|
2007
2201
|
"Replacement issue body. The runtime appends requester attribution and the conversation footer."
|
|
2008
2202
|
),
|
|
2009
|
-
state:
|
|
2203
|
+
state: z10.enum(["open", "closed"]).optional().describe("Replacement issue state.")
|
|
2010
2204
|
}).strict().refine(
|
|
2011
2205
|
({ title, body, state }) => title !== void 0 || body !== void 0 || state !== void 0,
|
|
2012
2206
|
{ message: "At least one issue field must be provided." }
|
|
2013
2207
|
);
|
|
2014
|
-
var issueSchema =
|
|
2015
|
-
body:
|
|
2016
|
-
number:
|
|
2017
|
-
state:
|
|
2208
|
+
var issueSchema = z10.object({
|
|
2209
|
+
body: z10.string().nullable(),
|
|
2210
|
+
number: z10.number(),
|
|
2211
|
+
state: z10.string(),
|
|
2018
2212
|
subscribable: subscribableResourceSchema7.optional(),
|
|
2019
|
-
title:
|
|
2020
|
-
url:
|
|
2213
|
+
title: z10.string(),
|
|
2214
|
+
url: z10.string()
|
|
2021
2215
|
});
|
|
2022
2216
|
var outputSchema6 = pluginToolOutputSchema8.merge(
|
|
2023
2217
|
issueSchema.extend({
|
|
2024
|
-
target:
|
|
2218
|
+
target: z10.literal("updateIssue")
|
|
2025
2219
|
})
|
|
2026
2220
|
);
|
|
2027
2221
|
function nonEmptyString4(value, name) {
|
|
@@ -2076,7 +2270,11 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2076
2270
|
...update.title !== void 0 ? { title: update.title } : void 0,
|
|
2077
2271
|
...update.body !== void 0 ? {
|
|
2078
2272
|
body: appendGitHubFooter(
|
|
2079
|
-
|
|
2273
|
+
appendGitHubRequesterAttribution(
|
|
2274
|
+
update.body,
|
|
2275
|
+
ctx,
|
|
2276
|
+
await resolveGitHubRequester(ctx)
|
|
2277
|
+
),
|
|
2080
2278
|
nonEmptyString4(ctx.conversationId, "conversationId"),
|
|
2081
2279
|
ctx.slack?.conversationLink?.url
|
|
2082
2280
|
)
|
|
@@ -2105,17 +2303,18 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2105
2303
|
`GitHub issue update failed with HTTP ${response.status}: ${githubApiErrorMessage3(parsed)}`
|
|
2106
2304
|
);
|
|
2107
2305
|
}
|
|
2108
|
-
const providerResult =
|
|
2109
|
-
body:
|
|
2110
|
-
html_url:
|
|
2111
|
-
number:
|
|
2112
|
-
state:
|
|
2113
|
-
title:
|
|
2306
|
+
const providerResult = z10.object({
|
|
2307
|
+
body: z10.string().nullable().optional().default(null),
|
|
2308
|
+
html_url: z10.string(),
|
|
2309
|
+
number: z10.number(),
|
|
2310
|
+
state: z10.string(),
|
|
2311
|
+
title: z10.string()
|
|
2114
2312
|
}).parse(parsed);
|
|
2115
|
-
const subscribable =
|
|
2313
|
+
const subscribable = gitHubIssueSubscribable({
|
|
2314
|
+
canSubscribe: ctx.events.canSubscribe,
|
|
2116
2315
|
number: providerResult.number,
|
|
2117
2316
|
repo: repo.ref
|
|
2118
|
-
})
|
|
2317
|
+
});
|
|
2119
2318
|
return {
|
|
2120
2319
|
objectAnnotations: [
|
|
2121
2320
|
githubObjectAnnotation({
|
|
@@ -2146,18 +2345,18 @@ import {
|
|
|
2146
2345
|
PluginToolInputError as PluginToolInputError10,
|
|
2147
2346
|
pluginToolOutputSchema as pluginToolOutputSchema9
|
|
2148
2347
|
} from "@sentry/junior-plugin-api";
|
|
2149
|
-
import { z as
|
|
2348
|
+
import { z as z11 } from "zod";
|
|
2150
2349
|
import { subscribableResourceSchema as subscribableResourceSchema8 } from "@sentry/junior-plugin-api";
|
|
2151
|
-
var inputSchema7 =
|
|
2152
|
-
repo:
|
|
2153
|
-
number:
|
|
2154
|
-
title:
|
|
2155
|
-
body:
|
|
2350
|
+
var inputSchema7 = z11.object({
|
|
2351
|
+
repo: z11.string().describe('Repository in "owner/name" format.'),
|
|
2352
|
+
number: z11.number().int().positive().describe("Pull request number."),
|
|
2353
|
+
title: z11.string().trim().min(1).optional().describe("Replacement pull request title."),
|
|
2354
|
+
body: z11.string().optional().describe(
|
|
2156
2355
|
"Replacement pull request body. The runtime appends requester attribution and the conversation footer."
|
|
2157
2356
|
),
|
|
2158
|
-
base:
|
|
2159
|
-
state:
|
|
2160
|
-
draft:
|
|
2357
|
+
base: z11.string().trim().min(1).optional().describe("Replacement base branch."),
|
|
2358
|
+
state: z11.enum(["open", "closed"]).optional().describe("Replacement pull request state."),
|
|
2359
|
+
draft: z11.boolean().optional().describe(
|
|
2161
2360
|
"Set false to mark a draft pull request ready for review, or true to convert it back to a draft."
|
|
2162
2361
|
)
|
|
2163
2362
|
}).strict().refine(
|
|
@@ -2172,27 +2371,27 @@ var CONVERT_TO_DRAFT = {
|
|
|
2172
2371
|
operationName: "ConvertPullRequestToDraft",
|
|
2173
2372
|
query: "mutation ConvertPullRequestToDraft($id: ID!) { result: convertPullRequestToDraft(input: {pullRequestId: $id}) { pullRequest { isDraft } } }"
|
|
2174
2373
|
};
|
|
2175
|
-
var draftMutationResponseSchema =
|
|
2176
|
-
data:
|
|
2177
|
-
result:
|
|
2374
|
+
var draftMutationResponseSchema = z11.object({
|
|
2375
|
+
data: z11.object({
|
|
2376
|
+
result: z11.object({ pullRequest: z11.object({ isDraft: z11.boolean() }) })
|
|
2178
2377
|
})
|
|
2179
2378
|
});
|
|
2180
|
-
var graphqlErrorsSchema =
|
|
2181
|
-
errors:
|
|
2379
|
+
var graphqlErrorsSchema = z11.object({
|
|
2380
|
+
errors: z11.array(z11.object({ message: z11.string() })).min(1)
|
|
2182
2381
|
});
|
|
2183
|
-
var pullRequestSchema2 =
|
|
2184
|
-
base:
|
|
2185
|
-
body:
|
|
2186
|
-
draft:
|
|
2187
|
-
number:
|
|
2188
|
-
state:
|
|
2382
|
+
var pullRequestSchema2 = z11.object({
|
|
2383
|
+
base: z11.string(),
|
|
2384
|
+
body: z11.string().nullable(),
|
|
2385
|
+
draft: z11.boolean(),
|
|
2386
|
+
number: z11.number(),
|
|
2387
|
+
state: z11.string(),
|
|
2189
2388
|
subscribable: subscribableResourceSchema8.optional(),
|
|
2190
|
-
title:
|
|
2191
|
-
url:
|
|
2389
|
+
title: z11.string(),
|
|
2390
|
+
url: z11.string()
|
|
2192
2391
|
});
|
|
2193
2392
|
var outputSchema7 = pluginToolOutputSchema9.merge(
|
|
2194
2393
|
pullRequestSchema2.extend({
|
|
2195
|
-
target:
|
|
2394
|
+
target: z11.literal("updatePullRequest")
|
|
2196
2395
|
})
|
|
2197
2396
|
);
|
|
2198
2397
|
function nonEmptyString5(value, name) {
|
|
@@ -2274,11 +2473,12 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2274
2473
|
}
|
|
2275
2474
|
const update = parsedInput.data;
|
|
2276
2475
|
const repo = parseRepo9(update.repo);
|
|
2476
|
+
const requester = await resolveGitHubRequester(ctx);
|
|
2277
2477
|
const payload = {
|
|
2278
2478
|
...update.title !== void 0 ? { title: update.title } : void 0,
|
|
2279
2479
|
...update.body !== void 0 ? {
|
|
2280
2480
|
body: appendGitHubFooter(
|
|
2281
|
-
|
|
2481
|
+
appendGitHubRequesterAttribution(update.body, ctx, requester),
|
|
2282
2482
|
nonEmptyString5(ctx.conversationId, "conversationId"),
|
|
2283
2483
|
ctx.slack?.conversationLink?.url
|
|
2284
2484
|
)
|
|
@@ -2307,16 +2507,16 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2307
2507
|
`GitHub pull request update failed with HTTP ${response.status}: ${githubApiErrorMessage4(parsed)}`
|
|
2308
2508
|
);
|
|
2309
2509
|
}
|
|
2310
|
-
const providerResult =
|
|
2311
|
-
base:
|
|
2312
|
-
body:
|
|
2313
|
-
draft:
|
|
2314
|
-
html_url:
|
|
2315
|
-
merged:
|
|
2316
|
-
node_id:
|
|
2317
|
-
number:
|
|
2318
|
-
state:
|
|
2319
|
-
title:
|
|
2510
|
+
const providerResult = z11.object({
|
|
2511
|
+
base: z11.object({ ref: z11.string() }),
|
|
2512
|
+
body: z11.string().nullable().optional().default(null),
|
|
2513
|
+
draft: z11.boolean(),
|
|
2514
|
+
html_url: z11.string(),
|
|
2515
|
+
merged: z11.boolean(),
|
|
2516
|
+
node_id: z11.string().optional(),
|
|
2517
|
+
number: z11.number(),
|
|
2518
|
+
state: z11.string(),
|
|
2519
|
+
title: z11.string()
|
|
2320
2520
|
}).parse(parsed);
|
|
2321
2521
|
if (update.draft !== void 0 && update.draft !== providerResult.draft) {
|
|
2322
2522
|
if (!providerResult.node_id) {
|
|
@@ -2331,10 +2531,18 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2331
2531
|
repo: repo.ref
|
|
2332
2532
|
});
|
|
2333
2533
|
}
|
|
2334
|
-
|
|
2534
|
+
if (requester?.identity) {
|
|
2535
|
+
await recordGitHubPullRequestRequester(ctx.db, {
|
|
2536
|
+
identityId: requester.identity.id,
|
|
2537
|
+
number: providerResult.number,
|
|
2538
|
+
repositoryFullName: repo.ref
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
const subscribable = gitHubPullRequestSubscribable({
|
|
2542
|
+
canSubscribe: ctx.events.canSubscribe,
|
|
2335
2543
|
number: providerResult.number,
|
|
2336
2544
|
repo: repo.ref
|
|
2337
|
-
})
|
|
2545
|
+
});
|
|
2338
2546
|
const data = {
|
|
2339
2547
|
base: providerResult.base.ref,
|
|
2340
2548
|
body: providerResult.body,
|
|
@@ -2373,7 +2581,7 @@ import {
|
|
|
2373
2581
|
PluginToolInputError as PluginToolInputError11,
|
|
2374
2582
|
pluginToolOutputSchema as pluginToolOutputSchema10
|
|
2375
2583
|
} from "@sentry/junior-plugin-api";
|
|
2376
|
-
import { z as
|
|
2584
|
+
import { z as z12 } from "zod";
|
|
2377
2585
|
var STATUS_TO_REACTION_CONTENT = {
|
|
2378
2586
|
reviewing: "eyes",
|
|
2379
2587
|
addressed: "+1",
|
|
@@ -2382,24 +2590,24 @@ var STATUS_TO_REACTION_CONTENT = {
|
|
|
2382
2590
|
var FEEDBACK_REACTION_CONTENTS = new Set(
|
|
2383
2591
|
Object.values(STATUS_TO_REACTION_CONTENT)
|
|
2384
2592
|
);
|
|
2385
|
-
var inputSchema8 =
|
|
2386
|
-
repo:
|
|
2387
|
-
commentKind:
|
|
2593
|
+
var inputSchema8 = z12.object({
|
|
2594
|
+
repo: z12.string().describe('Repository in "owner/name" format.'),
|
|
2595
|
+
commentKind: z12.enum(["conversation", "review"]).describe(
|
|
2388
2596
|
'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment.'
|
|
2389
2597
|
),
|
|
2390
|
-
commentId:
|
|
2598
|
+
commentId: z12.number().int().positive().describe(
|
|
2391
2599
|
"GitHub comment id (conversation comment id or inline review comment id)."
|
|
2392
2600
|
),
|
|
2393
|
-
status:
|
|
2601
|
+
status: z12.enum(["addressed", "declined"]).describe(
|
|
2394
2602
|
"Feedback outcome. Maps to a reaction: addressed -> +1, declined -> -1."
|
|
2395
2603
|
)
|
|
2396
2604
|
}).strict();
|
|
2397
2605
|
var outputSchema8 = pluginToolOutputSchema10.extend({
|
|
2398
|
-
target:
|
|
2399
|
-
repo:
|
|
2400
|
-
commentId:
|
|
2401
|
-
status:
|
|
2402
|
-
reactionId:
|
|
2606
|
+
target: z12.literal("updatePullRequestFeedback"),
|
|
2607
|
+
repo: z12.string(),
|
|
2608
|
+
commentId: z12.number(),
|
|
2609
|
+
status: z12.enum(["addressed", "declined"]),
|
|
2610
|
+
reactionId: z12.number()
|
|
2403
2611
|
});
|
|
2404
2612
|
function parseRepo10(value) {
|
|
2405
2613
|
const parts = value.split("/").map((part) => part.trim());
|
|
@@ -2431,10 +2639,10 @@ function githubError(payload) {
|
|
|
2431
2639
|
}
|
|
2432
2640
|
return "GitHub request failed";
|
|
2433
2641
|
}
|
|
2434
|
-
var reactionSchema =
|
|
2435
|
-
id:
|
|
2436
|
-
content:
|
|
2437
|
-
user:
|
|
2642
|
+
var reactionSchema = z12.object({
|
|
2643
|
+
id: z12.number(),
|
|
2644
|
+
content: z12.string(),
|
|
2645
|
+
user: z12.object({ id: z12.number() }).nullable()
|
|
2438
2646
|
});
|
|
2439
2647
|
function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
2440
2648
|
return definePluginTool10({
|
|
@@ -2444,7 +2652,7 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
2444
2652
|
openWorldHint: true,
|
|
2445
2653
|
readOnlyHint: false
|
|
2446
2654
|
},
|
|
2447
|
-
description: "Set
|
|
2655
|
+
description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1). Use the commentId and commentKind from the event after acting on the feedback. Replaces only your prior status reaction on that comment.",
|
|
2448
2656
|
exposure: "direct",
|
|
2449
2657
|
inputSchema: inputSchema8,
|
|
2450
2658
|
outputSchema: outputSchema8,
|
|
@@ -2482,7 +2690,7 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
2482
2690
|
`GitHub reaction lookup failed with HTTP ${listResponse.status}: ${githubError(listPayload)}`
|
|
2483
2691
|
);
|
|
2484
2692
|
}
|
|
2485
|
-
const botReactions =
|
|
2693
|
+
const botReactions = z12.array(reactionSchema).parse(listPayload).filter(
|
|
2486
2694
|
(reaction) => reaction.user?.id === botUserId && FEEDBACK_REACTION_CONTENTS.has(reaction.content)
|
|
2487
2695
|
);
|
|
2488
2696
|
const existing = botReactions.find(
|
|
@@ -2549,21 +2757,21 @@ import {
|
|
|
2549
2757
|
PluginToolInputError as PluginToolInputError12,
|
|
2550
2758
|
pluginToolOutputSchema as pluginToolOutputSchema11
|
|
2551
2759
|
} from "@sentry/junior-plugin-api";
|
|
2552
|
-
import { z as
|
|
2553
|
-
var inputSchema9 =
|
|
2554
|
-
repo:
|
|
2760
|
+
import { z as z13 } from "zod";
|
|
2761
|
+
var inputSchema9 = z13.object({
|
|
2762
|
+
repo: z13.string().describe(
|
|
2555
2763
|
'Repository in "owner/name" format. Required because GraphQL has no repo path.'
|
|
2556
2764
|
),
|
|
2557
|
-
threadId:
|
|
2765
|
+
threadId: z13.string().trim().min(1).describe(
|
|
2558
2766
|
"GitHub pull request review thread node ID (the same `threadId` / `id` variable used by `gh api graphql` resolveReviewThread)."
|
|
2559
2767
|
)
|
|
2560
2768
|
}).strict();
|
|
2561
2769
|
var outputSchema9 = pluginToolOutputSchema11.extend({
|
|
2562
|
-
target:
|
|
2563
|
-
repo:
|
|
2564
|
-
number:
|
|
2565
|
-
threadId:
|
|
2566
|
-
resolved:
|
|
2770
|
+
target: z13.literal("resolvePullRequestReviewThread"),
|
|
2771
|
+
repo: z13.string(),
|
|
2772
|
+
number: z13.number(),
|
|
2773
|
+
threadId: z13.string(),
|
|
2774
|
+
resolved: z13.boolean()
|
|
2567
2775
|
});
|
|
2568
2776
|
function parseRepo11(value) {
|
|
2569
2777
|
const parts = value.split("/").map((part) => part.trim());
|
|
@@ -2645,18 +2853,18 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
2645
2853
|
`GitHub review thread lookup failed with HTTP ${lookupResponse.status}: ${githubError2(lookupPayload)}`
|
|
2646
2854
|
);
|
|
2647
2855
|
}
|
|
2648
|
-
const threadNodeSchema =
|
|
2649
|
-
id:
|
|
2650
|
-
isResolved:
|
|
2651
|
-
pullRequest:
|
|
2652
|
-
author:
|
|
2653
|
-
number:
|
|
2654
|
-
repository:
|
|
2856
|
+
const threadNodeSchema = z13.object({
|
|
2857
|
+
id: z13.string(),
|
|
2858
|
+
isResolved: z13.boolean(),
|
|
2859
|
+
pullRequest: z13.object({
|
|
2860
|
+
author: z13.object({ databaseId: z13.number().optional() }).passthrough().nullable(),
|
|
2861
|
+
number: z13.number(),
|
|
2862
|
+
repository: z13.object({ nameWithOwner: z13.string() }).passthrough()
|
|
2655
2863
|
}).passthrough()
|
|
2656
2864
|
}).passthrough();
|
|
2657
|
-
const lookupResultSchema =
|
|
2658
|
-
data:
|
|
2659
|
-
node:
|
|
2865
|
+
const lookupResultSchema = z13.object({
|
|
2866
|
+
data: z13.object({
|
|
2867
|
+
node: z13.unknown().nullable().optional()
|
|
2660
2868
|
}).passthrough()
|
|
2661
2869
|
}).passthrough();
|
|
2662
2870
|
const lookupResult = lookupResultSchema.safeParse(lookupPayload);
|
|
@@ -2706,10 +2914,10 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
2706
2914
|
`GitHub review thread resolution failed with HTTP ${resolveResponse.status}: ${githubError2(resolvePayload)}`
|
|
2707
2915
|
);
|
|
2708
2916
|
}
|
|
2709
|
-
const resolveResultSchema =
|
|
2710
|
-
data:
|
|
2711
|
-
resolveReviewThread:
|
|
2712
|
-
thread:
|
|
2917
|
+
const resolveResultSchema = z13.object({
|
|
2918
|
+
data: z13.object({
|
|
2919
|
+
resolveReviewThread: z13.object({
|
|
2920
|
+
thread: z13.object({ id: z13.string(), isResolved: z13.boolean() }).passthrough()
|
|
2713
2921
|
}).passthrough()
|
|
2714
2922
|
}).passthrough()
|
|
2715
2923
|
}).passthrough();
|
|
@@ -2741,32 +2949,32 @@ import {
|
|
|
2741
2949
|
PluginToolInputError as PluginToolInputError13,
|
|
2742
2950
|
pluginToolOutputSchema as pluginToolOutputSchema12
|
|
2743
2951
|
} from "@sentry/junior-plugin-api";
|
|
2744
|
-
import { z as
|
|
2745
|
-
var reviewCommentSchema =
|
|
2746
|
-
path:
|
|
2747
|
-
body:
|
|
2748
|
-
line:
|
|
2749
|
-
side:
|
|
2750
|
-
startLine:
|
|
2751
|
-
startSide:
|
|
2952
|
+
import { z as z14 } from "zod";
|
|
2953
|
+
var reviewCommentSchema = z14.object({
|
|
2954
|
+
path: z14.string().trim().min(1).describe("File path in the pull request."),
|
|
2955
|
+
body: z14.string().trim().min(1).describe("Inline review comment."),
|
|
2956
|
+
line: z14.number().int().positive().describe("Line in the pull request diff."),
|
|
2957
|
+
side: z14.enum(["LEFT", "RIGHT"]).describe("Side of the pull request diff."),
|
|
2958
|
+
startLine: z14.number().int().positive().optional().describe("First line of a multi-line comment."),
|
|
2959
|
+
startSide: z14.enum(["LEFT", "RIGHT"]).optional().describe("First side of a multi-line comment.")
|
|
2752
2960
|
}).strict().refine(
|
|
2753
2961
|
({ startLine, startSide }) => startLine === void 0 === (startSide === void 0),
|
|
2754
2962
|
{ message: "startLine and startSide must be provided together." }
|
|
2755
2963
|
);
|
|
2756
|
-
var inputSchema10 =
|
|
2757
|
-
repo:
|
|
2758
|
-
number:
|
|
2759
|
-
event:
|
|
2760
|
-
body:
|
|
2761
|
-
comments:
|
|
2964
|
+
var inputSchema10 = z14.object({
|
|
2965
|
+
repo: z14.string().describe('Repository in "owner/name" format.'),
|
|
2966
|
+
number: z14.number().int().positive().describe("Pull request number."),
|
|
2967
|
+
event: z14.enum(["COMMENT", "REQUEST_CHANGES"]).describe("Review result. You cannot approve pull requests."),
|
|
2968
|
+
body: z14.string().trim().min(1).describe("Review summary."),
|
|
2969
|
+
comments: z14.array(reviewCommentSchema).optional().describe("Optional inline review comments.")
|
|
2762
2970
|
}).strict();
|
|
2763
2971
|
var outputSchema10 = pluginToolOutputSchema12.extend({
|
|
2764
|
-
target:
|
|
2765
|
-
repo:
|
|
2766
|
-
number:
|
|
2767
|
-
reviewId:
|
|
2768
|
-
state:
|
|
2769
|
-
url:
|
|
2972
|
+
target: z14.literal("submitPullRequestReview"),
|
|
2973
|
+
repo: z14.string(),
|
|
2974
|
+
number: z14.number(),
|
|
2975
|
+
reviewId: z14.number(),
|
|
2976
|
+
state: z14.string(),
|
|
2977
|
+
url: z14.string()
|
|
2770
2978
|
});
|
|
2771
2979
|
function parseRepo12(value) {
|
|
2772
2980
|
const parts = value.split("/").map((part) => part.trim());
|
|
@@ -2807,7 +3015,7 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
2807
3015
|
openWorldHint: true,
|
|
2808
3016
|
readOnlyHint: false
|
|
2809
3017
|
},
|
|
2810
|
-
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.
|
|
3018
|
+
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.",
|
|
2811
3019
|
exposure: "direct",
|
|
2812
3020
|
inputSchema: inputSchema10,
|
|
2813
3021
|
outputSchema: outputSchema10,
|
|
@@ -2845,7 +3053,7 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
2845
3053
|
if (!response.ok) {
|
|
2846
3054
|
throwReviewError(response.status, parsed);
|
|
2847
3055
|
}
|
|
2848
|
-
const providerResult =
|
|
3056
|
+
const providerResult = z14.object({ id: z14.number(), html_url: z14.string(), state: z14.string() }).parse(parsed);
|
|
2849
3057
|
return {
|
|
2850
3058
|
target: "submitPullRequestReview",
|
|
2851
3059
|
repo: repo.ref,
|
|
@@ -2888,100 +3096,8 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
|
2888
3096
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
2889
3097
|
|
|
2890
3098
|
// src/issue-outcomes/store.ts
|
|
2891
|
-
import { and, eq, lte, sql as sql2 } from "drizzle-orm";
|
|
3099
|
+
import { and as and2, eq as eq2, lte, sql as sql2 } from "drizzle-orm";
|
|
2892
3100
|
import { z as z15 } from "zod";
|
|
2893
|
-
|
|
2894
|
-
// src/db/schema.ts
|
|
2895
|
-
import { sql } from "drizzle-orm";
|
|
2896
|
-
import {
|
|
2897
|
-
index,
|
|
2898
|
-
integer,
|
|
2899
|
-
pgTable,
|
|
2900
|
-
primaryKey,
|
|
2901
|
-
text,
|
|
2902
|
-
timestamp
|
|
2903
|
-
} from "drizzle-orm/pg-core";
|
|
2904
|
-
import { z as z14 } from "zod";
|
|
2905
|
-
var githubPullRequestStateSchema = z14.enum([
|
|
2906
|
-
"closed_unmerged",
|
|
2907
|
-
"merged",
|
|
2908
|
-
"open"
|
|
2909
|
-
]);
|
|
2910
|
-
var githubPullRequestCommitCompositionSchema = z14.enum([
|
|
2911
|
-
"junior_only",
|
|
2912
|
-
"mixed"
|
|
2913
|
-
]);
|
|
2914
|
-
var githubIssueStateSchema = z14.enum(["closed", "open"]);
|
|
2915
|
-
var githubIssueStateReasonSchema = z14.enum([
|
|
2916
|
-
"completed",
|
|
2917
|
-
"duplicate",
|
|
2918
|
-
"not_planned",
|
|
2919
|
-
"reopened"
|
|
2920
|
-
]);
|
|
2921
|
-
var juniorGitHubIssues = pgTable(
|
|
2922
|
-
"junior_github_issues",
|
|
2923
|
-
{
|
|
2924
|
-
issueId: text("issue_id").primaryKey(),
|
|
2925
|
-
repositoryId: text("repository_id").notNull(),
|
|
2926
|
-
repositoryFullName: text("repository_full_name").notNull(),
|
|
2927
|
-
number: integer("number").notNull(),
|
|
2928
|
-
state: text("state").$type().notNull(),
|
|
2929
|
-
stateReason: text("state_reason").$type(),
|
|
2930
|
-
conversationIds: text("conversation_ids").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
2931
|
-
openedAt: timestamp("opened_at", { withTimezone: true }).notNull(),
|
|
2932
|
-
closedAt: timestamp("closed_at", { withTimezone: true }),
|
|
2933
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
2934
|
-
},
|
|
2935
|
-
(table) => [
|
|
2936
|
-
index("junior_github_issues_opened_at_idx").on(table.openedAt),
|
|
2937
|
-
index("junior_github_issues_closed_at_idx").on(table.closedAt),
|
|
2938
|
-
index("junior_github_issues_open_idx").on(table.issueId).where(sql`${table.state} = 'open'`)
|
|
2939
|
-
]
|
|
2940
|
-
);
|
|
2941
|
-
var juniorGitHubPullRequests = pgTable(
|
|
2942
|
-
"junior_github_pull_requests",
|
|
2943
|
-
{
|
|
2944
|
-
pullRequestId: text("pull_request_id").primaryKey(),
|
|
2945
|
-
repositoryId: text("repository_id").notNull(),
|
|
2946
|
-
repositoryFullName: text("repository_full_name").notNull(),
|
|
2947
|
-
number: integer("number").notNull(),
|
|
2948
|
-
state: text("state").$type().notNull(),
|
|
2949
|
-
commitComposition: text("commit_composition").$type(),
|
|
2950
|
-
conversationIds: text("conversation_ids").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
2951
|
-
openedAt: timestamp("opened_at", { withTimezone: true }).notNull(),
|
|
2952
|
-
mergedAt: timestamp("merged_at", { withTimezone: true }),
|
|
2953
|
-
closedAt: timestamp("closed_at", { withTimezone: true }),
|
|
2954
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
2955
|
-
},
|
|
2956
|
-
(table) => [
|
|
2957
|
-
index("junior_github_pull_requests_opened_at_idx").on(table.openedAt),
|
|
2958
|
-
index("junior_github_pull_requests_merged_at_idx").on(table.mergedAt),
|
|
2959
|
-
index("junior_github_pull_requests_closed_at_idx").on(table.closedAt),
|
|
2960
|
-
index("junior_github_pull_requests_open_idx").on(table.pullRequestId).where(sql`${table.state} = 'open'`),
|
|
2961
|
-
index("junior_github_pull_requests_unmerged_conversations_idx").using("gin", table.conversationIds).where(sql`${table.state} <> 'merged'`)
|
|
2962
|
-
]
|
|
2963
|
-
);
|
|
2964
|
-
var juniorGitHubPullRequestIssues = pgTable(
|
|
2965
|
-
"junior_github_pull_request_issues",
|
|
2966
|
-
{
|
|
2967
|
-
pullRequestId: text("pull_request_id").notNull().references(() => juniorGitHubPullRequests.pullRequestId, {
|
|
2968
|
-
onDelete: "cascade"
|
|
2969
|
-
}),
|
|
2970
|
-
issueRepositoryFullName: text("issue_repository_full_name").notNull(),
|
|
2971
|
-
issueNumber: integer("issue_number").notNull()
|
|
2972
|
-
},
|
|
2973
|
-
(table) => [
|
|
2974
|
-
primaryKey({
|
|
2975
|
-
columns: [
|
|
2976
|
-
table.pullRequestId,
|
|
2977
|
-
table.issueRepositoryFullName,
|
|
2978
|
-
table.issueNumber
|
|
2979
|
-
]
|
|
2980
|
-
})
|
|
2981
|
-
]
|
|
2982
|
-
);
|
|
2983
|
-
|
|
2984
|
-
// src/issue-outcomes/store.ts
|
|
2985
3101
|
var githubIssueOutcomeInputSchema = z15.object({
|
|
2986
3102
|
candidateOwned: z15.boolean(),
|
|
2987
3103
|
closedAt: z15.date().optional(),
|
|
@@ -3015,8 +3131,8 @@ async function recordGitHubIssueOutcome(db, input) {
|
|
|
3015
3131
|
const values = projectionValues(outcome);
|
|
3016
3132
|
if (!outcome.candidateOwned) {
|
|
3017
3133
|
const updated = await db.update(juniorGitHubIssues).set(values).where(
|
|
3018
|
-
|
|
3019
|
-
|
|
3134
|
+
and2(
|
|
3135
|
+
eq2(juniorGitHubIssues.issueId, outcome.issueId),
|
|
3020
3136
|
lte(juniorGitHubIssues.updatedAt, outcome.updatedAt)
|
|
3021
3137
|
)
|
|
3022
3138
|
).returning({
|
|
@@ -3054,12 +3170,12 @@ async function recordGitHubIssueConversations(db, input) {
|
|
|
3054
3170
|
) AS value
|
|
3055
3171
|
ORDER BY value
|
|
3056
3172
|
)`
|
|
3057
|
-
}).where(
|
|
3173
|
+
}).where(eq2(juniorGitHubIssues.issueId, association.issueId)).returning({ issueId: juniorGitHubIssues.issueId });
|
|
3058
3174
|
return updated.length > 0;
|
|
3059
3175
|
}
|
|
3060
3176
|
|
|
3061
3177
|
// src/pull-request-outcomes/store.ts
|
|
3062
|
-
import { and as
|
|
3178
|
+
import { and as and3, eq as eq3, lte as lte2, ne, sql as sql3 } from "drizzle-orm";
|
|
3063
3179
|
import { z as z16 } from "zod";
|
|
3064
3180
|
var githubPullRequestOutcomeInputSchema = z16.object({
|
|
3065
3181
|
candidateOwned: z16.boolean(),
|
|
@@ -3106,8 +3222,8 @@ async function recordGitHubPullRequestOutcome(db, input) {
|
|
|
3106
3222
|
const values = projectionValues2(outcome);
|
|
3107
3223
|
if (!outcome.candidateOwned) {
|
|
3108
3224
|
const updated = await db.update(juniorGitHubPullRequests).set(values).where(
|
|
3109
|
-
|
|
3110
|
-
|
|
3225
|
+
and3(
|
|
3226
|
+
eq3(juniorGitHubPullRequests.pullRequestId, outcome.pullRequestId),
|
|
3111
3227
|
lte2(juniorGitHubPullRequests.updatedAt, outcome.updatedAt)
|
|
3112
3228
|
)
|
|
3113
3229
|
).returning({
|
|
@@ -3153,7 +3269,7 @@ async function listGitHubUnfinishedWork(db, conversationIds) {
|
|
|
3153
3269
|
sql3`, `
|
|
3154
3270
|
);
|
|
3155
3271
|
const rows = await db.select({ conversationIds: juniorGitHubPullRequests.conversationIds }).from(juniorGitHubPullRequests).where(
|
|
3156
|
-
|
|
3272
|
+
and3(
|
|
3157
3273
|
ne(juniorGitHubPullRequests.state, "merged"),
|
|
3158
3274
|
sql3`${juniorGitHubPullRequests.conversationIds} && ARRAY[${values}]::text[]`
|
|
3159
3275
|
)
|
|
@@ -3170,8 +3286,8 @@ async function listGitHubFinishedWork(db, conversationIds) {
|
|
|
3170
3286
|
conversationIds: juniorGitHubPullRequests.conversationIds,
|
|
3171
3287
|
mergedAt: juniorGitHubPullRequests.mergedAt
|
|
3172
3288
|
}).from(juniorGitHubPullRequests).where(
|
|
3173
|
-
|
|
3174
|
-
|
|
3289
|
+
and3(
|
|
3290
|
+
eq3(juniorGitHubPullRequests.state, "merged"),
|
|
3175
3291
|
sql3`${juniorGitHubPullRequests.conversationIds} && ARRAY[${values}]::text[]`
|
|
3176
3292
|
)
|
|
3177
3293
|
);
|
|
@@ -3221,7 +3337,7 @@ async function recordGitHubPullRequestConversations(db, input) {
|
|
|
3221
3337
|
ORDER BY value
|
|
3222
3338
|
)`
|
|
3223
3339
|
}).where(
|
|
3224
|
-
|
|
3340
|
+
eq3(juniorGitHubPullRequests.pullRequestId, association.pullRequestId)
|
|
3225
3341
|
).returning({ pullRequestId: juniorGitHubPullRequests.pullRequestId });
|
|
3226
3342
|
return updated.length > 0;
|
|
3227
3343
|
}
|
|
@@ -3237,7 +3353,7 @@ async function recordGitHubPullRequestLinkedIssues(db, input) {
|
|
|
3237
3353
|
),
|
|
3238
3354
|
issueNumber: sql3`${issue.number}`.as("issue_number")
|
|
3239
3355
|
}).from(juniorGitHubPullRequests).where(
|
|
3240
|
-
|
|
3356
|
+
eq3(
|
|
3241
3357
|
juniorGitHubPullRequests.pullRequestId,
|
|
3242
3358
|
association.pullRequestId
|
|
3243
3359
|
)
|
|
@@ -3551,48 +3667,151 @@ function normalizeGitHubPullRequestLinkedIssues(args) {
|
|
|
3551
3667
|
} : void 0;
|
|
3552
3668
|
}
|
|
3553
3669
|
|
|
3554
|
-
// src/webhooks/pull-request-
|
|
3670
|
+
// src/webhooks/pull-request-match-data.ts
|
|
3555
3671
|
import { z as z19 } from "zod";
|
|
3556
|
-
var
|
|
3672
|
+
var LOOKUPS_BY_MATCH_KEY = {
|
|
3673
|
+
authors: ["authors"],
|
|
3674
|
+
openerEmail: ["opener"],
|
|
3675
|
+
openerRole: ["opener", "openerRole"],
|
|
3676
|
+
openerUsername: ["opener"]
|
|
3677
|
+
};
|
|
3678
|
+
var ALL_LOOKUPS = ["authors", "opener", "openerRole"];
|
|
3557
3679
|
var webhookSchema = z19.object({
|
|
3558
3680
|
repository: z19.object({ full_name: z19.string().min(1) })
|
|
3559
3681
|
});
|
|
3560
|
-
|
|
3561
|
-
const
|
|
3562
|
-
const
|
|
3563
|
-
(event
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3682
|
+
function pullRequestNumbers(events) {
|
|
3683
|
+
const numbers = /* @__PURE__ */ new Map();
|
|
3684
|
+
for (const event of events) {
|
|
3685
|
+
if (!event.eventType.startsWith("pull_request.")) continue;
|
|
3686
|
+
const match = /#(\d+)$/.exec(event.identifier);
|
|
3687
|
+
if (match) numbers.set(event.eventKey, Number(match[1]));
|
|
3688
|
+
}
|
|
3689
|
+
return numbers;
|
|
3690
|
+
}
|
|
3691
|
+
function logFailure(context, lookup, error) {
|
|
3692
|
+
context.log?.error(`GitHub pull request ${lookup} lookup failed`, {
|
|
3693
|
+
deliveryId: context.deliveryId,
|
|
3694
|
+
errorType: error instanceof Error ? error.name : "UnknownError",
|
|
3695
|
+
repository: context.repositoryFullName
|
|
3572
3696
|
});
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3697
|
+
return void 0;
|
|
3698
|
+
}
|
|
3699
|
+
async function withJuniorOpeners(context, events) {
|
|
3700
|
+
const botNumber = (event) => {
|
|
3701
|
+
const number = context.numbers.get(event.eventKey);
|
|
3702
|
+
return number !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number : void 0;
|
|
3703
|
+
};
|
|
3704
|
+
const numbers = events.flatMap((event) => botNumber(event) ?? []);
|
|
3705
|
+
if (numbers.length === 0) return events;
|
|
3706
|
+
const openers = await listGitHubPullRequestOpeners(context.db, {
|
|
3707
|
+
numbers,
|
|
3708
|
+
repositoryFullName: context.repositoryFullName
|
|
3709
|
+
});
|
|
3710
|
+
const logins = /* @__PURE__ */ new Map();
|
|
3711
|
+
for (const identityId of new Set(openers.values())) {
|
|
3580
3712
|
try {
|
|
3581
|
-
|
|
3713
|
+
logins.set(identityId, await context.loadGitHubLogin?.(identityId));
|
|
3582
3714
|
} catch (error) {
|
|
3583
|
-
|
|
3584
|
-
deliveryId: args.deliveryId,
|
|
3585
|
-
errorType: error instanceof Error ? error.name : "UnknownError",
|
|
3586
|
-
repository: repositoryFullName
|
|
3587
|
-
});
|
|
3715
|
+
logFailure(context, "opener", error);
|
|
3588
3716
|
}
|
|
3589
3717
|
}
|
|
3590
|
-
return
|
|
3591
|
-
const
|
|
3592
|
-
|
|
3593
|
-
|
|
3718
|
+
return events.map((event) => {
|
|
3719
|
+
const number = botNumber(event);
|
|
3720
|
+
if (number === void 0) return event;
|
|
3721
|
+
const identityId = openers.get(number);
|
|
3722
|
+
const login = identityId ? logins.get(identityId) : void 0;
|
|
3723
|
+
const {
|
|
3724
|
+
openerEmail: _email,
|
|
3725
|
+
openerUsername: _login,
|
|
3726
|
+
...data
|
|
3727
|
+
} = event.data ?? {};
|
|
3728
|
+
return {
|
|
3729
|
+
...event,
|
|
3730
|
+
data: { ...data, ...login ? { openerUsername: login } : void 0 }
|
|
3731
|
+
};
|
|
3594
3732
|
});
|
|
3595
3733
|
}
|
|
3734
|
+
async function withRolesAndAuthors(context, events, lookups) {
|
|
3735
|
+
const { repositoryFullName } = context;
|
|
3736
|
+
const roles = /* @__PURE__ */ new Map();
|
|
3737
|
+
const authors = /* @__PURE__ */ new Map();
|
|
3738
|
+
const loadRole = lookups.has("openerRole") ? context.loadRole : void 0;
|
|
3739
|
+
const loadAuthors = lookups.has("authors") ? context.loadAuthors : void 0;
|
|
3740
|
+
if (!loadRole && !loadAuthors) return events;
|
|
3741
|
+
return await Promise.all(
|
|
3742
|
+
events.map(async (event) => {
|
|
3743
|
+
const number = context.numbers.get(event.eventKey);
|
|
3744
|
+
if (number === void 0) return event;
|
|
3745
|
+
const login = event.data?.openerUsername;
|
|
3746
|
+
if (loadRole && typeof login === "string" && !roles.has(login)) {
|
|
3747
|
+
roles.set(
|
|
3748
|
+
login,
|
|
3749
|
+
loadRole({ login, repositoryFullName }).catch(
|
|
3750
|
+
(error) => logFailure(context, "role", error)
|
|
3751
|
+
)
|
|
3752
|
+
);
|
|
3753
|
+
}
|
|
3754
|
+
if (loadAuthors && !authors.has(number)) {
|
|
3755
|
+
authors.set(
|
|
3756
|
+
number,
|
|
3757
|
+
loadAuthors({ number, repositoryFullName }).catch(
|
|
3758
|
+
(error) => logFailure(context, "authors", error)
|
|
3759
|
+
)
|
|
3760
|
+
);
|
|
3761
|
+
}
|
|
3762
|
+
const role = loadRole && typeof login === "string" ? await roles.get(login) : void 0;
|
|
3763
|
+
const logins = loadAuthors ? await authors.get(number) : void 0;
|
|
3764
|
+
if (!role && !logins?.length) return event;
|
|
3765
|
+
return {
|
|
3766
|
+
...event,
|
|
3767
|
+
data: {
|
|
3768
|
+
...event.data,
|
|
3769
|
+
...role ? { openerRole: role } : void 0,
|
|
3770
|
+
...logins?.length ? { authors: logins } : void 0
|
|
3771
|
+
}
|
|
3772
|
+
};
|
|
3773
|
+
})
|
|
3774
|
+
);
|
|
3775
|
+
}
|
|
3776
|
+
async function withLookups(context, events, lookups) {
|
|
3777
|
+
const opened = lookups.has("opener") ? await withJuniorOpeners(context, events) : events;
|
|
3778
|
+
return await withRolesAndAuthors(context, opened, lookups);
|
|
3779
|
+
}
|
|
3780
|
+
async function withGitHubPullRequestMatchData(args) {
|
|
3781
|
+
const parsed = webhookSchema.safeParse(args.body);
|
|
3782
|
+
const numbers = pullRequestNumbers(args.events);
|
|
3783
|
+
const pullRequestEvents = args.events.filter(
|
|
3784
|
+
(event) => numbers.has(event.eventKey)
|
|
3785
|
+
);
|
|
3786
|
+
if (!parsed.success || pullRequestEvents.length === 0) return args.events;
|
|
3787
|
+
const context = {
|
|
3788
|
+
botEmail: args.botEmail,
|
|
3789
|
+
db: args.db,
|
|
3790
|
+
deliveryId: args.deliveryId,
|
|
3791
|
+
...args.loadAuthors ? { loadAuthors: args.loadAuthors } : void 0,
|
|
3792
|
+
...args.loadGitHubLogin ? { loadGitHubLogin: args.loadGitHubLogin } : void 0,
|
|
3793
|
+
...args.loadRole ? { loadRole: args.loadRole } : void 0,
|
|
3794
|
+
...args.log ? { log: args.log } : void 0,
|
|
3795
|
+
numbers,
|
|
3796
|
+
repositoryFullName: parsed.data.repository.full_name
|
|
3797
|
+
};
|
|
3798
|
+
const keys = await args.neededMatchKeys?.({
|
|
3799
|
+
eventTypes: [...new Set(pullRequestEvents.map((e) => e.eventType))],
|
|
3800
|
+
identifiers: [...new Set(pullRequestEvents.map((e) => e.identifier))]
|
|
3801
|
+
}) ?? [];
|
|
3802
|
+
const filtered = new Set(
|
|
3803
|
+
keys.flatMap((key) => LOOKUPS_BY_MATCH_KEY[key] ?? [])
|
|
3804
|
+
);
|
|
3805
|
+
const events = filtered.size > 0 ? await withLookups(context, args.events, filtered) : args.events;
|
|
3806
|
+
const rest = new Set(ALL_LOOKUPS.filter((lookup) => !filtered.has(lookup)));
|
|
3807
|
+
const { hasMatch } = args;
|
|
3808
|
+
if (rest.size === 0 || !hasMatch) return events;
|
|
3809
|
+
const matches = await Promise.all(
|
|
3810
|
+
events.filter((event) => numbers.has(event.eventKey)).map((event) => hasMatch(event))
|
|
3811
|
+
);
|
|
3812
|
+
if (!matches.some(Boolean)) return events;
|
|
3813
|
+
return await withLookups(context, events, rest);
|
|
3814
|
+
}
|
|
3596
3815
|
|
|
3597
3816
|
// src/webhooks/pull-request-people.ts
|
|
3598
3817
|
import { z as z20 } from "zod";
|
|
@@ -3619,6 +3838,42 @@ var commitPageSchema = z20.array(
|
|
|
3619
3838
|
commit: z20.object({ message: z20.string() })
|
|
3620
3839
|
})
|
|
3621
3840
|
);
|
|
3841
|
+
function shareCommitPages(load) {
|
|
3842
|
+
const loaders = /* @__PURE__ */ new Map();
|
|
3843
|
+
const pages = /* @__PURE__ */ new Map();
|
|
3844
|
+
return (target) => async (page, perPage) => {
|
|
3845
|
+
const pullRequest = `${target.repositoryFullName.toLowerCase()}#${target.number}`;
|
|
3846
|
+
const key = `${pullRequest}:${page}:${perPage}`;
|
|
3847
|
+
let result = pages.get(key);
|
|
3848
|
+
if (!result) {
|
|
3849
|
+
let loader = loaders.get(pullRequest);
|
|
3850
|
+
if (!loader) {
|
|
3851
|
+
loader = load(target);
|
|
3852
|
+
loaders.set(pullRequest, loader);
|
|
3853
|
+
}
|
|
3854
|
+
result = loader.then((loadPage) => loadPage(page, perPage));
|
|
3855
|
+
pages.set(key, result);
|
|
3856
|
+
}
|
|
3857
|
+
return await result;
|
|
3858
|
+
};
|
|
3859
|
+
}
|
|
3860
|
+
async function forEachCommit(loadPage, visit) {
|
|
3861
|
+
for (let page = 1; page <= MAX_PAGES; page += 1) {
|
|
3862
|
+
const commits = commitPageSchema.parse(await loadPage(page, PAGE_SIZE));
|
|
3863
|
+
for (const commit of commits) {
|
|
3864
|
+
visit({
|
|
3865
|
+
coAuthorEmails: [
|
|
3866
|
+
...commit.commit.message.matchAll(CO_AUTHOR_TRAILER)
|
|
3867
|
+
].map((match) => match[1]),
|
|
3868
|
+
...commit.author ? { login: commit.author.login } : void 0
|
|
3869
|
+
});
|
|
3870
|
+
}
|
|
3871
|
+
if (commits.length < PAGE_SIZE) break;
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
function noreplyLogin(email) {
|
|
3875
|
+
return GITHUB_NOREPLY_EMAIL.exec(email)?.groups?.login;
|
|
3876
|
+
}
|
|
3622
3877
|
async function loadGitHubPullRequestPeople(args) {
|
|
3623
3878
|
const people = /* @__PURE__ */ new Map();
|
|
3624
3879
|
const addLogin = (login) => {
|
|
@@ -3628,28 +3883,33 @@ async function loadGitHubPullRequestPeople(args) {
|
|
|
3628
3883
|
people.set(key, { provider: "github", handle: login });
|
|
3629
3884
|
};
|
|
3630
3885
|
const addEmail = (value) => {
|
|
3886
|
+
const login = noreplyLogin(value);
|
|
3887
|
+
if (login) return addLogin(login);
|
|
3631
3888
|
const email = value.toLowerCase();
|
|
3632
|
-
|
|
3633
|
-
if (login) addLogin(login);
|
|
3634
|
-
else if (!people.has(`email:${email}`)) {
|
|
3889
|
+
if (!people.has(`email:${email}`)) {
|
|
3635
3890
|
people.set(`email:${email}`, { email });
|
|
3636
3891
|
}
|
|
3637
3892
|
};
|
|
3638
3893
|
args.logins.forEach(addLogin);
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
for (const commit of commits) {
|
|
3644
|
-
if (commit.author) addLogin(commit.author.login);
|
|
3645
|
-
for (const match of commit.commit.message.matchAll(CO_AUTHOR_TRAILER)) {
|
|
3646
|
-
addEmail(match[1]);
|
|
3647
|
-
}
|
|
3648
|
-
}
|
|
3649
|
-
if (commits.length < PAGE_SIZE) break;
|
|
3650
|
-
}
|
|
3894
|
+
await forEachCommit(args.loadPage, (commit) => {
|
|
3895
|
+
if (commit.login) addLogin(commit.login);
|
|
3896
|
+
commit.coAuthorEmails.forEach(addEmail);
|
|
3897
|
+
});
|
|
3651
3898
|
return [...people.values()].slice(0, MAX_PEOPLE);
|
|
3652
3899
|
}
|
|
3900
|
+
async function loadGitHubPullRequestAuthors(args) {
|
|
3901
|
+
const authors = /* @__PURE__ */ new Map();
|
|
3902
|
+
const add = (login) => {
|
|
3903
|
+
if (login && !authors.has(login.toLowerCase())) {
|
|
3904
|
+
authors.set(login.toLowerCase(), login);
|
|
3905
|
+
}
|
|
3906
|
+
};
|
|
3907
|
+
await forEachCommit(args.loadPage, (commit) => {
|
|
3908
|
+
add(commit.login);
|
|
3909
|
+
commit.coAuthorEmails.forEach((email) => add(noreplyLogin(email)));
|
|
3910
|
+
});
|
|
3911
|
+
return [...authors.values()].slice(0, MAX_PEOPLE);
|
|
3912
|
+
}
|
|
3653
3913
|
async function withGitHubPullRequestPeople(args) {
|
|
3654
3914
|
const { hasMatch } = args;
|
|
3655
3915
|
const peopleEvents = args.events.filter(
|
|
@@ -3883,11 +4143,14 @@ function createGitHubWebhookRoute(args) {
|
|
|
3883
4143
|
privateKeyEnv: args.privateKeyEnv
|
|
3884
4144
|
}) : void 0;
|
|
3885
4145
|
const hasMatch = args.events.hasMatch;
|
|
4146
|
+
const commitPages = args.loadPullRequestCommitPages ? shareCommitPages(args.loadPullRequestCommitPages) : void 0;
|
|
3886
4147
|
const events = await withGitHubPullRequestPeople({
|
|
3887
4148
|
body,
|
|
3888
4149
|
deliveryId,
|
|
3889
|
-
events: await
|
|
4150
|
+
events: await withGitHubPullRequestMatchData({
|
|
3890
4151
|
body,
|
|
4152
|
+
botEmail,
|
|
4153
|
+
db: args.db,
|
|
3891
4154
|
deliveryId,
|
|
3892
4155
|
events: normalizeGitHubEvents({
|
|
3893
4156
|
body,
|
|
@@ -3896,12 +4159,24 @@ function createGitHubWebhookRoute(args) {
|
|
|
3896
4159
|
deliveryId,
|
|
3897
4160
|
eventName
|
|
3898
4161
|
}),
|
|
3899
|
-
|
|
4162
|
+
hasMatch,
|
|
4163
|
+
...commitPages ? {
|
|
4164
|
+
loadAuthors: async (target) => await loadGitHubPullRequestAuthors({
|
|
4165
|
+
loadPage: commitPages(target)
|
|
4166
|
+
})
|
|
4167
|
+
} : void 0,
|
|
4168
|
+
loadGitHubLogin: args.loadGitHubLogin,
|
|
4169
|
+
loadRole: args.loadRepositoryRole,
|
|
3900
4170
|
log: args.log,
|
|
3901
4171
|
neededMatchKeys: args.events.neededMatchKeys
|
|
3902
4172
|
}),
|
|
3903
4173
|
hasMatch,
|
|
3904
|
-
|
|
4174
|
+
...commitPages ? {
|
|
4175
|
+
load: async (target) => await loadGitHubPullRequestPeople({
|
|
4176
|
+
logins: target.logins,
|
|
4177
|
+
loadPage: commitPages(target)
|
|
4178
|
+
})
|
|
4179
|
+
} : void 0,
|
|
3905
4180
|
log: args.log
|
|
3906
4181
|
});
|
|
3907
4182
|
const feedbackTarget = pullRequestFeedbackTarget(events);
|
|
@@ -4156,12 +4431,12 @@ if [ -z "$message_file" ]; then
|
|
|
4156
4431
|
fi
|
|
4157
4432
|
|
|
4158
4433
|
if [ -z "\${JUNIOR_GIT_AUTHOR_NAME:-}" ] || [ -z "\${JUNIOR_GIT_AUTHOR_EMAIL:-}" ]; then
|
|
4159
|
-
echo "
|
|
4434
|
+
echo "GitHub plugin internal error: the host runtime did not inject the Git author identity. Do not set Git author env vars manually; report this configuration error." >&2
|
|
4160
4435
|
exit 1
|
|
4161
4436
|
fi
|
|
4162
4437
|
|
|
4163
4438
|
if [ "\${GIT_AUTHOR_NAME:-}" != "$JUNIOR_GIT_AUTHOR_NAME" ] || [ "\${GIT_AUTHOR_EMAIL:-}" != "$JUNIOR_GIT_AUTHOR_EMAIL" ]; then
|
|
4164
|
-
echo "
|
|
4439
|
+
echo "GitHub plugin internal error: Git author was not set to the configured identity. Do not override Git author manually; report this configuration error." >&2
|
|
4165
4440
|
exit 1
|
|
4166
4441
|
fi
|
|
4167
4442
|
|
|
@@ -4759,7 +5034,7 @@ function assertGitHubPullRequestApprovalDenied(input) {
|
|
|
4759
5034
|
if (!bodyText) {
|
|
4760
5035
|
if (isEventsPath) {
|
|
4761
5036
|
throw new EgressPolicyDenied(
|
|
4762
|
-
"GitHub pull request review submissions must include a parseable non-APPROVE event so
|
|
5037
|
+
"GitHub pull request review submissions must include a parseable non-APPROVE event so the no-approve policy can be enforced."
|
|
4763
5038
|
);
|
|
4764
5039
|
}
|
|
4765
5040
|
return;
|
|
@@ -4769,31 +5044,31 @@ function assertGitHubPullRequestApprovalDenied(input) {
|
|
|
4769
5044
|
body = JSON.parse(bodyText);
|
|
4770
5045
|
} catch {
|
|
4771
5046
|
throw new EgressPolicyDenied(
|
|
4772
|
-
"GitHub pull request review requests must use JSON bodies so
|
|
5047
|
+
"GitHub pull request review requests must use JSON bodies so the no-approve policy can be enforced."
|
|
4773
5048
|
);
|
|
4774
5049
|
}
|
|
4775
5050
|
if (!isRecord(body)) {
|
|
4776
5051
|
throw new EgressPolicyDenied(
|
|
4777
|
-
"GitHub pull request review requests must use JSON object bodies so
|
|
5052
|
+
"GitHub pull request review requests must use JSON object bodies so the no-approve policy can be enforced."
|
|
4778
5053
|
);
|
|
4779
5054
|
}
|
|
4780
5055
|
let event;
|
|
4781
5056
|
if ("event" in body) {
|
|
4782
5057
|
if (typeof body.event !== "string" || body.event.trim().length === 0) {
|
|
4783
5058
|
throw new EgressPolicyDenied(
|
|
4784
|
-
"GitHub pull request review submissions must include a parseable non-APPROVE event so
|
|
5059
|
+
"GitHub pull request review submissions must include a parseable non-APPROVE event so the no-approve policy can be enforced."
|
|
4785
5060
|
);
|
|
4786
5061
|
}
|
|
4787
5062
|
event = body.event.trim().toUpperCase();
|
|
4788
5063
|
}
|
|
4789
5064
|
if (event === "APPROVE") {
|
|
4790
5065
|
throw new EgressPolicyDenied(
|
|
4791
|
-
"
|
|
5066
|
+
"You cannot approve GitHub pull requests. Request changes, leave a comment review, or dismiss your own review instead."
|
|
4792
5067
|
);
|
|
4793
5068
|
}
|
|
4794
5069
|
if (isEventsPath && event === void 0) {
|
|
4795
5070
|
throw new EgressPolicyDenied(
|
|
4796
|
-
"GitHub pull request review submissions must include a parseable non-APPROVE event so
|
|
5071
|
+
"GitHub pull request review submissions must include a parseable non-APPROVE event so the no-approve policy can be enforced."
|
|
4797
5072
|
);
|
|
4798
5073
|
}
|
|
4799
5074
|
}
|
|
@@ -4997,14 +5272,14 @@ async function githubPermissionDeniedMessage(ctx) {
|
|
|
4997
5272
|
var PULL_REQUEST_COMMENT_REACTIONS_PATH = /^\/repos\/[^/]+\/[^/]+\/(issues|pulls)\/comments\/[^/]+\/reactions(?:\/[^/]+)?$/;
|
|
4998
5273
|
var GITHUB_BODY_WRITES = [
|
|
4999
5274
|
{
|
|
5000
|
-
denialMessage: `GitHub issue creation must use the github_createIssue tool
|
|
5275
|
+
denialMessage: `GitHub issue creation must use the github_createIssue tool, which owns idempotency and the conversation footer. ${CREATE_TOOL_ROUTING_GUIDANCE}`,
|
|
5001
5276
|
graphqlField: "createIssue",
|
|
5002
5277
|
method: "POST",
|
|
5003
5278
|
operation: "github.issue.create",
|
|
5004
5279
|
restPath: /^\/repos\/[^/]+\/[^/]+\/issues$/
|
|
5005
5280
|
},
|
|
5006
5281
|
{
|
|
5007
|
-
denialMessage: `GitHub pull request creation must use the github_createPullRequest tool
|
|
5282
|
+
denialMessage: `GitHub pull request creation must use the github_createPullRequest tool, which owns idempotency and the conversation footer. ${CREATE_TOOL_ROUTING_GUIDANCE}`,
|
|
5008
5283
|
graphqlField: "createPullRequest",
|
|
5009
5284
|
method: "POST",
|
|
5010
5285
|
operation: "github.pull.create",
|
|
@@ -5018,14 +5293,14 @@ var GITHUB_BODY_WRITES = [
|
|
|
5018
5293
|
restPath: /^\/repos\/[^/]+\/[^/]+\/pulls\/[^/]+\/reviews$/
|
|
5019
5294
|
},
|
|
5020
5295
|
{
|
|
5021
|
-
denialMessage: `GitHub issue updates must use the github_updateIssue tool
|
|
5296
|
+
denialMessage: `GitHub issue updates must use the github_updateIssue tool, which owns requester attribution and the conversation footer. ${CREATE_TOOL_ROUTING_GUIDANCE}`,
|
|
5022
5297
|
graphqlField: "updateIssue",
|
|
5023
5298
|
method: "PATCH",
|
|
5024
5299
|
operation: "github.issue.update",
|
|
5025
5300
|
restPath: /^\/repos\/[^/]+\/[^/]+\/issues\/[^/]+$/
|
|
5026
5301
|
},
|
|
5027
5302
|
{
|
|
5028
|
-
denialMessage: `GitHub pull request updates must use the github_updatePullRequest tool
|
|
5303
|
+
denialMessage: `GitHub pull request updates must use the github_updatePullRequest tool, which owns requester attribution and the conversation footer. ${CREATE_TOOL_ROUTING_GUIDANCE}`,
|
|
5029
5304
|
graphqlField: "updatePullRequest",
|
|
5030
5305
|
method: "PATCH",
|
|
5031
5306
|
operation: "github.pull.update",
|
|
@@ -5249,7 +5524,7 @@ async function githubGrantForEgress(ctx) {
|
|
|
5249
5524
|
const access = HTTP_READ_METHODS.has(method) ? "read" : "write";
|
|
5250
5525
|
if (access === "write") {
|
|
5251
5526
|
throw new EgressPolicyDenied2(
|
|
5252
|
-
"
|
|
5527
|
+
"This GitHub write request is not supported. Use the matching GitHub tool or a supported REST endpoint."
|
|
5253
5528
|
);
|
|
5254
5529
|
}
|
|
5255
5530
|
return grantForAccess(access, "github.api-read", "installation-read");
|
|
@@ -5306,22 +5581,13 @@ function githubPlugin(options = {}) {
|
|
|
5306
5581
|
{
|
|
5307
5582
|
type: "repository",
|
|
5308
5583
|
identifier: GITHUB_REPOSITORY_IDENTIFIER,
|
|
5309
|
-
supportedEvents: [
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
"pull_request.opened",
|
|
5317
|
-
...GITHUB_ISSUE_SUGGESTED_EVENTS,
|
|
5318
|
-
...GITHUB_PULL_REQUEST_SUGGESTED_EVENTS
|
|
5319
|
-
],
|
|
5320
|
-
matchFields: {
|
|
5321
|
-
...GITHUB_DEPLOYMENT_MATCH_FIELDS,
|
|
5322
|
-
...GITHUB_ISSUE_COMMENT_MATCH_FIELDS,
|
|
5323
|
-
...GITHUB_PULL_REQUEST_MATCH_FIELDS
|
|
5324
|
-
},
|
|
5584
|
+
supportedEvents: [...GITHUB_REPOSITORY_EVENTS],
|
|
5585
|
+
suggestedEvents: [...GITHUB_REPOSITORY_SUGGESTED_EVENTS],
|
|
5586
|
+
matchFields: mergeEventMatchFields(
|
|
5587
|
+
GITHUB_DEPLOYMENT_MATCH_FIELDS,
|
|
5588
|
+
GITHUB_ISSUE_COMMENT_MATCH_FIELDS,
|
|
5589
|
+
GITHUB_PULL_REQUEST_MATCH_FIELDS
|
|
5590
|
+
),
|
|
5325
5591
|
guidance: gitHubPullRequestEventGuidance(
|
|
5326
5592
|
options.pullRequestEvents?.guidance
|
|
5327
5593
|
)
|
|
@@ -5471,14 +5737,11 @@ function githubPlugin(options = {}) {
|
|
|
5471
5737
|
db: ctx.db,
|
|
5472
5738
|
installationId: () => readEnv(installationIdEnv),
|
|
5473
5739
|
installationIdEnv,
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
pullRequest
|
|
5480
|
-
)
|
|
5481
|
-
}),
|
|
5740
|
+
loadRepositoryRole: async (target) => await loadRepositoryRole(installationEnv, ctx.cache, target),
|
|
5741
|
+
loadGitHubLogin: async (identityId) => linkedGitHubLogin(
|
|
5742
|
+
(await ctx.users.readIdentity(identityId))?.user
|
|
5743
|
+
),
|
|
5744
|
+
loadPullRequestCommitPages: async (pullRequest) => await loadPullRequestCommitPages(installationEnv, pullRequest),
|
|
5482
5745
|
log: ctx.log,
|
|
5483
5746
|
markFeedbackReviewing: async (target) => await markPullRequestFeedbackReviewing(installationEnv, target),
|
|
5484
5747
|
privateKeyEnv,
|