@sentry/junior-github 0.278.0 → 0.280.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/{chunk-IR7D5MR7.js → chunk-NSAVG2P3.js} +8 -8
- package/dist/db/schema.d.ts +1 -1
- package/dist/events/release.d.ts +1 -1
- package/dist/events/scope.d.ts +1 -1
- package/dist/index.js +501 -838
- package/dist/issue-outcomes/store.d.ts +1 -1
- package/dist/pull-request-outcomes/store.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/tool-support/github-api.d.ts +40 -0
- package/dist/tools/stack-pull-request.d.ts +1 -1
- package/dist/webhooks/handler.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
readGrantPermissions,
|
|
60
60
|
requireEnv,
|
|
61
61
|
resolveUserAccount
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-NSAVG2P3.js";
|
|
63
63
|
|
|
64
64
|
// src/tool-support/attribution.ts
|
|
65
65
|
var GITHUB_REQUEST_ATTRIBUTION_START = "<!-- junior-request-attribution:start -->";
|
|
@@ -167,6 +167,73 @@ function appendGitHubRequesterAttribution(body, ctx, requester) {
|
|
|
167
167
|
);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
// src/tool-support/github-api.ts
|
|
171
|
+
import {
|
|
172
|
+
PluginToolInputError
|
|
173
|
+
} from "@sentry/junior-plugin-api";
|
|
174
|
+
var GITHUB_API_BASE = "https://api.github.com";
|
|
175
|
+
async function githubApi(egress, input) {
|
|
176
|
+
const headers = {
|
|
177
|
+
Accept: "application/vnd.github+json",
|
|
178
|
+
"X-GitHub-Api-Version": input.apiVersion ?? "2022-11-28"
|
|
179
|
+
};
|
|
180
|
+
if (input.body !== void 0) headers["Content-Type"] = "application/json";
|
|
181
|
+
const response = await egress.fetch({
|
|
182
|
+
provider: "github",
|
|
183
|
+
operation: input.operation,
|
|
184
|
+
request: new Request(`${GITHUB_API_BASE}${input.path}`, {
|
|
185
|
+
method: input.method ?? "GET",
|
|
186
|
+
headers,
|
|
187
|
+
signal: input.signal,
|
|
188
|
+
...input.body !== void 0 ? { body: JSON.stringify(input.body) } : void 0
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
return {
|
|
192
|
+
body: await readBody(response),
|
|
193
|
+
ok: response.ok,
|
|
194
|
+
status: response.status
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
async function readBody(response) {
|
|
198
|
+
const text2 = await response.text();
|
|
199
|
+
if (!text2) return void 0;
|
|
200
|
+
try {
|
|
201
|
+
return JSON.parse(text2);
|
|
202
|
+
} catch {
|
|
203
|
+
return text2;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function repoPath(repo) {
|
|
207
|
+
return `/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}`;
|
|
208
|
+
}
|
|
209
|
+
function parseRepo(value) {
|
|
210
|
+
const parts = value.split("/").map((part) => part.trim());
|
|
211
|
+
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
212
|
+
throw new PluginToolInputError('repo must use "owner/name" format');
|
|
213
|
+
}
|
|
214
|
+
return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
|
|
215
|
+
}
|
|
216
|
+
function githubErrorMessage(body) {
|
|
217
|
+
if (typeof body === "string" && body.trim()) return body.trim();
|
|
218
|
+
if (!isRecord2(body)) return "GitHub request failed";
|
|
219
|
+
const errors = Array.isArray(body.errors) ? body.errors.filter(isRecord2) : [];
|
|
220
|
+
if (typeof body.message === "string" && body.message.trim()) {
|
|
221
|
+
const details = errors.map(
|
|
222
|
+
(error) => ["resource", "field", "code", "message"].map((name) => {
|
|
223
|
+
const value = error[name];
|
|
224
|
+
return typeof value === "string" && value.trim() ? `${name}=${value.trim()}` : void 0;
|
|
225
|
+
}).filter(Boolean).join(" ")
|
|
226
|
+
).filter(Boolean).join("; ");
|
|
227
|
+
const message = body.message.trim();
|
|
228
|
+
return details ? `${message}: ${details}` : message;
|
|
229
|
+
}
|
|
230
|
+
const graphqlMessages = errors.map((error) => error.message).filter((message) => typeof message === "string" && message.trim());
|
|
231
|
+
return graphqlMessages.length ? graphqlMessages.join("; ") : "GitHub request failed";
|
|
232
|
+
}
|
|
233
|
+
function isRecord2(value) {
|
|
234
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
235
|
+
}
|
|
236
|
+
|
|
170
237
|
// src/plugin.ts
|
|
171
238
|
import {
|
|
172
239
|
defineJuniorPlugin,
|
|
@@ -176,10 +243,10 @@ import {
|
|
|
176
243
|
// src/tools/clone-repository.ts
|
|
177
244
|
import {
|
|
178
245
|
definePluginTool,
|
|
179
|
-
PluginToolInputError,
|
|
246
|
+
PluginToolInputError as PluginToolInputError2,
|
|
180
247
|
pluginToolOutputSchema
|
|
181
248
|
} from "@sentry/junior-plugin-api";
|
|
182
|
-
import
|
|
249
|
+
import * as z from "zod";
|
|
183
250
|
|
|
184
251
|
// src/sandbox-paths.ts
|
|
185
252
|
var RESERVED_SANDBOX_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
@@ -216,10 +283,10 @@ var outputSchema = pluginToolOutputSchema.merge(
|
|
|
216
283
|
target: z.literal("cloneRepository")
|
|
217
284
|
})
|
|
218
285
|
);
|
|
219
|
-
function
|
|
286
|
+
function parseRepo2(value) {
|
|
220
287
|
const parts = value.split("/").map((part) => part.trim());
|
|
221
288
|
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
222
|
-
throw new
|
|
289
|
+
throw new PluginToolInputError2('repo must use "owner/name" format');
|
|
223
290
|
}
|
|
224
291
|
return { owner: parts[0], name: parts[1] };
|
|
225
292
|
}
|
|
@@ -229,11 +296,11 @@ function quotedNames(workspaces) {
|
|
|
229
296
|
function workspaceRequiredError(repoId, workspaces) {
|
|
230
297
|
const names = quotedNames(workspaces);
|
|
231
298
|
if (workspaces.length === 1) {
|
|
232
|
-
return new
|
|
299
|
+
return new PluginToolInputError2(
|
|
233
300
|
`Repository ${repoId} is part of Workspace ${names}. Call switchWorkspace with that name; the checkout is already present after the switch. Pass allow_ad_hoc=true only for an intentional ad-hoc checkout.`
|
|
234
301
|
);
|
|
235
302
|
}
|
|
236
|
-
return new
|
|
303
|
+
return new PluginToolInputError2(
|
|
237
304
|
`Repository ${repoId} is part of Workspaces ${names}. Call switchWorkspace with one of those names; the checkout is already present after the switch. Pass allow_ad_hoc=true only for an intentional ad-hoc checkout.`
|
|
238
305
|
);
|
|
239
306
|
}
|
|
@@ -291,7 +358,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
291
358
|
inputSchema,
|
|
292
359
|
outputSchema,
|
|
293
360
|
async execute(input, options) {
|
|
294
|
-
const repo =
|
|
361
|
+
const repo = parseRepo2(input.repo);
|
|
295
362
|
const repoId = `${repo.owner}/${repo.name}`;
|
|
296
363
|
let workspaces = [];
|
|
297
364
|
let active;
|
|
@@ -319,7 +386,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
319
386
|
const directory = input.directory ?? defaultDirectory(repo.name);
|
|
320
387
|
const rootSegment = directory.split("/")[0] ?? directory;
|
|
321
388
|
if (isReservedSandboxDirectory(rootSegment)) {
|
|
322
|
-
throw new
|
|
389
|
+
throw new PluginToolInputError2(
|
|
323
390
|
`Directory conflicts with a reserved sandbox path: ${directory}`
|
|
324
391
|
);
|
|
325
392
|
}
|
|
@@ -333,7 +400,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
333
400
|
signal: commandSignal(options.signal, 3e4)
|
|
334
401
|
});
|
|
335
402
|
if (mkdir.exitCode !== 0) {
|
|
336
|
-
throw new
|
|
403
|
+
throw new PluginToolInputError2(
|
|
337
404
|
`Failed to create clone parent directory: ${parentDirectory}`
|
|
338
405
|
);
|
|
339
406
|
}
|
|
@@ -345,7 +412,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
345
412
|
signal: commandSignal(options.signal, 3e4)
|
|
346
413
|
});
|
|
347
414
|
if (exists.exitCode === 0) {
|
|
348
|
-
throw new
|
|
415
|
+
throw new PluginToolInputError2(`destination already exists: ${path}`);
|
|
349
416
|
}
|
|
350
417
|
let clone;
|
|
351
418
|
try {
|
|
@@ -368,7 +435,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
368
435
|
}
|
|
369
436
|
if (clone.exitCode !== 0) {
|
|
370
437
|
await removePartialClone(ctx, path);
|
|
371
|
-
throw new
|
|
438
|
+
throw new PluginToolInputError2(
|
|
372
439
|
`GitHub repository clone failed: ${clone.stderr.trim() || `exit ${clone.exitCode}`}`
|
|
373
440
|
);
|
|
374
441
|
}
|
|
@@ -385,10 +452,10 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
385
452
|
// src/tools/comment-on-pull-request.ts
|
|
386
453
|
import {
|
|
387
454
|
definePluginTool as definePluginTool2,
|
|
388
|
-
PluginToolInputError as
|
|
455
|
+
PluginToolInputError as PluginToolInputError3,
|
|
389
456
|
pluginToolOutputSchema as pluginToolOutputSchema2
|
|
390
457
|
} from "@sentry/junior-plugin-api";
|
|
391
|
-
import
|
|
458
|
+
import * as z2 from "zod";
|
|
392
459
|
var inputSchema2 = z2.object({
|
|
393
460
|
repo: z2.string().describe('Repository in "owner/name" format.'),
|
|
394
461
|
number: z2.number().int().positive().describe("Pull request number."),
|
|
@@ -404,29 +471,18 @@ var outputSchema2 = pluginToolOutputSchema2.extend({
|
|
|
404
471
|
comment_id: z2.number(),
|
|
405
472
|
url: z2.string()
|
|
406
473
|
});
|
|
407
|
-
function
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (!text2) return void 0;
|
|
417
|
-
try {
|
|
418
|
-
return JSON.parse(text2);
|
|
419
|
-
} catch {
|
|
420
|
-
return text2;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
function githubError(body) {
|
|
424
|
-
if (body && typeof body === "object" && !Array.isArray(body)) {
|
|
425
|
-
const message = body.message;
|
|
426
|
-
if (typeof message === "string" && message.trim()) return message.trim();
|
|
474
|
+
async function threadRootId(egress, prefix, commentId) {
|
|
475
|
+
const response = await githubApi(egress, {
|
|
476
|
+
operation: "github.pull.comment.get",
|
|
477
|
+
path: `${prefix}/pulls/comments/${commentId}`
|
|
478
|
+
});
|
|
479
|
+
if (!response.ok) {
|
|
480
|
+
const message = `GitHub review comment lookup failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
|
|
481
|
+
if (response.status === 404) throw new PluginToolInputError3(message);
|
|
482
|
+
throw new Error(message);
|
|
427
483
|
}
|
|
428
|
-
|
|
429
|
-
return
|
|
484
|
+
const comment = z2.object({ in_reply_to_id: z2.number().nullish() }).parse(response.body);
|
|
485
|
+
return comment.in_reply_to_id ?? commentId;
|
|
430
486
|
}
|
|
431
487
|
function createGitHubCommentOnPullRequestTool(egress) {
|
|
432
488
|
return definePluginTool2({
|
|
@@ -441,31 +497,23 @@ function createGitHubCommentOnPullRequestTool(egress) {
|
|
|
441
497
|
inputSchema: inputSchema2,
|
|
442
498
|
outputSchema: outputSchema2,
|
|
443
499
|
async execute(input) {
|
|
444
|
-
const repo =
|
|
445
|
-
const
|
|
446
|
-
const
|
|
447
|
-
const response = await egress
|
|
448
|
-
provider: "github",
|
|
500
|
+
const repo = parseRepo(input.repo);
|
|
501
|
+
const prefix = repoPath(repo);
|
|
502
|
+
const path = input.in_reply_to === void 0 ? `${prefix}/issues/${input.number}/comments` : `${prefix}/pulls/${input.number}/comments/${await threadRootId(egress, prefix, input.in_reply_to)}/replies`;
|
|
503
|
+
const response = await githubApi(egress, {
|
|
449
504
|
operation: "github.pull.comment.create",
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
Accept: "application/vnd.github+json",
|
|
454
|
-
"Content-Type": "application/json",
|
|
455
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
456
|
-
},
|
|
457
|
-
body: JSON.stringify({ body: input.body })
|
|
458
|
-
})
|
|
505
|
+
method: "POST",
|
|
506
|
+
path,
|
|
507
|
+
body: { body: input.body }
|
|
459
508
|
});
|
|
460
|
-
const parsed = await readJson(response);
|
|
461
509
|
if (!response.ok) {
|
|
462
|
-
const message = `GitHub pull request comment failed with HTTP ${response.status}: ${
|
|
510
|
+
const message = `GitHub pull request comment failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
|
|
463
511
|
if (response.status === 404 || response.status === 422) {
|
|
464
|
-
throw new
|
|
512
|
+
throw new PluginToolInputError3(message);
|
|
465
513
|
}
|
|
466
514
|
throw new Error(message);
|
|
467
515
|
}
|
|
468
|
-
const comment = z2.object({ id: z2.number(), html_url: z2.string() }).parse(
|
|
516
|
+
const comment = z2.object({ id: z2.number(), html_url: z2.string() }).parse(response.body);
|
|
469
517
|
return {
|
|
470
518
|
target: "commentOnPullRequest",
|
|
471
519
|
repo: repo.ref,
|
|
@@ -478,7 +526,7 @@ function createGitHubCommentOnPullRequestTool(egress) {
|
|
|
478
526
|
}
|
|
479
527
|
|
|
480
528
|
// src/object-facts.ts
|
|
481
|
-
import
|
|
529
|
+
import * as z3 from "zod";
|
|
482
530
|
var person = z3.object({ login: z3.string() });
|
|
483
531
|
var responseSchema = z3.object({
|
|
484
532
|
body: z3.string().nullable().optional(),
|
|
@@ -617,22 +665,22 @@ import {
|
|
|
617
665
|
objectFactsSchema,
|
|
618
666
|
definePluginTool as definePluginTool3,
|
|
619
667
|
EgressAuthRequired,
|
|
620
|
-
PluginToolInputError as
|
|
668
|
+
PluginToolInputError as PluginToolInputError5,
|
|
621
669
|
subscribableResourceSchema,
|
|
622
670
|
pluginToolOutputSchema as pluginToolOutputSchema3
|
|
623
671
|
} from "@sentry/junior-plugin-api";
|
|
624
672
|
import { Type } from "@sinclair/typebox";
|
|
625
673
|
import { Value } from "@sinclair/typebox/value";
|
|
626
|
-
import
|
|
674
|
+
import * as z4 from "zod";
|
|
627
675
|
|
|
628
676
|
// src/tools/footer.ts
|
|
629
|
-
import { PluginToolInputError as
|
|
677
|
+
import { PluginToolInputError as PluginToolInputError4 } from "@sentry/junior-plugin-api";
|
|
630
678
|
var GITHUB_SESSION_FOOTER_START = "<!-- junior-session-footer:start -->";
|
|
631
679
|
var GITHUB_SESSION_FOOTER_END = "<!-- junior-session-footer:end -->";
|
|
632
680
|
var GITHUB_CONVERSATION_ID_MARKER = "junior-conversation-id:";
|
|
633
681
|
function nonEmptyString(value, name) {
|
|
634
682
|
if (!value?.trim()) {
|
|
635
|
-
throw new
|
|
683
|
+
throw new PluginToolInputError4(`${name} is required`);
|
|
636
684
|
}
|
|
637
685
|
return value.trim();
|
|
638
686
|
}
|
|
@@ -709,11 +757,11 @@ function githubLinkedIssues(body, repositoryFullName) {
|
|
|
709
757
|
if (!body) return [];
|
|
710
758
|
const references = /* @__PURE__ */ new Map();
|
|
711
759
|
const add = (linkedRepository, rawNumber) => {
|
|
712
|
-
const
|
|
713
|
-
if (!Number.isInteger(
|
|
760
|
+
const number22 = Number.parseInt(rawNumber, 10);
|
|
761
|
+
if (!Number.isInteger(number22) || number22 <= 0) return;
|
|
714
762
|
const normalizedRepository = linkedRepository.toLowerCase();
|
|
715
|
-
references.set(`${normalizedRepository}#${
|
|
716
|
-
number,
|
|
763
|
+
references.set(`${normalizedRepository}#${number22}`, {
|
|
764
|
+
number: number22,
|
|
717
765
|
repositoryFullName: linkedRepository
|
|
718
766
|
});
|
|
719
767
|
};
|
|
@@ -816,7 +864,7 @@ var gitHubIssueOutputSchema = pluginToolOutputSchema3.merge(
|
|
|
816
864
|
})
|
|
817
865
|
);
|
|
818
866
|
function gitHubIssueToolResult(input, result, canSubscribe) {
|
|
819
|
-
const repo =
|
|
867
|
+
const repo = parseRepo(input.repo);
|
|
820
868
|
const subscribable = gitHubIssueSubscribable({
|
|
821
869
|
canSubscribe,
|
|
822
870
|
number: result.number,
|
|
@@ -849,51 +897,17 @@ function parseCreateIssueInput(input) {
|
|
|
849
897
|
try {
|
|
850
898
|
return Value.Parse(createIssueInputSchema, input);
|
|
851
899
|
} catch (error) {
|
|
852
|
-
throw new
|
|
900
|
+
throw new PluginToolInputError5("Invalid GitHub createIssue input.", {
|
|
853
901
|
cause: error
|
|
854
902
|
});
|
|
855
903
|
}
|
|
856
904
|
}
|
|
857
905
|
function nonEmptyString2(value, name) {
|
|
858
906
|
if (!value?.trim()) {
|
|
859
|
-
throw new
|
|
907
|
+
throw new PluginToolInputError5(`${name} is required`);
|
|
860
908
|
}
|
|
861
909
|
return value.trim();
|
|
862
910
|
}
|
|
863
|
-
function parseRepo3(value) {
|
|
864
|
-
const repo = nonEmptyString2(value, "repo");
|
|
865
|
-
const parts = repo.split("/");
|
|
866
|
-
if (parts.length !== 2 || !parts[0]?.trim() || !parts[1]?.trim()) {
|
|
867
|
-
throw new PluginToolInputError4('repo must use "owner/name" format');
|
|
868
|
-
}
|
|
869
|
-
return {
|
|
870
|
-
owner: parts[0].trim(),
|
|
871
|
-
name: parts[1].trim()
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
async function readJsonResponse(response) {
|
|
875
|
-
const text2 = await response.text();
|
|
876
|
-
if (!text2) {
|
|
877
|
-
return void 0;
|
|
878
|
-
}
|
|
879
|
-
try {
|
|
880
|
-
return JSON.parse(text2);
|
|
881
|
-
} catch {
|
|
882
|
-
return text2;
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
function githubApiErrorMessage(payload) {
|
|
886
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
887
|
-
const message = payload.message;
|
|
888
|
-
if (typeof message === "string") {
|
|
889
|
-
return message;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
if (typeof payload === "string" && payload.trim()) {
|
|
893
|
-
return payload.trim();
|
|
894
|
-
}
|
|
895
|
-
return "GitHub request failed";
|
|
896
|
-
}
|
|
897
911
|
function createIssueState(value) {
|
|
898
912
|
if (value === void 0) {
|
|
899
913
|
return void 0;
|
|
@@ -916,7 +930,7 @@ function isDefinitiveGitHubIssueCreateRejection(error) {
|
|
|
916
930
|
return [400, 401, 404, 410, 422].includes(error.status);
|
|
917
931
|
}
|
|
918
932
|
async function createGitHubIssueRequest(conversationId, input, ctx, dashboardUrl) {
|
|
919
|
-
const repo =
|
|
933
|
+
const repo = parseRepo(input.repo);
|
|
920
934
|
const labels = input.labels?.map(
|
|
921
935
|
(label) => nonEmptyString2(label, "labels entry")
|
|
922
936
|
);
|
|
@@ -933,31 +947,18 @@ async function createGitHubIssueRequest(conversationId, input, ctx, dashboardUrl
|
|
|
933
947
|
),
|
|
934
948
|
...labels?.length ? { labels } : void 0
|
|
935
949
|
};
|
|
936
|
-
return
|
|
937
|
-
`https://api.github.com/repos/${encodeURIComponent(
|
|
938
|
-
repo.owner
|
|
939
|
-
)}/${encodeURIComponent(repo.name)}/issues`,
|
|
940
|
-
{
|
|
941
|
-
method: "POST",
|
|
942
|
-
headers: {
|
|
943
|
-
Accept: "application/vnd.github+json",
|
|
944
|
-
"Content-Type": "application/json",
|
|
945
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
946
|
-
},
|
|
947
|
-
body: JSON.stringify(payload)
|
|
948
|
-
}
|
|
949
|
-
);
|
|
950
|
+
return { path: `${repoPath(repo)}/issues`, body: payload };
|
|
950
951
|
}
|
|
951
952
|
async function createGitHubIssue(ctx, request) {
|
|
952
|
-
const response = await ctx.egress
|
|
953
|
-
provider: "github",
|
|
953
|
+
const response = await githubApi(ctx.egress, {
|
|
954
954
|
operation: "github.issue.create",
|
|
955
|
-
|
|
955
|
+
method: "POST",
|
|
956
|
+
...request
|
|
956
957
|
});
|
|
957
|
-
const parsed =
|
|
958
|
+
const parsed = response.body;
|
|
958
959
|
if (!response.ok) {
|
|
959
960
|
throw new GitHubIssueCreateRejectedError(
|
|
960
|
-
`GitHub issue creation failed with HTTP ${response.status}: ${
|
|
961
|
+
`GitHub issue creation failed with HTTP ${response.status}: ${githubErrorMessage(
|
|
961
962
|
parsed
|
|
962
963
|
)}`,
|
|
963
964
|
response.status
|
|
@@ -1071,11 +1072,11 @@ function createGitHubIssueTool(ctx) {
|
|
|
1071
1072
|
// src/tools/get-deployment.ts
|
|
1072
1073
|
import {
|
|
1073
1074
|
definePluginTool as definePluginTool4,
|
|
1074
|
-
PluginToolInputError as
|
|
1075
|
+
PluginToolInputError as PluginToolInputError6,
|
|
1075
1076
|
pluginToolOutputSchema as pluginToolOutputSchema4,
|
|
1076
1077
|
subscribableResourceSchema as subscribableResourceSchema2
|
|
1077
1078
|
} from "@sentry/junior-plugin-api";
|
|
1078
|
-
import
|
|
1079
|
+
import * as z5 from "zod";
|
|
1079
1080
|
var commitShaSchema = z5.string().regex(/^[0-9a-f]{40}$/i);
|
|
1080
1081
|
var inputSchema3 = z5.object({
|
|
1081
1082
|
repo: z5.string().describe('Repository in "owner/name" format.'),
|
|
@@ -1139,33 +1140,14 @@ var providerStatusSchema = z5.object({
|
|
|
1139
1140
|
log_url: z5.string().nullable().optional(),
|
|
1140
1141
|
state: z5.string()
|
|
1141
1142
|
}).passthrough();
|
|
1142
|
-
function parseRepo4(value) {
|
|
1143
|
-
const parts = value.split("/").map((part) => part.trim());
|
|
1144
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
1145
|
-
throw new PluginToolInputError5('repo must use "owner/name" format');
|
|
1146
|
-
}
|
|
1147
|
-
return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
|
|
1148
|
-
}
|
|
1149
|
-
async function readJson2(response) {
|
|
1150
|
-
const text2 = await response.text();
|
|
1151
|
-
if (!text2) return void 0;
|
|
1152
|
-
try {
|
|
1153
|
-
return JSON.parse(text2);
|
|
1154
|
-
} catch {
|
|
1155
|
-
return text2;
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
1143
|
function throwLookupError(target, status, body) {
|
|
1159
1144
|
const message = `GitHub ${target} lookup failed with HTTP ${status}`;
|
|
1160
1145
|
const hasValidationErrors = body !== null && typeof body === "object" && !Array.isArray(body) && Array.isArray(body.errors) && body.errors.length > 0;
|
|
1161
1146
|
if (target === "deployment" && (status === 404 || status === 422 && hasValidationErrors)) {
|
|
1162
|
-
throw new
|
|
1147
|
+
throw new PluginToolInputError6(message);
|
|
1163
1148
|
}
|
|
1164
1149
|
throw new Error(message);
|
|
1165
1150
|
}
|
|
1166
|
-
function repositoryUrl(repo, path) {
|
|
1167
|
-
return `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/${path}`;
|
|
1168
|
-
}
|
|
1169
1151
|
function createGitHubGetDeploymentTool(ctx) {
|
|
1170
1152
|
return definePluginTool4({
|
|
1171
1153
|
annotations: {
|
|
@@ -1178,57 +1160,31 @@ function createGitHubGetDeploymentTool(ctx) {
|
|
|
1178
1160
|
inputSchema: inputSchema3,
|
|
1179
1161
|
outputSchema: outputSchema3,
|
|
1180
1162
|
async execute(input) {
|
|
1181
|
-
const repo =
|
|
1163
|
+
const repo = parseRepo(input.repo);
|
|
1182
1164
|
const commitSha = input.commit_sha.toLowerCase();
|
|
1183
|
-
const
|
|
1184
|
-
deploymentsUrl.searchParams.set("sha", commitSha);
|
|
1165
|
+
const deploymentsQuery = new URLSearchParams({ sha: commitSha });
|
|
1185
1166
|
if (input.environment) {
|
|
1186
|
-
|
|
1167
|
+
deploymentsQuery.set("environment", input.environment);
|
|
1187
1168
|
}
|
|
1188
|
-
|
|
1189
|
-
const
|
|
1190
|
-
provider: "github",
|
|
1169
|
+
deploymentsQuery.set("per_page", "1");
|
|
1170
|
+
const deployments = await githubApi(ctx.egress, {
|
|
1191
1171
|
operation: "github.deployment.list",
|
|
1192
|
-
|
|
1193
|
-
headers: {
|
|
1194
|
-
Accept: "application/vnd.github+json",
|
|
1195
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
1196
|
-
}
|
|
1197
|
-
})
|
|
1172
|
+
path: `${repoPath(repo)}/deployments?${deploymentsQuery}`
|
|
1198
1173
|
});
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
throwLookupError(
|
|
1202
|
-
"deployment",
|
|
1203
|
-
deploymentsResponse.status,
|
|
1204
|
-
deploymentsBody
|
|
1205
|
-
);
|
|
1174
|
+
if (!deployments.ok) {
|
|
1175
|
+
throwLookupError("deployment", deployments.status, deployments.body);
|
|
1206
1176
|
}
|
|
1207
|
-
const providerDeployment = z5.array(providerDeploymentSchema).parse(
|
|
1177
|
+
const providerDeployment = z5.array(providerDeploymentSchema).parse(deployments.body)[0];
|
|
1208
1178
|
let deployment = null;
|
|
1209
1179
|
if (providerDeployment) {
|
|
1210
|
-
const
|
|
1211
|
-
provider: "github",
|
|
1180
|
+
const statuses = await githubApi(ctx.egress, {
|
|
1212
1181
|
operation: "github.deployment-status.list",
|
|
1213
|
-
|
|
1214
|
-
`${repositoryUrl(repo, `deployments/${providerDeployment.id}/statuses`)}?per_page=1`,
|
|
1215
|
-
{
|
|
1216
|
-
headers: {
|
|
1217
|
-
Accept: "application/vnd.github+json",
|
|
1218
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
)
|
|
1182
|
+
path: `${repoPath(repo)}/deployments/${providerDeployment.id}/statuses?per_page=1`
|
|
1222
1183
|
});
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
throwLookupError(
|
|
1226
|
-
"deployment status",
|
|
1227
|
-
statusesResponse.status,
|
|
1228
|
-
statusesBody
|
|
1229
|
-
);
|
|
1184
|
+
if (!statuses.ok) {
|
|
1185
|
+
throwLookupError("deployment status", statuses.status, statuses.body);
|
|
1230
1186
|
}
|
|
1231
|
-
const providerStatus = z5.array(providerStatusSchema).parse(
|
|
1187
|
+
const providerStatus = z5.array(providerStatusSchema).parse(statuses.body)[0];
|
|
1232
1188
|
deployment = {
|
|
1233
1189
|
created_at: providerDeployment.created_at,
|
|
1234
1190
|
creator: providerDeployment.creator?.login ?? null,
|
|
@@ -1276,14 +1232,14 @@ import {
|
|
|
1276
1232
|
objectFactsSchema as objectFactsSchema2,
|
|
1277
1233
|
definePluginTool as definePluginTool5,
|
|
1278
1234
|
EgressAuthRequired as EgressAuthRequired2,
|
|
1279
|
-
PluginToolInputError as
|
|
1235
|
+
PluginToolInputError as PluginToolInputError7,
|
|
1280
1236
|
pluginToolOutputSchema as pluginToolOutputSchema5,
|
|
1281
1237
|
watchResultSchema,
|
|
1282
1238
|
subscribableResourceSchema as subscribableResourceSchema3
|
|
1283
1239
|
} from "@sentry/junior-plugin-api";
|
|
1284
1240
|
import { Type as Type2 } from "@sinclair/typebox";
|
|
1285
1241
|
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
1286
|
-
import
|
|
1242
|
+
import * as z8 from "zod";
|
|
1287
1243
|
|
|
1288
1244
|
// src/pull-request-requesters/store.ts
|
|
1289
1245
|
import { and, asc, eq, inArray, lt } from "drizzle-orm";
|
|
@@ -1298,7 +1254,7 @@ import {
|
|
|
1298
1254
|
text,
|
|
1299
1255
|
timestamp
|
|
1300
1256
|
} from "drizzle-orm/pg-core";
|
|
1301
|
-
import
|
|
1257
|
+
import * as z6 from "zod";
|
|
1302
1258
|
var githubPullRequestStateSchema = z6.enum([
|
|
1303
1259
|
"closed_unmerged",
|
|
1304
1260
|
"merged",
|
|
@@ -1470,12 +1426,9 @@ async function listGitHubPullRequestOpeners(db, input) {
|
|
|
1470
1426
|
}
|
|
1471
1427
|
|
|
1472
1428
|
// src/tools/stack-pull-request.ts
|
|
1473
|
-
import
|
|
1429
|
+
import * as z7 from "zod";
|
|
1474
1430
|
var MAX_STACK_DEPTH = 10;
|
|
1475
|
-
var
|
|
1476
|
-
Accept: "application/vnd.github+json",
|
|
1477
|
-
"X-GitHub-Api-Version": "2026-03-10"
|
|
1478
|
-
};
|
|
1431
|
+
var GITHUB_STACKS_API_VERSION = "2026-03-10";
|
|
1479
1432
|
var stackTargetSchema = z7.object({
|
|
1480
1433
|
number: z7.number().int().positive(),
|
|
1481
1434
|
head: z7.object({
|
|
@@ -1505,16 +1458,13 @@ async function stackGitHubPullRequest(ctx, target) {
|
|
|
1505
1458
|
return void 0;
|
|
1506
1459
|
}
|
|
1507
1460
|
const [owner, name] = repo.split("/");
|
|
1508
|
-
const api =
|
|
1509
|
-
const github = async (operation,
|
|
1510
|
-
const response = await ctx.egress
|
|
1511
|
-
|
|
1461
|
+
const api = repoPath({ owner, name });
|
|
1462
|
+
const github = async (operation, path, schema, body) => {
|
|
1463
|
+
const response = await githubApi(ctx.egress, {
|
|
1464
|
+
apiVersion: GITHUB_STACKS_API_VERSION,
|
|
1512
1465
|
operation,
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
headers: body === void 0 ? GITHUB_HEADERS : { ...GITHUB_HEADERS, "Content-Type": "application/json" },
|
|
1516
|
-
...body === void 0 ? void 0 : { body: JSON.stringify(body) }
|
|
1517
|
-
})
|
|
1466
|
+
path,
|
|
1467
|
+
...body === void 0 ? void 0 : { method: "POST", body }
|
|
1518
1468
|
});
|
|
1519
1469
|
if (!response.ok) {
|
|
1520
1470
|
ctx.log.warn("github.pull_request.stack_after_create.rejected", {
|
|
@@ -1525,7 +1475,7 @@ async function stackGitHubPullRequest(ctx, target) {
|
|
|
1525
1475
|
});
|
|
1526
1476
|
return void 0;
|
|
1527
1477
|
}
|
|
1528
|
-
return schema.parse(
|
|
1478
|
+
return schema.parse(response.body);
|
|
1529
1479
|
};
|
|
1530
1480
|
const result = (stack) => ({
|
|
1531
1481
|
number: stack.number,
|
|
@@ -1670,70 +1620,17 @@ function parseCreatePullRequestInput(input) {
|
|
|
1670
1620
|
try {
|
|
1671
1621
|
return Value2.Parse(createPullRequestInputSchema, input);
|
|
1672
1622
|
} catch (error) {
|
|
1673
|
-
throw new
|
|
1623
|
+
throw new PluginToolInputError7("Invalid GitHub createPullRequest input.", {
|
|
1674
1624
|
cause: error
|
|
1675
1625
|
});
|
|
1676
1626
|
}
|
|
1677
1627
|
}
|
|
1678
1628
|
function nonEmptyString3(value, name) {
|
|
1679
1629
|
if (!value?.trim()) {
|
|
1680
|
-
throw new
|
|
1630
|
+
throw new PluginToolInputError7(`${name} is required`);
|
|
1681
1631
|
}
|
|
1682
1632
|
return value.trim();
|
|
1683
1633
|
}
|
|
1684
|
-
function parseRepo5(value) {
|
|
1685
|
-
const repo = nonEmptyString3(value, "repo");
|
|
1686
|
-
const parts = repo.split("/");
|
|
1687
|
-
if (parts.length !== 2 || !parts[0]?.trim() || !parts[1]?.trim()) {
|
|
1688
|
-
throw new PluginToolInputError6('repo must use "owner/name" format');
|
|
1689
|
-
}
|
|
1690
|
-
return {
|
|
1691
|
-
owner: parts[0].trim(),
|
|
1692
|
-
name: parts[1].trim()
|
|
1693
|
-
};
|
|
1694
|
-
}
|
|
1695
|
-
async function readJsonResponse2(response) {
|
|
1696
|
-
const text2 = await response.text();
|
|
1697
|
-
if (!text2) {
|
|
1698
|
-
return void 0;
|
|
1699
|
-
}
|
|
1700
|
-
try {
|
|
1701
|
-
return JSON.parse(text2);
|
|
1702
|
-
} catch {
|
|
1703
|
-
return text2;
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
function githubApiErrorMessage2(payload) {
|
|
1707
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
1708
|
-
const record = payload;
|
|
1709
|
-
const message = record.message;
|
|
1710
|
-
if (typeof message === "string") {
|
|
1711
|
-
const details = githubApiErrorDetails(record);
|
|
1712
|
-
return details ? `${message}: ${details}` : message;
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
if (typeof payload === "string" && payload.trim()) {
|
|
1716
|
-
return payload.trim();
|
|
1717
|
-
}
|
|
1718
|
-
return "GitHub request failed";
|
|
1719
|
-
}
|
|
1720
|
-
function githubApiErrorDetails(payload) {
|
|
1721
|
-
const errors = payload.errors;
|
|
1722
|
-
if (!Array.isArray(errors)) {
|
|
1723
|
-
return void 0;
|
|
1724
|
-
}
|
|
1725
|
-
const details = errors.map((error) => {
|
|
1726
|
-
if (!error || typeof error !== "object" || Array.isArray(error)) {
|
|
1727
|
-
return void 0;
|
|
1728
|
-
}
|
|
1729
|
-
const fields = ["resource", "field", "code", "message"].map((name) => {
|
|
1730
|
-
const value = error[name];
|
|
1731
|
-
return typeof value === "string" && value.trim() ? `${name}=${value.trim()}` : void 0;
|
|
1732
|
-
}).filter((value) => value !== void 0);
|
|
1733
|
-
return fields.length ? fields.join(" ") : void 0;
|
|
1734
|
-
}).filter((value) => value !== void 0);
|
|
1735
|
-
return details.length ? details.join("; ") : void 0;
|
|
1736
|
-
}
|
|
1737
1634
|
function createPullRequestState(value) {
|
|
1738
1635
|
if (value === void 0) {
|
|
1739
1636
|
return void 0;
|
|
@@ -1756,7 +1653,7 @@ function isDefinitiveGitHubPullRequestCreateRejection(error) {
|
|
|
1756
1653
|
return [400, 401, 404, 410, 422].includes(error.status);
|
|
1757
1654
|
}
|
|
1758
1655
|
function createGitHubPullRequestRequest(conversationId, input, ctx, requester, dashboardUrl) {
|
|
1759
|
-
const repo =
|
|
1656
|
+
const repo = parseRepo(input.repo);
|
|
1760
1657
|
const payload = {
|
|
1761
1658
|
title: nonEmptyString3(input.title, "title"),
|
|
1762
1659
|
head: nonEmptyString3(input.head, "head"),
|
|
@@ -1768,31 +1665,18 @@ function createGitHubPullRequestRequest(conversationId, input, ctx, requester, d
|
|
|
1768
1665
|
),
|
|
1769
1666
|
...input.draft !== void 0 ? { draft: input.draft } : void 0
|
|
1770
1667
|
};
|
|
1771
|
-
return
|
|
1772
|
-
`https://api.github.com/repos/${encodeURIComponent(
|
|
1773
|
-
repo.owner
|
|
1774
|
-
)}/${encodeURIComponent(repo.name)}/pulls`,
|
|
1775
|
-
{
|
|
1776
|
-
method: "POST",
|
|
1777
|
-
headers: {
|
|
1778
|
-
Accept: "application/vnd.github+json",
|
|
1779
|
-
"Content-Type": "application/json",
|
|
1780
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
1781
|
-
},
|
|
1782
|
-
body: JSON.stringify(payload)
|
|
1783
|
-
}
|
|
1784
|
-
);
|
|
1668
|
+
return { path: `${repoPath(repo)}/pulls`, body: payload };
|
|
1785
1669
|
}
|
|
1786
1670
|
async function createGitHubPullRequest(ctx, request) {
|
|
1787
|
-
const response = await ctx.egress
|
|
1788
|
-
provider: "github",
|
|
1671
|
+
const response = await githubApi(ctx.egress, {
|
|
1789
1672
|
operation: "github.pull.create",
|
|
1790
|
-
|
|
1673
|
+
method: "POST",
|
|
1674
|
+
...request
|
|
1791
1675
|
});
|
|
1792
|
-
const parsed =
|
|
1676
|
+
const parsed = response.body;
|
|
1793
1677
|
if (!response.ok) {
|
|
1794
1678
|
throw new GitHubPullRequestCreateRejectedError(
|
|
1795
|
-
`GitHub pull request creation failed with HTTP ${response.status}: ${
|
|
1679
|
+
`GitHub pull request creation failed with HTTP ${response.status}: ${githubErrorMessage(
|
|
1796
1680
|
parsed
|
|
1797
1681
|
)}`,
|
|
1798
1682
|
response.status
|
|
@@ -1822,35 +1706,25 @@ async function createGitHubPullRequest(ctx, request) {
|
|
|
1822
1706
|
async function recordOpener(ctx, input, state, requester) {
|
|
1823
1707
|
const { conversationId, identityId } = requester;
|
|
1824
1708
|
if (!identityId) return;
|
|
1825
|
-
const repo =
|
|
1709
|
+
const repo = parseRepo(input.repo);
|
|
1826
1710
|
await recordGitHubPullRequestOpener(ctx.db, {
|
|
1827
1711
|
conversationId,
|
|
1828
1712
|
createdAt: new Date(state.createdAtMs),
|
|
1829
1713
|
identityId,
|
|
1830
1714
|
number: state.number,
|
|
1831
|
-
repositoryFullName:
|
|
1715
|
+
repositoryFullName: repo.ref
|
|
1832
1716
|
});
|
|
1833
1717
|
}
|
|
1834
1718
|
async function assignPullRequestRequester(ctx, input, result, requester) {
|
|
1835
1719
|
const assignee = linkedGitHubLogin(requester?.user);
|
|
1836
1720
|
if (!assignee) return;
|
|
1837
1721
|
try {
|
|
1838
|
-
const repo =
|
|
1839
|
-
const response = await ctx.egress
|
|
1840
|
-
provider: "github",
|
|
1722
|
+
const repo = parseRepo(input.repo);
|
|
1723
|
+
const response = await githubApi(ctx.egress, {
|
|
1841
1724
|
operation: "github.pull.assign",
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
method: "POST",
|
|
1846
|
-
headers: {
|
|
1847
|
-
Accept: "application/vnd.github+json",
|
|
1848
|
-
"Content-Type": "application/json",
|
|
1849
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
1850
|
-
},
|
|
1851
|
-
body: JSON.stringify({ assignees: [assignee] })
|
|
1852
|
-
}
|
|
1853
|
-
)
|
|
1725
|
+
method: "POST",
|
|
1726
|
+
path: `${repoPath(repo)}/issues/${result.number}/assignees`,
|
|
1727
|
+
body: { assignees: [assignee] }
|
|
1854
1728
|
});
|
|
1855
1729
|
if (!response.ok) {
|
|
1856
1730
|
ctx.log.warn("github.pull_request.assign_after_create.rejected", {
|
|
@@ -1868,7 +1742,7 @@ async function assignPullRequestRequester(ctx, input, result, requester) {
|
|
|
1868
1742
|
}
|
|
1869
1743
|
}
|
|
1870
1744
|
function gitHubPullRequestToolResult(input, result, canSubscribe, omitSuggestedEvents) {
|
|
1871
|
-
const repo =
|
|
1745
|
+
const repo = parseRepo(input.repo);
|
|
1872
1746
|
const subscribable = gitHubPullRequestSubscribable({
|
|
1873
1747
|
canSubscribe,
|
|
1874
1748
|
number: result.number,
|
|
@@ -2062,10 +1936,10 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
2062
1936
|
// src/tools/get-pull-request.ts
|
|
2063
1937
|
import {
|
|
2064
1938
|
definePluginTool as definePluginTool6,
|
|
2065
|
-
PluginToolInputError as
|
|
1939
|
+
PluginToolInputError as PluginToolInputError8,
|
|
2066
1940
|
pluginToolOutputSchema as pluginToolOutputSchema6
|
|
2067
1941
|
} from "@sentry/junior-plugin-api";
|
|
2068
|
-
import
|
|
1942
|
+
import * as z9 from "zod";
|
|
2069
1943
|
import { subscribableResourceSchema as subscribableResourceSchema4 } from "@sentry/junior-plugin-api";
|
|
2070
1944
|
var commitShaSchema2 = z9.string().regex(/^[0-9a-f]{40}$/i);
|
|
2071
1945
|
var inputSchema4 = z9.object({
|
|
@@ -2089,22 +1963,6 @@ var outputSchema4 = pluginToolOutputSchema6.merge(
|
|
|
2089
1963
|
target: z9.literal("getPullRequest")
|
|
2090
1964
|
})
|
|
2091
1965
|
);
|
|
2092
|
-
function parseRepo6(value) {
|
|
2093
|
-
const parts = value.split("/").map((part) => part.trim());
|
|
2094
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
2095
|
-
throw new PluginToolInputError7('repo must use "owner/name" format');
|
|
2096
|
-
}
|
|
2097
|
-
return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
|
|
2098
|
-
}
|
|
2099
|
-
async function readJson3(response) {
|
|
2100
|
-
const text2 = await response.text();
|
|
2101
|
-
if (!text2) return void 0;
|
|
2102
|
-
try {
|
|
2103
|
-
return JSON.parse(text2);
|
|
2104
|
-
} catch {
|
|
2105
|
-
return text2;
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
1966
|
function createGitHubGetPullRequestTool(ctx) {
|
|
2109
1967
|
return definePluginTool6({
|
|
2110
1968
|
annotations: {
|
|
@@ -2117,25 +1975,15 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2117
1975
|
inputSchema: inputSchema4,
|
|
2118
1976
|
outputSchema: outputSchema4,
|
|
2119
1977
|
async execute(input) {
|
|
2120
|
-
const repo =
|
|
2121
|
-
const response = await ctx.egress
|
|
2122
|
-
provider: "github",
|
|
1978
|
+
const repo = parseRepo(input.repo);
|
|
1979
|
+
const response = await githubApi(ctx.egress, {
|
|
2123
1980
|
operation: "github.pull.get",
|
|
2124
|
-
|
|
2125
|
-
`https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/pulls/${input.number}`,
|
|
2126
|
-
{
|
|
2127
|
-
headers: {
|
|
2128
|
-
Accept: "application/vnd.github+json",
|
|
2129
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
)
|
|
1981
|
+
path: `${repoPath(repo)}/pulls/${input.number}`
|
|
2133
1982
|
});
|
|
2134
|
-
const parsed = await readJson3(response);
|
|
2135
1983
|
if (!response.ok) {
|
|
2136
1984
|
const message = `GitHub pull request lookup failed with HTTP ${response.status}`;
|
|
2137
1985
|
if (response.status === 404) {
|
|
2138
|
-
throw new
|
|
1986
|
+
throw new PluginToolInputError8(message);
|
|
2139
1987
|
}
|
|
2140
1988
|
throw new Error(message);
|
|
2141
1989
|
}
|
|
@@ -2148,7 +1996,7 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2148
1996
|
number: z9.number(),
|
|
2149
1997
|
state: z9.string(),
|
|
2150
1998
|
title: z9.string()
|
|
2151
|
-
}).parse(
|
|
1999
|
+
}).parse(response.body);
|
|
2152
2000
|
const subscribable = gitHubPullRequestSubscribable({
|
|
2153
2001
|
canSubscribe: ctx.events.canSubscribe,
|
|
2154
2002
|
number: providerResult.number,
|
|
@@ -2175,7 +2023,7 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2175
2023
|
url: data.url,
|
|
2176
2024
|
objectType: "code_change",
|
|
2177
2025
|
status: data.merged ? "merged" : data.state === "open" && data.draft ? "draft" : data.state,
|
|
2178
|
-
...githubObjectFacts("code_change",
|
|
2026
|
+
...githubObjectFacts("code_change", response.body)
|
|
2179
2027
|
})
|
|
2180
2028
|
],
|
|
2181
2029
|
target: "getPullRequest",
|
|
@@ -2188,11 +2036,10 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2188
2036
|
// src/tools/get-release.ts
|
|
2189
2037
|
import {
|
|
2190
2038
|
definePluginTool as definePluginTool7,
|
|
2191
|
-
PluginToolInputError as PluginToolInputError8,
|
|
2192
2039
|
pluginToolOutputSchema as pluginToolOutputSchema7,
|
|
2193
2040
|
subscribableResourceSchema as subscribableResourceSchema5
|
|
2194
2041
|
} from "@sentry/junior-plugin-api";
|
|
2195
|
-
import
|
|
2042
|
+
import * as z10 from "zod";
|
|
2196
2043
|
var inputSchema5 = z10.object({
|
|
2197
2044
|
repo: z10.string().describe('Repository in "owner/name" format.'),
|
|
2198
2045
|
tag: z10.string().trim().min(1).describe(
|
|
@@ -2232,25 +2079,6 @@ var providerReleaseSchema = z10.object({
|
|
|
2232
2079
|
tag_name: z10.string(),
|
|
2233
2080
|
target_commitish: z10.string()
|
|
2234
2081
|
}).passthrough();
|
|
2235
|
-
function parseRepo7(value) {
|
|
2236
|
-
const parts = value.split("/").map((part) => part.trim());
|
|
2237
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
2238
|
-
throw new PluginToolInputError8('repo must use "owner/name" format');
|
|
2239
|
-
}
|
|
2240
|
-
return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
|
|
2241
|
-
}
|
|
2242
|
-
async function readJson4(response) {
|
|
2243
|
-
const text2 = await response.text();
|
|
2244
|
-
if (!text2) return void 0;
|
|
2245
|
-
try {
|
|
2246
|
-
return JSON.parse(text2);
|
|
2247
|
-
} catch {
|
|
2248
|
-
return text2;
|
|
2249
|
-
}
|
|
2250
|
-
}
|
|
2251
|
-
function repositoryUrl2(repo, path) {
|
|
2252
|
-
return `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/${path}`;
|
|
2253
|
-
}
|
|
2254
2082
|
function mapRelease(providerRelease) {
|
|
2255
2083
|
return {
|
|
2256
2084
|
created_at: providerRelease.created_at,
|
|
@@ -2276,45 +2104,28 @@ function createGitHubGetReleaseTool(ctx) {
|
|
|
2276
2104
|
inputSchema: inputSchema5,
|
|
2277
2105
|
outputSchema: outputSchema5,
|
|
2278
2106
|
async execute(input) {
|
|
2279
|
-
const repo =
|
|
2107
|
+
const repo = parseRepo(input.repo);
|
|
2280
2108
|
const tag = input.tag?.trim() || void 0;
|
|
2281
2109
|
let release = null;
|
|
2282
2110
|
if (tag) {
|
|
2283
|
-
const response = await ctx.egress
|
|
2284
|
-
provider: "github",
|
|
2111
|
+
const response = await githubApi(ctx.egress, {
|
|
2285
2112
|
operation: "github.release.get",
|
|
2286
|
-
|
|
2287
|
-
repositoryUrl2(repo, `releases/tags/${encodeURIComponent(tag)}`),
|
|
2288
|
-
{
|
|
2289
|
-
headers: {
|
|
2290
|
-
Accept: "application/vnd.github+json",
|
|
2291
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
)
|
|
2113
|
+
path: `${repoPath(repo)}/releases/tags/${encodeURIComponent(tag)}`
|
|
2295
2114
|
});
|
|
2296
|
-
const body = await readJson4(response);
|
|
2297
2115
|
if (response.ok) {
|
|
2298
|
-
release = mapRelease(providerReleaseSchema.parse(body));
|
|
2116
|
+
release = mapRelease(providerReleaseSchema.parse(response.body));
|
|
2299
2117
|
} else if (response.status !== 404) {
|
|
2300
2118
|
throw new Error(
|
|
2301
2119
|
`GitHub release lookup failed with HTTP ${response.status}`
|
|
2302
2120
|
);
|
|
2303
2121
|
}
|
|
2304
2122
|
} else {
|
|
2305
|
-
const response = await ctx.egress
|
|
2306
|
-
provider: "github",
|
|
2123
|
+
const response = await githubApi(ctx.egress, {
|
|
2307
2124
|
operation: "github.release.latest",
|
|
2308
|
-
|
|
2309
|
-
headers: {
|
|
2310
|
-
Accept: "application/vnd.github+json",
|
|
2311
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
2312
|
-
}
|
|
2313
|
-
})
|
|
2125
|
+
path: `${repoPath(repo)}/releases/latest`
|
|
2314
2126
|
});
|
|
2315
|
-
const body = await readJson4(response);
|
|
2316
2127
|
if (response.ok) {
|
|
2317
|
-
release = mapRelease(providerReleaseSchema.parse(body));
|
|
2128
|
+
release = mapRelease(providerReleaseSchema.parse(response.body));
|
|
2318
2129
|
} else if (response.status === 404) {
|
|
2319
2130
|
release = null;
|
|
2320
2131
|
} else {
|
|
@@ -2349,7 +2160,7 @@ import {
|
|
|
2349
2160
|
pluginToolOutputSchema as pluginToolOutputSchema8,
|
|
2350
2161
|
subscribableResourceSchema as subscribableResourceSchema6
|
|
2351
2162
|
} from "@sentry/junior-plugin-api";
|
|
2352
|
-
import
|
|
2163
|
+
import * as z11 from "zod";
|
|
2353
2164
|
var inputSchema6 = z11.object({
|
|
2354
2165
|
repo: z11.string().describe('Repository in "owner/name" format.')
|
|
2355
2166
|
}).strict();
|
|
@@ -2366,22 +2177,6 @@ var outputSchema6 = pluginToolOutputSchema8.merge(
|
|
|
2366
2177
|
target: z11.literal("getRepository")
|
|
2367
2178
|
})
|
|
2368
2179
|
);
|
|
2369
|
-
function parseRepo8(value) {
|
|
2370
|
-
const parts = value.split("/").map((part) => part.trim());
|
|
2371
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
2372
|
-
throw new PluginToolInputError9('repo must use "owner/name" format');
|
|
2373
|
-
}
|
|
2374
|
-
return { owner: parts[0], name: parts[1] };
|
|
2375
|
-
}
|
|
2376
|
-
async function readJson5(response) {
|
|
2377
|
-
const text2 = await response.text();
|
|
2378
|
-
if (!text2) return void 0;
|
|
2379
|
-
try {
|
|
2380
|
-
return JSON.parse(text2);
|
|
2381
|
-
} catch {
|
|
2382
|
-
return text2;
|
|
2383
|
-
}
|
|
2384
|
-
}
|
|
2385
2180
|
function createGitHubGetRepositoryTool(ctx) {
|
|
2386
2181
|
return definePluginTool8({
|
|
2387
2182
|
annotations: {
|
|
@@ -2394,21 +2189,11 @@ function createGitHubGetRepositoryTool(ctx) {
|
|
|
2394
2189
|
inputSchema: inputSchema6,
|
|
2395
2190
|
outputSchema: outputSchema6,
|
|
2396
2191
|
async execute(input) {
|
|
2397
|
-
const repo =
|
|
2398
|
-
const response = await ctx.egress
|
|
2399
|
-
provider: "github",
|
|
2192
|
+
const repo = parseRepo(input.repo);
|
|
2193
|
+
const response = await githubApi(ctx.egress, {
|
|
2400
2194
|
operation: "github.repository.get",
|
|
2401
|
-
|
|
2402
|
-
`https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}`,
|
|
2403
|
-
{
|
|
2404
|
-
headers: {
|
|
2405
|
-
Accept: "application/vnd.github+json",
|
|
2406
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
)
|
|
2195
|
+
path: repoPath(repo)
|
|
2410
2196
|
});
|
|
2411
|
-
const parsed = await readJson5(response);
|
|
2412
2197
|
if (!response.ok) {
|
|
2413
2198
|
throw new PluginToolInputError9(
|
|
2414
2199
|
`GitHub repository lookup failed with HTTP ${response.status}`
|
|
@@ -2420,7 +2205,7 @@ function createGitHubGetRepositoryTool(ctx) {
|
|
|
2420
2205
|
full_name: z11.string(),
|
|
2421
2206
|
html_url: z11.string(),
|
|
2422
2207
|
private: z11.boolean()
|
|
2423
|
-
}).parse(
|
|
2208
|
+
}).parse(response.body);
|
|
2424
2209
|
const subscribable = gitHubRepositorySubscribable({
|
|
2425
2210
|
canSubscribe: ctx.events.canSubscribe,
|
|
2426
2211
|
repo: providerResult.full_name
|
|
@@ -2446,10 +2231,10 @@ import {
|
|
|
2446
2231
|
definePluginTool as definePluginTool9,
|
|
2447
2232
|
pluginToolOutputSchema as pluginToolOutputSchema9
|
|
2448
2233
|
} from "@sentry/junior-plugin-api";
|
|
2449
|
-
import
|
|
2234
|
+
import * as z13 from "zod";
|
|
2450
2235
|
|
|
2451
2236
|
// src/github-status.ts
|
|
2452
|
-
import
|
|
2237
|
+
import * as z12 from "zod";
|
|
2453
2238
|
var GITHUB_STATUS_INCIDENTS_URL = "https://www.githubstatus.com/api/v2/incidents.json";
|
|
2454
2239
|
var GITHUB_STATUS_TTL_MS = 60 * 1e3;
|
|
2455
2240
|
var GITHUB_STATUS_TIMEOUT_MS = 5e3;
|
|
@@ -2557,7 +2342,7 @@ import {
|
|
|
2557
2342
|
pluginToolOutputSchema as pluginToolOutputSchema10,
|
|
2558
2343
|
subscribableResourceSchema as subscribableResourceSchema7
|
|
2559
2344
|
} from "@sentry/junior-plugin-api";
|
|
2560
|
-
import
|
|
2345
|
+
import * as z14 from "zod";
|
|
2561
2346
|
var inputSchema8 = z14.object({
|
|
2562
2347
|
repo: z14.string().describe('Repository in "owner/name" format.'),
|
|
2563
2348
|
number: z14.number().int().positive().describe("Issue number."),
|
|
@@ -2587,30 +2372,6 @@ function nonEmptyString4(value, name) {
|
|
|
2587
2372
|
if (!value?.trim()) throw new PluginToolInputError10(`${name} is required`);
|
|
2588
2373
|
return value.trim();
|
|
2589
2374
|
}
|
|
2590
|
-
function parseRepo9(value) {
|
|
2591
|
-
const parts = value.split("/").map((part) => part.trim());
|
|
2592
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
2593
|
-
throw new PluginToolInputError10('repo must use "owner/name" format');
|
|
2594
|
-
}
|
|
2595
|
-
return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
|
|
2596
|
-
}
|
|
2597
|
-
async function readJson6(response) {
|
|
2598
|
-
const text2 = await response.text();
|
|
2599
|
-
if (!text2) return void 0;
|
|
2600
|
-
try {
|
|
2601
|
-
return JSON.parse(text2);
|
|
2602
|
-
} catch {
|
|
2603
|
-
return text2;
|
|
2604
|
-
}
|
|
2605
|
-
}
|
|
2606
|
-
function githubApiErrorMessage3(payload) {
|
|
2607
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
2608
|
-
const message = payload.message;
|
|
2609
|
-
if (typeof message === "string" && message.trim()) return message.trim();
|
|
2610
|
-
}
|
|
2611
|
-
if (typeof payload === "string" && payload.trim()) return payload.trim();
|
|
2612
|
-
return "GitHub request failed";
|
|
2613
|
-
}
|
|
2614
2375
|
function createGitHubUpdateIssueTool(ctx) {
|
|
2615
2376
|
return definePluginTool10({
|
|
2616
2377
|
annotations: {
|
|
@@ -2630,7 +2391,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2630
2391
|
});
|
|
2631
2392
|
}
|
|
2632
2393
|
const update = parsedInput.data;
|
|
2633
|
-
const repo =
|
|
2394
|
+
const repo = parseRepo(update.repo);
|
|
2634
2395
|
const payload = {
|
|
2635
2396
|
...update.title !== void 0 ? { title: update.title } : void 0,
|
|
2636
2397
|
...update.body !== void 0 ? {
|
|
@@ -2646,26 +2407,16 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2646
2407
|
} : void 0,
|
|
2647
2408
|
...update.state !== void 0 ? { state: update.state } : void 0
|
|
2648
2409
|
};
|
|
2649
|
-
const response = await ctx.egress
|
|
2650
|
-
provider: "github",
|
|
2410
|
+
const response = await githubApi(ctx.egress, {
|
|
2651
2411
|
operation: "github.issue.update",
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
method: "PATCH",
|
|
2656
|
-
headers: {
|
|
2657
|
-
Accept: "application/vnd.github+json",
|
|
2658
|
-
"Content-Type": "application/json",
|
|
2659
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
2660
|
-
},
|
|
2661
|
-
body: JSON.stringify(payload)
|
|
2662
|
-
}
|
|
2663
|
-
)
|
|
2412
|
+
method: "PATCH",
|
|
2413
|
+
path: `${repoPath(repo)}/issues/${update.number}`,
|
|
2414
|
+
body: payload
|
|
2664
2415
|
});
|
|
2665
|
-
const parsed =
|
|
2416
|
+
const parsed = response.body;
|
|
2666
2417
|
if (!response.ok) {
|
|
2667
2418
|
throw new Error(
|
|
2668
|
-
`GitHub issue update failed with HTTP ${response.status}: ${
|
|
2419
|
+
`GitHub issue update failed with HTTP ${response.status}: ${githubErrorMessage(parsed)}`
|
|
2669
2420
|
);
|
|
2670
2421
|
}
|
|
2671
2422
|
const providerResult = z14.object({
|
|
@@ -2710,7 +2461,7 @@ import {
|
|
|
2710
2461
|
PluginToolInputError as PluginToolInputError11,
|
|
2711
2462
|
pluginToolOutputSchema as pluginToolOutputSchema11
|
|
2712
2463
|
} from "@sentry/junior-plugin-api";
|
|
2713
|
-
import
|
|
2464
|
+
import * as z15 from "zod";
|
|
2714
2465
|
import { subscribableResourceSchema as subscribableResourceSchema8 } from "@sentry/junior-plugin-api";
|
|
2715
2466
|
var inputSchema9 = z15.object({
|
|
2716
2467
|
repo: z15.string().describe('Repository in "owner/name" format.'),
|
|
@@ -2741,9 +2492,6 @@ var draftMutationResponseSchema = z15.object({
|
|
|
2741
2492
|
result: z15.object({ pullRequest: z15.object({ isDraft: z15.boolean() }) })
|
|
2742
2493
|
})
|
|
2743
2494
|
});
|
|
2744
|
-
var graphqlErrorsSchema = z15.object({
|
|
2745
|
-
errors: z15.array(z15.object({ message: z15.string() })).min(1)
|
|
2746
|
-
});
|
|
2747
2495
|
var pullRequestSchema2 = z15.object({
|
|
2748
2496
|
base: z15.string(),
|
|
2749
2497
|
body: z15.string().nullable(),
|
|
@@ -2765,58 +2513,27 @@ function nonEmptyString5(value, name) {
|
|
|
2765
2513
|
}
|
|
2766
2514
|
return value.trim();
|
|
2767
2515
|
}
|
|
2768
|
-
function parseRepo10(value) {
|
|
2769
|
-
const parts = value.split("/").map((part) => part.trim());
|
|
2770
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
2771
|
-
throw new PluginToolInputError11('repo must use "owner/name" format');
|
|
2772
|
-
}
|
|
2773
|
-
return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
|
|
2774
|
-
}
|
|
2775
|
-
async function readJson7(response) {
|
|
2776
|
-
const text2 = await response.text();
|
|
2777
|
-
if (!text2) return void 0;
|
|
2778
|
-
try {
|
|
2779
|
-
return JSON.parse(text2);
|
|
2780
|
-
} catch {
|
|
2781
|
-
return text2;
|
|
2782
|
-
}
|
|
2783
|
-
}
|
|
2784
|
-
function githubApiErrorMessage4(payload) {
|
|
2785
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
2786
|
-
const message = payload.message;
|
|
2787
|
-
if (typeof message === "string" && message.trim()) return message.trim();
|
|
2788
|
-
}
|
|
2789
|
-
if (typeof payload === "string" && payload.trim()) return payload.trim();
|
|
2790
|
-
return "GitHub request failed";
|
|
2791
|
-
}
|
|
2792
2516
|
async function setPullRequestDraft(input) {
|
|
2793
2517
|
const mutation = input.draft ? CONVERT_TO_DRAFT : MARK_READY_FOR_REVIEW;
|
|
2794
|
-
const response = await input.egress
|
|
2795
|
-
provider: "github",
|
|
2518
|
+
const response = await githubApi(input.egress, {
|
|
2796
2519
|
operation: `github.pull.draft.update:${input.repo.toLowerCase()}`,
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
})
|
|
2805
|
-
})
|
|
2520
|
+
method: "POST",
|
|
2521
|
+
path: "/graphql",
|
|
2522
|
+
body: {
|
|
2523
|
+
operationName: mutation.operationName,
|
|
2524
|
+
query: mutation.query,
|
|
2525
|
+
variables: { id: input.nodeId }
|
|
2526
|
+
}
|
|
2806
2527
|
});
|
|
2807
|
-
const payload =
|
|
2528
|
+
const payload = response.body;
|
|
2808
2529
|
const isDraft = draftMutationResponseSchema.safeParse(payload).data?.data.result.pullRequest.isDraft;
|
|
2809
2530
|
if (!response.ok || isDraft !== input.draft) {
|
|
2810
2531
|
throw new Error(
|
|
2811
|
-
`GitHub pull request draft update failed with HTTP ${response.status}: ${
|
|
2532
|
+
`GitHub pull request draft update failed with HTTP ${response.status}: ${githubErrorMessage(payload)}`
|
|
2812
2533
|
);
|
|
2813
2534
|
}
|
|
2814
2535
|
return isDraft;
|
|
2815
2536
|
}
|
|
2816
|
-
function githubGraphqlErrorMessage(payload) {
|
|
2817
|
-
const result = graphqlErrorsSchema.safeParse(payload);
|
|
2818
|
-
return result.success ? result.data.errors.map((error) => error.message).join("; ") : githubApiErrorMessage4(payload);
|
|
2819
|
-
}
|
|
2820
2537
|
function createGitHubUpdatePullRequestTool(ctx) {
|
|
2821
2538
|
return definePluginTool11({
|
|
2822
2539
|
annotations: {
|
|
@@ -2837,7 +2554,7 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2837
2554
|
);
|
|
2838
2555
|
}
|
|
2839
2556
|
const update = parsedInput.data;
|
|
2840
|
-
const repo =
|
|
2557
|
+
const repo = parseRepo(update.repo);
|
|
2841
2558
|
const requester = await resolveGitHubRequester(ctx);
|
|
2842
2559
|
const payload = {
|
|
2843
2560
|
...update.title !== void 0 ? { title: update.title } : void 0,
|
|
@@ -2851,25 +2568,16 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2851
2568
|
...update.base !== void 0 ? { base: update.base } : void 0,
|
|
2852
2569
|
...update.state !== void 0 ? { state: update.state } : void 0
|
|
2853
2570
|
};
|
|
2854
|
-
const pullUrl = `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/pulls/${update.number}`;
|
|
2855
2571
|
const hasRestUpdate = Object.keys(payload).length > 0;
|
|
2856
|
-
const response = await ctx.egress
|
|
2857
|
-
provider: "github",
|
|
2572
|
+
const response = await githubApi(ctx.egress, {
|
|
2858
2573
|
operation: hasRestUpdate ? "github.pull.update" : "github.pull.get",
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
headers: {
|
|
2862
|
-
Accept: "application/vnd.github+json",
|
|
2863
|
-
"X-GitHub-Api-Version": "2022-11-28",
|
|
2864
|
-
...hasRestUpdate ? { "Content-Type": "application/json" } : void 0
|
|
2865
|
-
},
|
|
2866
|
-
...hasRestUpdate ? { body: JSON.stringify(payload) } : void 0
|
|
2867
|
-
})
|
|
2574
|
+
path: `${repoPath(repo)}/pulls/${update.number}`,
|
|
2575
|
+
...hasRestUpdate ? { method: "PATCH", body: payload } : void 0
|
|
2868
2576
|
});
|
|
2869
|
-
const parsed =
|
|
2577
|
+
const parsed = response.body;
|
|
2870
2578
|
if (!response.ok) {
|
|
2871
2579
|
throw new Error(
|
|
2872
|
-
`GitHub pull request update failed with HTTP ${response.status}: ${
|
|
2580
|
+
`GitHub pull request update failed with HTTP ${response.status}: ${githubErrorMessage(parsed)}`
|
|
2873
2581
|
);
|
|
2874
2582
|
}
|
|
2875
2583
|
const providerResult = z15.object({
|
|
@@ -2946,7 +2654,7 @@ import {
|
|
|
2946
2654
|
PluginToolInputError as PluginToolInputError12,
|
|
2947
2655
|
pluginToolOutputSchema as pluginToolOutputSchema12
|
|
2948
2656
|
} from "@sentry/junior-plugin-api";
|
|
2949
|
-
import
|
|
2657
|
+
import * as z16 from "zod";
|
|
2950
2658
|
var STATUS_TO_REACTION_CONTENT = {
|
|
2951
2659
|
reviewing: "eyes",
|
|
2952
2660
|
addressed: "+1",
|
|
@@ -2974,13 +2682,6 @@ var outputSchema10 = pluginToolOutputSchema12.extend({
|
|
|
2974
2682
|
status: z16.enum(["addressed", "declined"]),
|
|
2975
2683
|
reaction_id: z16.number()
|
|
2976
2684
|
});
|
|
2977
|
-
function parseRepo11(value) {
|
|
2978
|
-
const parts = value.split("/").map((part) => part.trim());
|
|
2979
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
2980
|
-
throw new PluginToolInputError12('repo must use "owner/name" format');
|
|
2981
|
-
}
|
|
2982
|
-
return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
|
|
2983
|
-
}
|
|
2984
2685
|
function pullRequestCommentPath(input) {
|
|
2985
2686
|
const segment = input.commentKind === "conversation" ? "issues" : "pulls";
|
|
2986
2687
|
return `/repos/${encodeURIComponent(input.owner)}/${encodeURIComponent(input.name)}/${segment}/comments/${input.commentId}`;
|
|
@@ -2991,43 +2692,19 @@ function pullRequestCommentReactionsPath(input) {
|
|
|
2991
2692
|
function pullRequestFeedbackReactionContent(status) {
|
|
2992
2693
|
return STATUS_TO_REACTION_CONTENT[status];
|
|
2993
2694
|
}
|
|
2994
|
-
async function readJson8(response) {
|
|
2995
|
-
const text2 = await response.text();
|
|
2996
|
-
if (!text2) return void 0;
|
|
2997
|
-
try {
|
|
2998
|
-
return JSON.parse(text2);
|
|
2999
|
-
} catch {
|
|
3000
|
-
return text2;
|
|
3001
|
-
}
|
|
3002
|
-
}
|
|
3003
|
-
function githubError2(payload) {
|
|
3004
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
3005
|
-
const message = payload.message;
|
|
3006
|
-
if (typeof message === "string" && message.trim()) return message.trim();
|
|
3007
|
-
}
|
|
3008
|
-
return "GitHub request failed";
|
|
3009
|
-
}
|
|
3010
2695
|
var reactionSchema = z16.object({
|
|
3011
2696
|
id: z16.number(),
|
|
3012
2697
|
content: z16.string(),
|
|
3013
2698
|
user: z16.object({ id: z16.number() }).nullable()
|
|
3014
2699
|
});
|
|
3015
2700
|
async function assertBotAuthoredPullRequest(egress, input) {
|
|
3016
|
-
const
|
|
3017
|
-
Accept: "application/vnd.github+json",
|
|
3018
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
3019
|
-
};
|
|
3020
|
-
const commentResponse = await egress.fetch({
|
|
3021
|
-
provider: "github",
|
|
2701
|
+
const commentResponse = await githubApi(egress, {
|
|
3022
2702
|
operation: "github.pull.comment.get",
|
|
3023
|
-
|
|
3024
|
-
`https://api.github.com${pullRequestCommentPath(input)}`,
|
|
3025
|
-
{ headers }
|
|
3026
|
-
)
|
|
2703
|
+
path: pullRequestCommentPath(input)
|
|
3027
2704
|
});
|
|
3028
|
-
const commentPayload =
|
|
2705
|
+
const commentPayload = commentResponse.body;
|
|
3029
2706
|
if (!commentResponse.ok) {
|
|
3030
|
-
const message = `GitHub comment lookup failed with HTTP ${commentResponse.status}: ${
|
|
2707
|
+
const message = `GitHub comment lookup failed with HTTP ${commentResponse.status}: ${githubErrorMessage(commentPayload)}`;
|
|
3031
2708
|
if (commentResponse.status === 404) throw new PluginToolInputError12(message);
|
|
3032
2709
|
throw new Error(message);
|
|
3033
2710
|
}
|
|
@@ -3036,22 +2713,18 @@ async function assertBotAuthoredPullRequest(egress, input) {
|
|
|
3036
2713
|
pull_request_url: z16.string().optional()
|
|
3037
2714
|
}).safeParse(commentPayload);
|
|
3038
2715
|
const parentUrl = comment.success ? input.commentKind === "conversation" ? comment.data.issue_url : comment.data.pull_request_url : void 0;
|
|
3039
|
-
const
|
|
3040
|
-
if (!
|
|
2716
|
+
const number22 = /\/(?:issues|pulls)\/(\d+)$/.exec(parentUrl ?? "")?.[1];
|
|
2717
|
+
if (!number22) {
|
|
3041
2718
|
throw new Error("GitHub comment did not name its issue or pull request.");
|
|
3042
2719
|
}
|
|
3043
|
-
const pullResponse = await egress
|
|
3044
|
-
provider: "github",
|
|
2720
|
+
const pullResponse = await githubApi(egress, {
|
|
3045
2721
|
operation: "github.pull.get",
|
|
3046
|
-
|
|
3047
|
-
`https://api.github.com/repos/${encodeURIComponent(input.owner)}/${encodeURIComponent(input.name)}/pulls/${number}`,
|
|
3048
|
-
{ headers }
|
|
3049
|
-
)
|
|
2722
|
+
path: `${repoPath(input)}/pulls/${number22}`
|
|
3050
2723
|
});
|
|
3051
|
-
const pullPayload =
|
|
2724
|
+
const pullPayload = pullResponse.body;
|
|
3052
2725
|
if (!pullResponse.ok && pullResponse.status !== 404) {
|
|
3053
2726
|
throw new Error(
|
|
3054
|
-
`GitHub pull request lookup failed with HTTP ${pullResponse.status}: ${
|
|
2727
|
+
`GitHub pull request lookup failed with HTTP ${pullResponse.status}: ${githubErrorMessage(pullPayload)}`
|
|
3055
2728
|
);
|
|
3056
2729
|
}
|
|
3057
2730
|
const pull = z16.object({ user: z16.object({ id: z16.number() }).nullable() }).safeParse(pullPayload);
|
|
@@ -3089,7 +2762,7 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3089
2762
|
comment_kind: commentKind,
|
|
3090
2763
|
status
|
|
3091
2764
|
} = parsedInput.data;
|
|
3092
|
-
const repo =
|
|
2765
|
+
const repo = parseRepo(parsedInput.data.repo);
|
|
3093
2766
|
const botUserId = botUserIdFromEmail(botEmail);
|
|
3094
2767
|
if (botUserId === void 0) {
|
|
3095
2768
|
throw new Error("GitHub App bot identity is not configured.");
|
|
@@ -3102,23 +2775,20 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3102
2775
|
botUserId
|
|
3103
2776
|
});
|
|
3104
2777
|
const targetContent = pullRequestFeedbackReactionContent(status);
|
|
3105
|
-
const
|
|
2778
|
+
const reactionsPath = pullRequestCommentReactionsPath({
|
|
3106
2779
|
owner: repo.owner,
|
|
3107
2780
|
name: repo.name,
|
|
3108
2781
|
commentKind,
|
|
3109
2782
|
commentId
|
|
3110
|
-
})
|
|
3111
|
-
const listResponse = await ctx.egress
|
|
3112
|
-
provider: "github",
|
|
2783
|
+
});
|
|
2784
|
+
const listResponse = await githubApi(ctx.egress, {
|
|
3113
2785
|
operation: "github.pull.comment-reaction.list",
|
|
3114
|
-
|
|
3115
|
-
headers: { Accept: "application/vnd.github+json" }
|
|
3116
|
-
})
|
|
2786
|
+
path: `${reactionsPath}?per_page=100`
|
|
3117
2787
|
});
|
|
3118
|
-
const listPayload =
|
|
2788
|
+
const listPayload = listResponse.body;
|
|
3119
2789
|
if (!listResponse.ok) {
|
|
3120
2790
|
throw new Error(
|
|
3121
|
-
`GitHub reaction lookup failed with HTTP ${listResponse.status}: ${
|
|
2791
|
+
`GitHub reaction lookup failed with HTTP ${listResponse.status}: ${githubErrorMessage(listPayload)}`
|
|
3122
2792
|
);
|
|
3123
2793
|
}
|
|
3124
2794
|
const botReactions = z16.array(reactionSchema).parse(listPayload).filter(
|
|
@@ -3129,17 +2799,14 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3129
2799
|
);
|
|
3130
2800
|
for (const stale of botReactions) {
|
|
3131
2801
|
if (stale.content === targetContent) continue;
|
|
3132
|
-
const deleteResponse = await ctx.egress
|
|
3133
|
-
provider: "github",
|
|
2802
|
+
const deleteResponse = await githubApi(ctx.egress, {
|
|
3134
2803
|
operation: "github.pull.comment-reaction.delete",
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
})
|
|
2804
|
+
method: "DELETE",
|
|
2805
|
+
path: `${reactionsPath}/${stale.id}`
|
|
3138
2806
|
});
|
|
3139
2807
|
if (!deleteResponse.ok && deleteResponse.status !== 404) {
|
|
3140
|
-
const deletePayload = await readJson8(deleteResponse);
|
|
3141
2808
|
throw new Error(
|
|
3142
|
-
`GitHub reaction removal failed with HTTP ${deleteResponse.status}: ${
|
|
2809
|
+
`GitHub reaction removal failed with HTTP ${deleteResponse.status}: ${githubErrorMessage(deleteResponse.body)}`
|
|
3143
2810
|
);
|
|
3144
2811
|
}
|
|
3145
2812
|
}
|
|
@@ -3152,22 +2819,16 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3152
2819
|
reaction_id: existing.id
|
|
3153
2820
|
};
|
|
3154
2821
|
}
|
|
3155
|
-
const createResponse = await ctx.egress
|
|
3156
|
-
provider: "github",
|
|
2822
|
+
const createResponse = await githubApi(ctx.egress, {
|
|
3157
2823
|
operation: "github.pull.comment-reaction.create",
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
Accept: "application/vnd.github+json",
|
|
3162
|
-
"Content-Type": "application/json"
|
|
3163
|
-
},
|
|
3164
|
-
body: JSON.stringify({ content: targetContent })
|
|
3165
|
-
})
|
|
2824
|
+
method: "POST",
|
|
2825
|
+
path: reactionsPath,
|
|
2826
|
+
body: { content: targetContent }
|
|
3166
2827
|
});
|
|
3167
|
-
const createPayload =
|
|
2828
|
+
const createPayload = createResponse.body;
|
|
3168
2829
|
if (!createResponse.ok) {
|
|
3169
2830
|
throw new Error(
|
|
3170
|
-
`GitHub reaction creation failed with HTTP ${createResponse.status}: ${
|
|
2831
|
+
`GitHub reaction creation failed with HTTP ${createResponse.status}: ${githubErrorMessage(createPayload)}`
|
|
3171
2832
|
);
|
|
3172
2833
|
}
|
|
3173
2834
|
const created = reactionSchema.parse(createPayload);
|
|
@@ -3188,7 +2849,7 @@ import {
|
|
|
3188
2849
|
PluginToolInputError as PluginToolInputError13,
|
|
3189
2850
|
pluginToolOutputSchema as pluginToolOutputSchema13
|
|
3190
2851
|
} from "@sentry/junior-plugin-api";
|
|
3191
|
-
import
|
|
2852
|
+
import * as z17 from "zod";
|
|
3192
2853
|
var inputSchema11 = z17.object({
|
|
3193
2854
|
repo: z17.string().describe(
|
|
3194
2855
|
'Repository in "owner/name" format. Required because GraphQL has no repo path.'
|
|
@@ -3204,29 +2865,6 @@ var outputSchema11 = pluginToolOutputSchema13.extend({
|
|
|
3204
2865
|
thread_id: z17.string(),
|
|
3205
2866
|
resolved: z17.boolean()
|
|
3206
2867
|
});
|
|
3207
|
-
function parseRepo12(value) {
|
|
3208
|
-
const parts = value.split("/").map((part) => part.trim());
|
|
3209
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
3210
|
-
throw new PluginToolInputError13('repo must use "owner/name" format');
|
|
3211
|
-
}
|
|
3212
|
-
return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
|
|
3213
|
-
}
|
|
3214
|
-
async function readJson9(response) {
|
|
3215
|
-
const text2 = await response.text();
|
|
3216
|
-
if (!text2) return void 0;
|
|
3217
|
-
try {
|
|
3218
|
-
return JSON.parse(text2);
|
|
3219
|
-
} catch {
|
|
3220
|
-
return text2;
|
|
3221
|
-
}
|
|
3222
|
-
}
|
|
3223
|
-
function githubError3(payload) {
|
|
3224
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
3225
|
-
const message = payload.message;
|
|
3226
|
-
if (typeof message === "string" && message.trim()) return message.trim();
|
|
3227
|
-
}
|
|
3228
|
-
return "GitHub request failed";
|
|
3229
|
-
}
|
|
3230
2868
|
function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
3231
2869
|
return definePluginTool13({
|
|
3232
2870
|
// No action review: the tool checks in code that the bot authored the pull
|
|
@@ -3251,7 +2889,7 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3251
2889
|
{ cause: parsedInput.error }
|
|
3252
2890
|
);
|
|
3253
2891
|
}
|
|
3254
|
-
const repo =
|
|
2892
|
+
const repo = parseRepo(parsedInput.data.repo);
|
|
3255
2893
|
const botUserId = botUserIdFromEmail(botEmail);
|
|
3256
2894
|
if (botUserId === void 0) {
|
|
3257
2895
|
throw new Error("GitHub App bot identity is not configured.");
|
|
@@ -3269,23 +2907,20 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3269
2907
|
}
|
|
3270
2908
|
}
|
|
3271
2909
|
}`;
|
|
3272
|
-
const lookupResponse = await ctx.egress
|
|
3273
|
-
provider: "github",
|
|
2910
|
+
const lookupResponse = await githubApi(ctx.egress, {
|
|
3274
2911
|
operation: "github.pull.review-thread.get",
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
})
|
|
3283
|
-
})
|
|
2912
|
+
method: "POST",
|
|
2913
|
+
path: "/graphql",
|
|
2914
|
+
body: {
|
|
2915
|
+
operationName: "ReviewThreadOwnership",
|
|
2916
|
+
query,
|
|
2917
|
+
variables: { threadId: parsedInput.data.thread_id }
|
|
2918
|
+
}
|
|
3284
2919
|
});
|
|
3285
|
-
const lookupPayload =
|
|
2920
|
+
const lookupPayload = lookupResponse.body;
|
|
3286
2921
|
if (!lookupResponse.ok) {
|
|
3287
2922
|
throw new Error(
|
|
3288
|
-
`GitHub review thread lookup failed with HTTP ${lookupResponse.status}: ${
|
|
2923
|
+
`GitHub review thread lookup failed with HTTP ${lookupResponse.status}: ${githubErrorMessage(lookupPayload)}`
|
|
3289
2924
|
);
|
|
3290
2925
|
}
|
|
3291
2926
|
const threadNodeSchema = z17.object({
|
|
@@ -3330,23 +2965,20 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3330
2965
|
thread { id isResolved }
|
|
3331
2966
|
}
|
|
3332
2967
|
}`;
|
|
3333
|
-
const resolveResponse = await ctx.egress
|
|
3334
|
-
provider: "github",
|
|
2968
|
+
const resolveResponse = await githubApi(ctx.egress, {
|
|
3335
2969
|
operation: `github.pull.review-thread.resolve:${repo.ref.toLowerCase()}`,
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
})
|
|
3344
|
-
})
|
|
2970
|
+
method: "POST",
|
|
2971
|
+
path: "/graphql",
|
|
2972
|
+
body: {
|
|
2973
|
+
operationName: "ResolveReviewThread",
|
|
2974
|
+
query: mutation,
|
|
2975
|
+
variables: { threadId: thread.id }
|
|
2976
|
+
}
|
|
3345
2977
|
});
|
|
3346
|
-
const resolvePayload =
|
|
2978
|
+
const resolvePayload = resolveResponse.body;
|
|
3347
2979
|
if (!resolveResponse.ok) {
|
|
3348
2980
|
throw new Error(
|
|
3349
|
-
`GitHub review thread resolution failed with HTTP ${resolveResponse.status}: ${
|
|
2981
|
+
`GitHub review thread resolution failed with HTTP ${resolveResponse.status}: ${githubErrorMessage(resolvePayload)}`
|
|
3350
2982
|
);
|
|
3351
2983
|
}
|
|
3352
2984
|
const resolveResultSchema = z17.object({
|
|
@@ -3384,7 +3016,7 @@ import {
|
|
|
3384
3016
|
PluginToolInputError as PluginToolInputError14,
|
|
3385
3017
|
pluginToolOutputSchema as pluginToolOutputSchema14
|
|
3386
3018
|
} from "@sentry/junior-plugin-api";
|
|
3387
|
-
import
|
|
3019
|
+
import * as z18 from "zod";
|
|
3388
3020
|
var reviewCommentSchema = z18.object({
|
|
3389
3021
|
path: z18.string().trim().min(1).describe("File path in the pull request."),
|
|
3390
3022
|
body: z18.string().trim().min(1).describe("Inline review comment."),
|
|
@@ -3411,32 +3043,8 @@ var outputSchema12 = pluginToolOutputSchema14.extend({
|
|
|
3411
3043
|
state: z18.string(),
|
|
3412
3044
|
url: z18.string()
|
|
3413
3045
|
});
|
|
3414
|
-
function parseRepo13(value) {
|
|
3415
|
-
const parts = value.split("/").map((part) => part.trim());
|
|
3416
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
3417
|
-
throw new PluginToolInputError14('repo must use "owner/name" format');
|
|
3418
|
-
}
|
|
3419
|
-
return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
|
|
3420
|
-
}
|
|
3421
|
-
async function readJson10(response) {
|
|
3422
|
-
const text2 = await response.text();
|
|
3423
|
-
if (!text2) return void 0;
|
|
3424
|
-
try {
|
|
3425
|
-
return JSON.parse(text2);
|
|
3426
|
-
} catch {
|
|
3427
|
-
return text2;
|
|
3428
|
-
}
|
|
3429
|
-
}
|
|
3430
|
-
function githubError4(body) {
|
|
3431
|
-
if (body && typeof body === "object" && !Array.isArray(body)) {
|
|
3432
|
-
const message = body.message;
|
|
3433
|
-
if (typeof message === "string" && message.trim()) return message.trim();
|
|
3434
|
-
}
|
|
3435
|
-
if (typeof body === "string" && body.trim()) return body.trim();
|
|
3436
|
-
return "GitHub request failed";
|
|
3437
|
-
}
|
|
3438
3046
|
function throwReviewError(status, body) {
|
|
3439
|
-
const message = `GitHub pull request review failed with HTTP ${status}: ${
|
|
3047
|
+
const message = `GitHub pull request review failed with HTTP ${status}: ${githubErrorMessage(body)}`;
|
|
3440
3048
|
if (status === 404 || status === 422) {
|
|
3441
3049
|
throw new PluginToolInputError14(message);
|
|
3442
3050
|
}
|
|
@@ -3455,7 +3063,7 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
3455
3063
|
inputSchema: inputSchema12,
|
|
3456
3064
|
outputSchema: outputSchema12,
|
|
3457
3065
|
async execute(review) {
|
|
3458
|
-
const repo =
|
|
3066
|
+
const repo = parseRepo(review.repo);
|
|
3459
3067
|
const comments = review.comments?.map((comment) => ({
|
|
3460
3068
|
path: comment.path,
|
|
3461
3069
|
body: comment.body,
|
|
@@ -3464,31 +3072,20 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
3464
3072
|
...comment.start_line !== void 0 ? { start_line: comment.start_line } : void 0,
|
|
3465
3073
|
...comment.start_side !== void 0 ? { start_side: comment.start_side } : void 0
|
|
3466
3074
|
}));
|
|
3467
|
-
const response = await egress
|
|
3468
|
-
provider: "github",
|
|
3075
|
+
const response = await githubApi(egress, {
|
|
3469
3076
|
operation: "github.pull.review.create",
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
3478
|
-
},
|
|
3479
|
-
body: JSON.stringify({
|
|
3480
|
-
body: review.body,
|
|
3481
|
-
event: review.event,
|
|
3482
|
-
...comments ? { comments } : void 0
|
|
3483
|
-
})
|
|
3484
|
-
}
|
|
3485
|
-
)
|
|
3077
|
+
method: "POST",
|
|
3078
|
+
path: `${repoPath(repo)}/pulls/${review.number}/reviews`,
|
|
3079
|
+
body: {
|
|
3080
|
+
body: review.body,
|
|
3081
|
+
event: review.event,
|
|
3082
|
+
...comments ? { comments } : void 0
|
|
3083
|
+
}
|
|
3486
3084
|
});
|
|
3487
|
-
const parsed = await readJson10(response);
|
|
3488
3085
|
if (!response.ok) {
|
|
3489
|
-
throwReviewError(response.status,
|
|
3086
|
+
throwReviewError(response.status, response.body);
|
|
3490
3087
|
}
|
|
3491
|
-
const providerResult = z18.object({ id: z18.number(), html_url: z18.string(), state: z18.string() }).parse(
|
|
3088
|
+
const providerResult = z18.object({ id: z18.number(), html_url: z18.string(), state: z18.string() }).parse(response.body);
|
|
3492
3089
|
return {
|
|
3493
3090
|
target: "submitPullRequestReview",
|
|
3494
3091
|
repo: repo.ref,
|
|
@@ -3531,11 +3128,11 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
|
3531
3128
|
|
|
3532
3129
|
// src/webhooks/handler.ts
|
|
3533
3130
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
3534
|
-
import
|
|
3131
|
+
import * as z28 from "zod";
|
|
3535
3132
|
|
|
3536
3133
|
// src/issue-outcomes/store.ts
|
|
3537
3134
|
import { and as and2, eq as eq2, lte, sql as sql2 } from "drizzle-orm";
|
|
3538
|
-
import
|
|
3135
|
+
import * as z19 from "zod";
|
|
3539
3136
|
var githubIssueOutcomeInputSchema = z19.object({
|
|
3540
3137
|
candidateOwned: z19.boolean(),
|
|
3541
3138
|
closedAt: z19.date().optional(),
|
|
@@ -3614,7 +3211,7 @@ async function recordGitHubIssueConversations(db, input) {
|
|
|
3614
3211
|
|
|
3615
3212
|
// src/pull-request-outcomes/store.ts
|
|
3616
3213
|
import { and as and3, eq as eq3, lte as lte2, ne, sql as sql3 } from "drizzle-orm";
|
|
3617
|
-
import
|
|
3214
|
+
import * as z20 from "zod";
|
|
3618
3215
|
var githubPullRequestOutcomeInputSchema = z20.object({
|
|
3619
3216
|
candidateOwned: z20.boolean(),
|
|
3620
3217
|
closedAt: z20.date().optional(),
|
|
@@ -3845,7 +3442,7 @@ async function releaseGitHubPullRequestReadySync(db, target, claim) {
|
|
|
3845
3442
|
}
|
|
3846
3443
|
|
|
3847
3444
|
// src/webhooks/issue-outcome.ts
|
|
3848
|
-
import
|
|
3445
|
+
import * as z21 from "zod";
|
|
3849
3446
|
var canonicalIssueOutcomeSchema = z21.object({
|
|
3850
3447
|
action: z21.enum(["opened", "closed", "reopened"]),
|
|
3851
3448
|
issue: z21.object({
|
|
@@ -3983,7 +3580,7 @@ function normalizeGitHubIssueConversations(args) {
|
|
|
3983
3580
|
}
|
|
3984
3581
|
|
|
3985
3582
|
// src/webhooks/pull-request-outcome.ts
|
|
3986
|
-
import
|
|
3583
|
+
import * as z22 from "zod";
|
|
3987
3584
|
var canonicalPullRequestOutcomeSchema = z22.object({
|
|
3988
3585
|
action: z22.enum(["opened", "closed", "reopened"]),
|
|
3989
3586
|
pull_request: z22.object({
|
|
@@ -4146,7 +3743,7 @@ function normalizeGitHubPullRequestLinkedIssues(args) {
|
|
|
4146
3743
|
}
|
|
4147
3744
|
|
|
4148
3745
|
// src/webhooks/merge-conflict.ts
|
|
4149
|
-
import
|
|
3746
|
+
import * as z23 from "zod";
|
|
4150
3747
|
var EVENT_TYPE = "pull_request.merge_conflict";
|
|
4151
3748
|
var CLOSED_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
4152
3749
|
"pull_request.closed_unmerged",
|
|
@@ -4237,10 +3834,10 @@ async function loadGitHubMergeConflictEvents(args) {
|
|
|
4237
3834
|
}
|
|
4238
3835
|
|
|
4239
3836
|
// src/webhooks/pull-request-ready.ts
|
|
4240
|
-
import
|
|
3837
|
+
import * as z25 from "zod";
|
|
4241
3838
|
|
|
4242
3839
|
// src/webhooks/installation-requests.ts
|
|
4243
|
-
import
|
|
3840
|
+
import * as z24 from "zod";
|
|
4244
3841
|
function splitRepository(fullName, label) {
|
|
4245
3842
|
const [owner, name, ...extra] = fullName.split("/");
|
|
4246
3843
|
if (!owner || !name || extra.length > 0) {
|
|
@@ -4507,7 +4104,7 @@ async function syncGitHubPullRequestReadyNotices(args) {
|
|
|
4507
4104
|
}
|
|
4508
4105
|
|
|
4509
4106
|
// src/webhooks/pull-request-match-data.ts
|
|
4510
|
-
import
|
|
4107
|
+
import * as z26 from "zod";
|
|
4511
4108
|
var LOOKUPS_BY_MATCH_KEY = {
|
|
4512
4109
|
authors: ["authors"],
|
|
4513
4110
|
openerEmail: ["opener"],
|
|
@@ -4529,8 +4126,8 @@ var webhookSchema = z26.object({
|
|
|
4529
4126
|
function pullRequestNumbers(events) {
|
|
4530
4127
|
const numbers = /* @__PURE__ */ new Map();
|
|
4531
4128
|
for (const event of events) {
|
|
4532
|
-
const
|
|
4533
|
-
if (typeof
|
|
4129
|
+
const number22 = event.data?.pullRequest;
|
|
4130
|
+
if (typeof number22 === "number") numbers.set(event.eventKey, number22);
|
|
4534
4131
|
}
|
|
4535
4132
|
return numbers;
|
|
4536
4133
|
}
|
|
@@ -4544,8 +4141,8 @@ function logFailure(context, lookup, error) {
|
|
|
4544
4141
|
}
|
|
4545
4142
|
async function withJuniorOpeners(context, events) {
|
|
4546
4143
|
const botNumber = (event) => {
|
|
4547
|
-
const
|
|
4548
|
-
return
|
|
4144
|
+
const number22 = context.numbers.get(event.eventKey);
|
|
4145
|
+
return number22 !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number22 : void 0;
|
|
4549
4146
|
};
|
|
4550
4147
|
const numbers = events.flatMap((event) => botNumber(event) ?? []);
|
|
4551
4148
|
if (numbers.length === 0) return events;
|
|
@@ -4564,9 +4161,9 @@ async function withJuniorOpeners(context, events) {
|
|
|
4564
4161
|
}
|
|
4565
4162
|
}
|
|
4566
4163
|
return events.map((event) => {
|
|
4567
|
-
const
|
|
4568
|
-
if (
|
|
4569
|
-
const identityId = openers.get(
|
|
4164
|
+
const number22 = botNumber(event);
|
|
4165
|
+
if (number22 === void 0) return event;
|
|
4166
|
+
const identityId = openers.get(number22)?.identityId;
|
|
4570
4167
|
const login = identityId ? logins.get(identityId) : void 0;
|
|
4571
4168
|
const {
|
|
4572
4169
|
openerEmail: _email,
|
|
@@ -4588,8 +4185,8 @@ async function withRolesAndAuthors(context, events, lookups) {
|
|
|
4588
4185
|
if (!loadRole && !loadAuthors) return events;
|
|
4589
4186
|
return await Promise.all(
|
|
4590
4187
|
events.map(async (event) => {
|
|
4591
|
-
const
|
|
4592
|
-
if (
|
|
4188
|
+
const number22 = context.numbers.get(event.eventKey);
|
|
4189
|
+
if (number22 === void 0) return event;
|
|
4593
4190
|
const login = event.data?.openerUsername;
|
|
4594
4191
|
if (loadRole && typeof login === "string" && !roles.has(login)) {
|
|
4595
4192
|
roles.set(
|
|
@@ -4599,16 +4196,16 @@ async function withRolesAndAuthors(context, events, lookups) {
|
|
|
4599
4196
|
)
|
|
4600
4197
|
);
|
|
4601
4198
|
}
|
|
4602
|
-
if (loadAuthors && !authors.has(
|
|
4199
|
+
if (loadAuthors && !authors.has(number22)) {
|
|
4603
4200
|
authors.set(
|
|
4604
|
-
|
|
4605
|
-
loadAuthors({ number, repositoryFullName }).catch(
|
|
4201
|
+
number22,
|
|
4202
|
+
loadAuthors({ number: number22, repositoryFullName }).catch(
|
|
4606
4203
|
(error) => logFailure(context, "authors", error)
|
|
4607
4204
|
)
|
|
4608
4205
|
);
|
|
4609
4206
|
}
|
|
4610
4207
|
const role = loadRole && typeof login === "string" ? await roles.get(login) : void 0;
|
|
4611
|
-
const logins = loadAuthors ? await authors.get(
|
|
4208
|
+
const logins = loadAuthors ? await authors.get(number22) : void 0;
|
|
4612
4209
|
if (!role && !logins?.length) return event;
|
|
4613
4210
|
return {
|
|
4614
4211
|
...event,
|
|
@@ -4667,7 +4264,7 @@ async function withGitHubPullRequestMatchData(args) {
|
|
|
4667
4264
|
}
|
|
4668
4265
|
|
|
4669
4266
|
// src/webhooks/pull-request-people.ts
|
|
4670
|
-
import
|
|
4267
|
+
import * as z27 from "zod";
|
|
4671
4268
|
var PEOPLE_EVENTS = /* @__PURE__ */ new Set([
|
|
4672
4269
|
"pull_request.review.approved",
|
|
4673
4270
|
"pull_request.merged"
|
|
@@ -5107,19 +4704,19 @@ function gitHubResourceUrl(input) {
|
|
|
5107
4704
|
if (input.resourceType === "repository") {
|
|
5108
4705
|
return `https://github.com/${input.identifier}`;
|
|
5109
4706
|
}
|
|
5110
|
-
const [repo,
|
|
5111
|
-
if (!repo || !
|
|
4707
|
+
const [repo, number22] = input.identifier.split("#");
|
|
4708
|
+
if (!repo || !number22) return void 0;
|
|
5112
4709
|
if (input.resourceType === "pull_request") {
|
|
5113
|
-
return `https://github.com/${repo}/pull/${
|
|
4710
|
+
return `https://github.com/${repo}/pull/${number22}`;
|
|
5114
4711
|
}
|
|
5115
4712
|
if (input.resourceType === "issue") {
|
|
5116
|
-
return `https://github.com/${repo}/issues/${
|
|
4713
|
+
return `https://github.com/${repo}/issues/${number22}`;
|
|
5117
4714
|
}
|
|
5118
4715
|
return void 0;
|
|
5119
4716
|
}
|
|
5120
4717
|
|
|
5121
4718
|
// src/pull-request-outcomes/commit-composition.ts
|
|
5122
|
-
import
|
|
4719
|
+
import * as z29 from "zod";
|
|
5123
4720
|
var canonicalCommitSchema = z29.object({
|
|
5124
4721
|
authorEmail: z29.string().nullable(),
|
|
5125
4722
|
authorLogin: z29.string().nullable()
|
|
@@ -5284,8 +4881,12 @@ if [ -z "$repository_hooks_dir" ]; then
|
|
|
5284
4881
|
repository_hooks_dir="$git_common_dir/hooks"
|
|
5285
4882
|
fi
|
|
5286
4883
|
fi
|
|
5287
|
-
if [ -n "$repository_hooks_dir" ] && [ -x "$repository_hooks_dir/${name}" ]
|
|
5288
|
-
|
|
4884
|
+
if [ -n "$repository_hooks_dir" ] && [ -x "$repository_hooks_dir/${name}" ]; then
|
|
4885
|
+
repository_hooks_real=$(CDPATH='' cd -- "$repository_hooks_dir" && pwd -P) || repository_hooks_real=""
|
|
4886
|
+
junior_hooks_real=$(CDPATH='' cd -- "\${0%/*}" && pwd -P) || junior_hooks_real=""
|
|
4887
|
+
if [ "$repository_hooks_real" != "$junior_hooks_real" ]; then
|
|
4888
|
+
repository_hook="$repository_hooks_dir/${name}"
|
|
4889
|
+
fi
|
|
5289
4890
|
fi`;
|
|
5290
4891
|
}
|
|
5291
4892
|
function repositoryHook(name) {
|
|
@@ -5298,14 +4899,100 @@ if [ -n "$repository_hook" ]; then
|
|
|
5298
4899
|
fi
|
|
5299
4900
|
`;
|
|
5300
4901
|
}
|
|
4902
|
+
var SET_COAUTHOR_TRAILERS_AWK = String.raw`
|
|
4903
|
+
function blank(line) { return line ~ /^[[:space:]]*$/ }
|
|
4904
|
+
function comment(line) { return substr(line, 1, 1) == "#" }
|
|
4905
|
+
function trailer(line) {
|
|
4906
|
+
return coauthor(line) || line ~ /^[A-Z][[:alnum:]-]*: ./ || line ~ /^\(cherry picked from commit [0-9a-f]+\)$/
|
|
4907
|
+
}
|
|
4908
|
+
function coauthor(line) { return tolower(line) ~ /^co-authored-by: / }
|
|
4909
|
+
{ lines[NR] = $0 }
|
|
4910
|
+
END {
|
|
4911
|
+
last = NR
|
|
4912
|
+
while (last > 0 && (blank(lines[last]) || comment(lines[last]))) last--
|
|
4913
|
+
count = 0
|
|
4914
|
+
i = 1
|
|
4915
|
+
while (i <= last) {
|
|
4916
|
+
count++
|
|
4917
|
+
gap[count] = i
|
|
4918
|
+
while (blank(lines[i])) i++
|
|
4919
|
+
first[count] = i
|
|
4920
|
+
while (i <= last && !blank(lines[i])) i++
|
|
4921
|
+
final[count] = i - 1
|
|
4922
|
+
}
|
|
4923
|
+
subject = 0
|
|
4924
|
+
content_count = 0
|
|
4925
|
+
for (p = 1; p <= count; p++) {
|
|
4926
|
+
content = 0
|
|
4927
|
+
trailers = 1
|
|
4928
|
+
for (j = first[p]; j <= final[p]; j++) {
|
|
4929
|
+
if (comment(lines[j])) continue
|
|
4930
|
+
content = 1
|
|
4931
|
+
if (!trailer(lines[j])) trailers = 0
|
|
4932
|
+
}
|
|
4933
|
+
if (content && !subject) subject = p
|
|
4934
|
+
trailer_paragraph[p] = content && trailers
|
|
4935
|
+
kept[p] = 0
|
|
4936
|
+
kept_content[p] = 0
|
|
4937
|
+
for (j = first[p]; j <= final[p]; j++) {
|
|
4938
|
+
drop[j] = trailer_paragraph[p] && coauthor(lines[j])
|
|
4939
|
+
if (drop[j]) continue
|
|
4940
|
+
kept[p]++
|
|
4941
|
+
if (!comment(lines[j])) kept_content[p]++
|
|
4942
|
+
}
|
|
4943
|
+
if (kept_content[p]) content_count++
|
|
4944
|
+
}
|
|
4945
|
+
if (ENVIRON["JUNIOR_COAUTHOR_LIST"] != "") {
|
|
4946
|
+
for (j = 1; j <= last; j++) {
|
|
4947
|
+
if (!drop[j]) continue
|
|
4948
|
+
line = lines[j]
|
|
4949
|
+
sub(/^[^:]*:[[:space:]]*/, "", line)
|
|
4950
|
+
print "Co-Authored-By: " line
|
|
4951
|
+
}
|
|
4952
|
+
exit
|
|
4953
|
+
}
|
|
4954
|
+
last_paragraph = 0
|
|
4955
|
+
for (p = 1; p <= count; p++) {
|
|
4956
|
+
if (!kept[p]) continue
|
|
4957
|
+
for (j = gap[p]; j < first[p]; j++) print lines[j]
|
|
4958
|
+
for (j = first[p]; j <= final[p]; j++) if (!drop[j]) print lines[j]
|
|
4959
|
+
last_paragraph = p
|
|
4960
|
+
}
|
|
4961
|
+
if (content_count) {
|
|
4962
|
+
inline = last_paragraph != subject && trailer_paragraph[last_paragraph] && kept_content[last_paragraph]
|
|
4963
|
+
bot = tolower(ENVIRON["JUNIOR_GIT_AUTHOR_EMAIL"])
|
|
4964
|
+
n = split(ENVIRON["JUNIOR_COAUTHOR_TRAILERS"], wanted, "\n")
|
|
4965
|
+
for (k = 1; k <= n; k++) {
|
|
4966
|
+
line = wanted[k]
|
|
4967
|
+
if (line !~ /^Co-Authored-By: [^<>]+ <[^<>[:space:]]+@[^<>[:space:]]+>$/) continue
|
|
4968
|
+
email = tolower(line)
|
|
4969
|
+
sub(/^[^<]*</, "", email)
|
|
4970
|
+
sub(/>$/, "", email)
|
|
4971
|
+
if (email == bot || seen[email]++) continue
|
|
4972
|
+
if (!inline) print ""
|
|
4973
|
+
inline = 1
|
|
4974
|
+
print line
|
|
4975
|
+
}
|
|
4976
|
+
}
|
|
4977
|
+
for (j = last + 1; j <= NR; j++) print lines[j]
|
|
4978
|
+
}
|
|
4979
|
+
`;
|
|
5301
4980
|
function prepareCommitMsgHook() {
|
|
5302
|
-
return `#!/
|
|
4981
|
+
return `#!/bin/sh
|
|
5303
4982
|
set -eu
|
|
5304
4983
|
|
|
5305
|
-
|
|
5306
|
-
if [ -z "$message_file" ]; then
|
|
4984
|
+
if [ "$#" -lt 1 ] || [ -z "$1" ]; then
|
|
5307
4985
|
exit 1
|
|
5308
4986
|
fi
|
|
4987
|
+
message_file=$1
|
|
4988
|
+
commit_source=""
|
|
4989
|
+
if [ "$#" -ge 2 ]; then
|
|
4990
|
+
commit_source=$2
|
|
4991
|
+
fi
|
|
4992
|
+
source_commit=""
|
|
4993
|
+
if [ "$#" -ge 3 ]; then
|
|
4994
|
+
source_commit=$3
|
|
4995
|
+
fi
|
|
5309
4996
|
|
|
5310
4997
|
# Run the repository hook first so Junior's trailers stay final.
|
|
5311
4998
|
${findRepositoryHook("prepare-commit-msg")}
|
|
@@ -5318,124 +5005,109 @@ if [ -z "\${JUNIOR_GIT_AUTHOR_NAME:-}" ] || [ -z "\${JUNIOR_GIT_AUTHOR_EMAIL:-}"
|
|
|
5318
5005
|
exit 1
|
|
5319
5006
|
fi
|
|
5320
5007
|
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
exit 1
|
|
5324
|
-
fi
|
|
5008
|
+
nl='
|
|
5009
|
+
'
|
|
5325
5010
|
|
|
5326
|
-
#
|
|
5327
|
-
#
|
|
5328
|
-
#
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5011
|
+
# Commits whose changes this commit replaces. Their co-authors stay
|
|
5012
|
+
# credited, so an amend, rebase, cherry-pick, or squash keeps them even when
|
|
5013
|
+
# the current run has other human actors or none.
|
|
5014
|
+
rewritten_commits=""
|
|
5015
|
+
add_rewritten_commit() {
|
|
5016
|
+
if [ -n "$1" ]; then
|
|
5017
|
+
rewritten_commits="$rewritten_commits $1"
|
|
5018
|
+
fi
|
|
5332
5019
|
}
|
|
5333
5020
|
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
add_trailer "$actor_trailer"
|
|
5338
|
-
fi
|
|
5339
|
-
done <<< "$JUNIOR_GIT_ACTOR_COAUTHOR_TRAILERS"
|
|
5021
|
+
# \`--amend\`, \`-c\`, \`-C\`, and rebase \`reword\`.
|
|
5022
|
+
if [ "$commit_source" = "commit" ]; then
|
|
5023
|
+
add_rewritten_commit "$source_commit"
|
|
5340
5024
|
fi
|
|
5341
5025
|
|
|
5342
|
-
#
|
|
5343
|
-
# from the
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
line--
|
|
5352
|
-
}
|
|
5353
|
-
start = line
|
|
5354
|
-
while (start > 0 && lines[start] != "") {
|
|
5355
|
-
start--
|
|
5356
|
-
}
|
|
5357
|
-
valid = line > 0
|
|
5358
|
-
for (i = start + 1; valid && i <= line; i++) {
|
|
5359
|
-
if (lines[i] !~ /^[[:alnum:]-]+: .+/) {
|
|
5360
|
-
valid = 0
|
|
5361
|
-
}
|
|
5362
|
-
}
|
|
5363
|
-
if (!valid) {
|
|
5364
|
-
for (i = 1; i <= NR; i++) {
|
|
5365
|
-
print lines[i]
|
|
5366
|
-
}
|
|
5367
|
-
exit 0
|
|
5368
|
-
}
|
|
5369
|
-
kept = 0
|
|
5370
|
-
for (i = start + 1; i <= line; i++) {
|
|
5371
|
-
if (tolower(lines[i]) !~ /^co-authored-by: /) {
|
|
5372
|
-
kept++
|
|
5373
|
-
}
|
|
5374
|
-
}
|
|
5375
|
-
before = kept > 0 ? start : start - 1
|
|
5376
|
-
for (i = 1; i <= before; i++) {
|
|
5377
|
-
print lines[i]
|
|
5378
|
-
}
|
|
5379
|
-
for (i = start + 1; i <= line; i++) {
|
|
5380
|
-
if (tolower(lines[i]) !~ /^co-authored-by: /) {
|
|
5381
|
-
print lines[i]
|
|
5382
|
-
}
|
|
5383
|
-
}
|
|
5384
|
-
}
|
|
5385
|
-
' "$message_file" > "$tmp_file"
|
|
5386
|
-
cat "$tmp_file" > "$message_file"
|
|
5387
|
-
|
|
5388
|
-
final_trailer_block=$(awk '
|
|
5389
|
-
{ lines[NR] = $0 }
|
|
5390
|
-
END {
|
|
5391
|
-
line = NR
|
|
5392
|
-
while (line > 0 && lines[line] == "") {
|
|
5393
|
-
line--
|
|
5394
|
-
}
|
|
5395
|
-
if (line == 0) {
|
|
5396
|
-
exit 0
|
|
5397
|
-
}
|
|
5398
|
-
start = line
|
|
5399
|
-
while (start > 0 && lines[start] != "") {
|
|
5400
|
-
start--
|
|
5401
|
-
}
|
|
5402
|
-
for (i = start + 1; i <= line; i++) {
|
|
5403
|
-
if (lines[i] !~ /^[[:alnum:]-]+: .+/) {
|
|
5404
|
-
exit 0
|
|
5405
|
-
}
|
|
5406
|
-
}
|
|
5407
|
-
for (i = start + 1; i <= line; i++) {
|
|
5408
|
-
print lines[i]
|
|
5409
|
-
}
|
|
5410
|
-
}
|
|
5411
|
-
' "$message_file")
|
|
5026
|
+
# \`--amend -m\` and \`--amend -F\` give the "message" source, so read the
|
|
5027
|
+
# flag from the parent \`git commit\` process.
|
|
5028
|
+
parent_args=""
|
|
5029
|
+
if [ -r "/proc/$PPID/cmdline" ]; then
|
|
5030
|
+
parent_args=$(tr '\\000' '\\n' < "/proc/$PPID/cmdline") || parent_args=""
|
|
5031
|
+
fi
|
|
5032
|
+
case "$nl$parent_args$nl" in
|
|
5033
|
+
*"$nl--amend$nl"*) add_rewritten_commit HEAD ;;
|
|
5034
|
+
esac
|
|
5412
5035
|
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5036
|
+
git_dir=$(git rev-parse --git-dir 2>/dev/null) || git_dir=""
|
|
5037
|
+
if [ -n "$git_dir" ]; then
|
|
5038
|
+
# Each rebase \`pick\` and each \`git cherry-pick\`.
|
|
5039
|
+
if git rev-parse -q --verify CHERRY_PICK_HEAD >/dev/null 2>&1; then
|
|
5040
|
+
add_rewritten_commit CHERRY_PICK_HEAD
|
|
5417
5041
|
fi
|
|
5418
|
-
}
|
|
5419
5042
|
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5043
|
+
if [ -f "$git_dir/rebase-merge/done" ]; then
|
|
5044
|
+
# A rebase step that stopped on a conflict. An \`edit\` stop writes
|
|
5045
|
+
# \`amend\`, and a new commit there replaces no commit.
|
|
5046
|
+
if [ ! -f "$git_dir/rebase-merge/amend" ] && git rev-parse -q --verify REBASE_HEAD >/dev/null 2>&1; then
|
|
5047
|
+
add_rewritten_commit REBASE_HEAD
|
|
5048
|
+
fi
|
|
5049
|
+
# A \`fixup\` or \`squash\` folds its commit into HEAD. A rebased merge
|
|
5050
|
+
# reuses the commit in \`merge -C\`.
|
|
5051
|
+
rebase_step=$(tail -n 1 "$git_dir/rebase-merge/done")
|
|
5052
|
+
case "$rebase_step" in
|
|
5053
|
+
f\\ *|fixup\\ *|s\\ *|squash\\ *) add_rewritten_commit HEAD ;;
|
|
5054
|
+
esac
|
|
5055
|
+
case "$rebase_step" in
|
|
5056
|
+
f\\ *|fixup\\ *|s\\ *|squash\\ *|m\\ *|merge\\ *)
|
|
5057
|
+
step_commit=$(printf '%s\\n' "$rebase_step" | sed -n 's/^[a-z]* \\(-[Cc] \\)\\{0,1\\}\\([0-9a-f]\\{40,64\\}\\).*/\\2/p')
|
|
5058
|
+
add_rewritten_commit "$step_commit"
|
|
5059
|
+
;;
|
|
5060
|
+
esac
|
|
5423
5061
|
fi
|
|
5424
|
-
done <<< "$desired_trailers"
|
|
5425
5062
|
|
|
5426
|
-
|
|
5427
|
-
|
|
5063
|
+
# \`git merge --squash\` lists the squashed commits in SQUASH_MSG.
|
|
5064
|
+
if [ "$commit_source" = "squash" ] && [ -f "$git_dir/SQUASH_MSG" ]; then
|
|
5065
|
+
squashed_commits=$(sed -n 's/^commit \\([0-9a-f]\\{40,64\\}\\).*/\\1/p' "$git_dir/SQUASH_MSG")
|
|
5066
|
+
for squashed_commit in $squashed_commits; do
|
|
5067
|
+
add_rewritten_commit "$squashed_commit"
|
|
5068
|
+
done
|
|
5069
|
+
fi
|
|
5428
5070
|
fi
|
|
5429
5071
|
|
|
5430
|
-
|
|
5431
|
-
|
|
5072
|
+
# A rewrite keeps the author of the commit it replaces, and Git passes that
|
|
5073
|
+
# author to this hook.
|
|
5074
|
+
if [ "\${GIT_AUTHOR_NAME:-}" != "$JUNIOR_GIT_AUTHOR_NAME" ] || [ "\${GIT_AUTHOR_EMAIL:-}" != "$JUNIOR_GIT_AUTHOR_EMAIL" ]; then
|
|
5075
|
+
kept_author=""
|
|
5076
|
+
for rewritten_commit in $rewritten_commits; do
|
|
5077
|
+
rewritten_author=$(git show -s --format='%an%n%ae' "$rewritten_commit" -- 2>/dev/null) || continue
|
|
5078
|
+
if [ "$rewritten_author" = "\${GIT_AUTHOR_NAME:-}$nl\${GIT_AUTHOR_EMAIL:-}" ]; then
|
|
5079
|
+
kept_author=$rewritten_author
|
|
5080
|
+
fi
|
|
5081
|
+
done
|
|
5082
|
+
if [ -z "$kept_author" ]; then
|
|
5083
|
+
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
|
|
5084
|
+
exit 1
|
|
5085
|
+
fi
|
|
5432
5086
|
fi
|
|
5433
5087
|
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5088
|
+
set_coauthor_trailers() {
|
|
5089
|
+
awk '${SET_COAUTHOR_TRAILERS_AWK}' "$@"
|
|
5090
|
+
}
|
|
5091
|
+
|
|
5092
|
+
# Existing co-authors first, then the host-derived human run actors.
|
|
5093
|
+
coauthor_trailers=""
|
|
5094
|
+
for rewritten_commit in $rewritten_commits; do
|
|
5095
|
+
rewritten_message=$(git show -s --format=%B "$rewritten_commit" -- 2>/dev/null) || continue
|
|
5096
|
+
coauthors=$(
|
|
5097
|
+
JUNIOR_COAUTHOR_LIST=1
|
|
5098
|
+
export JUNIOR_COAUTHOR_LIST
|
|
5099
|
+
printf '%s\\n' "$rewritten_message" | set_coauthor_trailers
|
|
5100
|
+
)
|
|
5101
|
+
coauthor_trailers="$coauthor_trailers$coauthors$nl"
|
|
5102
|
+
done
|
|
5103
|
+
coauthor_trailers="$coauthor_trailers\${JUNIOR_GIT_ACTOR_COAUTHOR_TRAILERS:-}"
|
|
5104
|
+
|
|
5105
|
+
message=$(
|
|
5106
|
+
JUNIOR_COAUTHOR_TRAILERS=$coauthor_trailers
|
|
5107
|
+
export JUNIOR_COAUTHOR_TRAILERS
|
|
5108
|
+
set_coauthor_trailers "$message_file"
|
|
5109
|
+
)
|
|
5110
|
+
printf '%s\\n' "$message" > "$message_file"
|
|
5439
5111
|
`;
|
|
5440
5112
|
}
|
|
5441
5113
|
var PREPARE_GIT_SCRIPT = `set -eu
|
|
@@ -5562,8 +5234,8 @@ function linkifyLine(line) {
|
|
|
5562
5234
|
if (isReferenceBoundary(index2 === 0 ? void 0 : line[index2 - 1])) {
|
|
5563
5235
|
const match = GITHUB_ISSUE_REFERENCE_PATTERN.exec(line.slice(index2));
|
|
5564
5236
|
if (match) {
|
|
5565
|
-
const [reference, owner, repository2,
|
|
5566
|
-
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${
|
|
5237
|
+
const [reference, owner, repository2, number22] = match;
|
|
5238
|
+
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number22})`;
|
|
5567
5239
|
index2 += reference.length;
|
|
5568
5240
|
continue;
|
|
5569
5241
|
}
|
|
@@ -5705,9 +5377,9 @@ function parseGitHubReferences(text2, config) {
|
|
|
5705
5377
|
}
|
|
5706
5378
|
return [...references.values()];
|
|
5707
5379
|
}
|
|
5708
|
-
function objectTitle(kind,
|
|
5709
|
-
if (!isRecord(
|
|
5710
|
-
const raw = kind === "commit" ? isRecord(
|
|
5380
|
+
function objectTitle(kind, object29) {
|
|
5381
|
+
if (!isRecord(object29)) return void 0;
|
|
5382
|
+
const raw = kind === "commit" ? isRecord(object29.commit) && typeof object29.commit.message === "string" ? object29.commit.message.split("\n")[0] : void 0 : typeof object29.title === "string" ? object29.title : void 0;
|
|
5711
5383
|
return raw?.replace(/\s+/g, " ").trim() || void 0;
|
|
5712
5384
|
}
|
|
5713
5385
|
async function loadGitHubConversationTitleContext(args) {
|
|
@@ -6135,7 +5807,7 @@ function shouldInspectGitHubGraphqlResponse(ctx) {
|
|
|
6135
5807
|
var GITHUB_ERROR_BODY_LIMIT_BYTES = 4 * 1024;
|
|
6136
5808
|
var GITHUB_ACCESS_DENIED_MESSAGE = "Resource not accessible by integration";
|
|
6137
5809
|
var GITHUB_ACCEPTED_PERMISSIONS_PATTERN = /^[a-z_]+=[a-z]+(?:\s*[,;]\s*[a-z_]+=[a-z]+)*$/;
|
|
6138
|
-
function
|
|
5810
|
+
function githubErrorMessage2(bodyText) {
|
|
6139
5811
|
if (!bodyText) {
|
|
6140
5812
|
return void 0;
|
|
6141
5813
|
}
|
|
@@ -6152,7 +5824,7 @@ async function githubForbiddenPermissionDeniedMessage(ctx) {
|
|
|
6152
5824
|
const url = sso.match(/\burl=(https:\/\/github\.com\/\S+)/)?.[1];
|
|
6153
5825
|
return `GitHub requires SAML SSO authorization for this credential.${url ? ` Authorize it at ${url}` : ""}`;
|
|
6154
5826
|
}
|
|
6155
|
-
const message =
|
|
5827
|
+
const message = githubErrorMessage2(
|
|
6156
5828
|
await ctx.response.readText(GITHUB_ERROR_BODY_LIMIT_BYTES)
|
|
6157
5829
|
);
|
|
6158
5830
|
if (message !== GITHUB_ACCESS_DENIED_MESSAGE) {
|
|
@@ -6574,26 +6246,17 @@ function githubPlugin(options = {}) {
|
|
|
6574
6246
|
operation: "github.pull.get"
|
|
6575
6247
|
}
|
|
6576
6248
|
}[reference.kind];
|
|
6577
|
-
const response = await ctx.egress
|
|
6578
|
-
provider: "github",
|
|
6249
|
+
const response = await githubApi(ctx.egress, {
|
|
6579
6250
|
operation,
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
{
|
|
6583
|
-
headers: {
|
|
6584
|
-
Accept: "application/vnd.github+json",
|
|
6585
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
6586
|
-
},
|
|
6587
|
-
signal: ctx.signal
|
|
6588
|
-
}
|
|
6589
|
-
)
|
|
6251
|
+
path: `${repoPath(reference)}/${collection}/${encodeURIComponent(reference.id)}`,
|
|
6252
|
+
signal: ctx.signal
|
|
6590
6253
|
});
|
|
6591
6254
|
if (!response.ok) {
|
|
6592
6255
|
throw new Error(
|
|
6593
6256
|
`GitHub ${reference.kind} lookup failed with HTTP ${response.status}`
|
|
6594
6257
|
);
|
|
6595
6258
|
}
|
|
6596
|
-
return
|
|
6259
|
+
return response.body;
|
|
6597
6260
|
}
|
|
6598
6261
|
});
|
|
6599
6262
|
},
|