@sentry/junior-github 0.298.0 → 0.300.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-OK6BNAGC.js → chunk-YUF5P5I7.js} +50 -20
- package/dist/credential-support.d.ts +7 -0
- package/dist/db/schema.d.ts +34 -0
- package/dist/events/pull-request.d.ts +8 -2
- package/dist/graphql-documents.d.ts +31 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1532 -785
- package/dist/object-facts.d.ts +16 -1
- package/dist/plugin.d.ts +3 -0
- package/dist/pull-request-outcomes/apply.d.ts +3 -1
- package/dist/pull-request-outcomes/reconcile.d.ts +10 -5
- package/dist/pull-request-outcomes/store.d.ts +5 -0
- package/dist/pull-request-requesters/draft-reviewers.d.ts +15 -0
- package/dist/testing.js +1 -1
- package/dist/tool-support/attribution.d.ts +4 -2
- package/dist/tool-support/pull-request-description.d.ts +8 -0
- package/dist/tools/clone-repository.d.ts +70 -2
- package/dist/tools/comment-on-issue.d.ts +70 -2
- package/dist/tools/comment-on-pull-request.d.ts +70 -2
- package/dist/tools/create-issue.d.ts +70 -2
- package/dist/tools/create-pull-request.d.ts +75 -4
- package/dist/tools/get-deployment.d.ts +70 -2
- package/dist/tools/get-issue.d.ts +70 -2
- package/dist/tools/get-pull-request.d.ts +90 -2
- package/dist/tools/get-release.d.ts +70 -2
- package/dist/tools/get-repository.d.ts +70 -2
- package/dist/tools/get-status.d.ts +70 -2
- package/dist/tools/react-to-issue.d.ts +70 -2
- package/dist/tools/resolve-pull-request-review-thread.d.ts +70 -2
- package/dist/tools/submit-pull-request-review.d.ts +70 -2
- package/dist/tools/update-issue-comment.d.ts +70 -2
- package/dist/tools/update-issue.d.ts +70 -2
- package/dist/tools/update-pull-request-feedback.d.ts +70 -4
- package/dist/tools/update-pull-request.d.ts +74 -4
- package/dist/tools.d.ts +10 -1
- package/dist/webhooks/check-suite.d.ts +2 -4
- package/dist/webhooks/fail-open-log.d.ts +10 -0
- package/dist/webhooks/handler.d.ts +1 -1
- package/dist/webhooks/installation-requests.d.ts +12 -1
- package/dist/webhooks/merge-conflict.d.ts +1 -1
- package/dist/webhooks/pull-request-preview.d.ts +12 -0
- package/dist/webhooks/pull-request-ready-reviewers.d.ts +25 -0
- package/dist/webhooks/pull-request-ready.d.ts +1 -1
- package/migrations/0011_pull_request_draft.sql +1 -0
- package/migrations/meta/0011_snapshot.json +434 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +7 -4
- package/skills/github-code/SKILL.md +1 -1
- package/skills/github-code/SPEC.md +1 -1
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
GITHUB_REPOSITORY_EVENTS,
|
|
26
26
|
GITHUB_REPOSITORY_IDENTIFIER,
|
|
27
27
|
GITHUB_REPOSITORY_SUGGESTED_EVENTS,
|
|
28
|
+
GitHubRequestError,
|
|
28
29
|
HTTP_READ_METHODS,
|
|
29
30
|
USER_WRITE_REQUIREMENTS,
|
|
30
31
|
botLoginFromEmail,
|
|
@@ -51,6 +52,7 @@ import {
|
|
|
51
52
|
issueInstallationToken,
|
|
52
53
|
listVerifiedUserEmails,
|
|
53
54
|
loadCheckSuiteFacts,
|
|
55
|
+
logFailOpenFailure,
|
|
54
56
|
needsCheckSuitePullRequestFacts,
|
|
55
57
|
normalizeGitHubEvents,
|
|
56
58
|
normalizePermissions,
|
|
@@ -61,7 +63,7 @@ import {
|
|
|
61
63
|
readGrantPermissions,
|
|
62
64
|
requireEnv,
|
|
63
65
|
resolveUserAccount
|
|
64
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-YUF5P5I7.js";
|
|
65
67
|
|
|
66
68
|
// src/tool-support/attribution.ts
|
|
67
69
|
import * as z from "zod";
|
|
@@ -157,10 +159,15 @@ var GITHUB_REQUEST_ATTRIBUTION_START = "<!-- junior-request-attribution:start --
|
|
|
157
159
|
var GITHUB_REQUEST_ATTRIBUTION_END = "<!-- junior-request-attribution:end -->";
|
|
158
160
|
var SLACK_USER_ID_DISPLAY_PATTERN = /^[UW][A-Z0-9]{5,}$/;
|
|
159
161
|
var GITHUB_LOGIN_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/;
|
|
160
|
-
function
|
|
161
|
-
const login2 =
|
|
162
|
+
function parseGitHubLogin(value) {
|
|
163
|
+
const login2 = value?.trim().replace(/^@/, "");
|
|
162
164
|
return login2 && GITHUB_LOGIN_PATTERN.test(login2) ? login2 : void 0;
|
|
163
165
|
}
|
|
166
|
+
function linkedGitHubLogin(user) {
|
|
167
|
+
return parseGitHubLogin(
|
|
168
|
+
user?.identities.find((identity) => identity.provider === "github")?.handle
|
|
169
|
+
);
|
|
170
|
+
}
|
|
164
171
|
function cleanDisplayValue(value, userId) {
|
|
165
172
|
const cleaned = value?.replace(/[\r\n<>]/g, " ").trim();
|
|
166
173
|
if (!cleaned) {
|
|
@@ -458,7 +465,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
458
465
|
openWorldHint: true,
|
|
459
466
|
readOnlyHint: true
|
|
460
467
|
},
|
|
461
|
-
description: "Clone a GitHub repository into the sandbox as an ad-hoc checkout. The destination must not already exist. In the default Sandbox, a matching Workspace is a tool input error: call switchWorkspace instead, or
|
|
468
|
+
description: "Clone a GitHub repository into the sandbox as an ad-hoc checkout. The destination must not already exist. In the default Sandbox, a matching Workspace is a tool input error: call switchWorkspace instead, or opt in to an intentional ad-hoc checkout. Inside a Workspace, the clone proceeds and the result notes matching Workspaces.",
|
|
462
469
|
describeProposal(input) {
|
|
463
470
|
const directory = typeof input.directory === "string" && input.directory.length > 0 ? input.directory : void 0;
|
|
464
471
|
const adHoc = input.allow_ad_hoc === true ? " as an intentional ad-hoc checkout" : "";
|
|
@@ -659,7 +666,7 @@ function createGitHubCommentOnPullRequestTool(egress) {
|
|
|
659
666
|
openWorldHint: true,
|
|
660
667
|
readOnlyHint: false
|
|
661
668
|
},
|
|
662
|
-
description: "Post a conversation comment on a GitHub pull request, or reply in an inline review thread
|
|
669
|
+
description: "Post a conversation comment on a GitHub pull request, or reply in an inline review thread. For issues, use github_commentOnIssue. Use it to answer a question asked in a pull request review or comment. Returns the comment id and URL.",
|
|
663
670
|
inputSchema: inputSchema4,
|
|
664
671
|
outputSchema: outputSchema4,
|
|
665
672
|
async execute(input) {
|
|
@@ -693,6 +700,12 @@ function createGitHubCommentOnPullRequestTool(egress) {
|
|
|
693
700
|
}
|
|
694
701
|
|
|
695
702
|
// src/object-facts.ts
|
|
703
|
+
import {
|
|
704
|
+
OBJECT_FACTS_MAX_BYTES,
|
|
705
|
+
objectFactsBytes
|
|
706
|
+
} from "@sentry/junior-plugin-api";
|
|
707
|
+
import { lexer, walkTokens } from "marked";
|
|
708
|
+
import { parseFragment } from "parse5";
|
|
696
709
|
import * as z6 from "zod";
|
|
697
710
|
var person = z6.object({ login: z6.string() });
|
|
698
711
|
var responseSchema = z6.object({
|
|
@@ -713,7 +726,7 @@ var short = (value) => {
|
|
|
713
726
|
const text2 = value?.trim();
|
|
714
727
|
return text2 ? text2.length > 64 ? `${text2.slice(0, 63)}\u2026` : text2 : void 0;
|
|
715
728
|
};
|
|
716
|
-
function
|
|
729
|
+
function visibleBody(body) {
|
|
717
730
|
let text2 = (body ?? "").replace(
|
|
718
731
|
/<!-- junior-(session-footer|request-attribution):start -->[\s\S]*?<!-- junior-\1:end -->/g,
|
|
719
732
|
""
|
|
@@ -721,26 +734,80 @@ function description(body) {
|
|
|
721
734
|
while (text2.includes("<!--")) {
|
|
722
735
|
text2 = text2.replace(/<!--[\s\S]*?(?:-->|$)/g, "");
|
|
723
736
|
}
|
|
724
|
-
|
|
737
|
+
return text2.trim();
|
|
738
|
+
}
|
|
739
|
+
function description(body) {
|
|
740
|
+
const text2 = visibleBody(body);
|
|
725
741
|
if (!text2) return void 0;
|
|
726
742
|
return text2.length > 4e3 ? `${text2.slice(0, 3999)}\u2026` : text2;
|
|
727
743
|
}
|
|
744
|
+
function htmlImageSources(html) {
|
|
745
|
+
const sources = [];
|
|
746
|
+
const visit2 = (node) => {
|
|
747
|
+
if ("tagName" in node && node.tagName === "img") {
|
|
748
|
+
const src = node.attrs.find((attr) => attr.name === "src")?.value;
|
|
749
|
+
if (src) sources.push(src);
|
|
750
|
+
}
|
|
751
|
+
if ("childNodes" in node) node.childNodes.forEach(visit2);
|
|
752
|
+
if ("content" in node) visit2(node.content);
|
|
753
|
+
};
|
|
754
|
+
visit2(parseFragment(html));
|
|
755
|
+
return sources;
|
|
756
|
+
}
|
|
757
|
+
function publicArtifactUrl(value) {
|
|
758
|
+
const baseUrl = process.env.JUNIOR_BASE_URL?.trim().replace(/\/+$/, "");
|
|
759
|
+
if (!baseUrl) return void 0;
|
|
760
|
+
let url;
|
|
761
|
+
let prefix;
|
|
762
|
+
try {
|
|
763
|
+
url = new URL(value);
|
|
764
|
+
prefix = new URL(`${baseUrl}/public/artifacts/`);
|
|
765
|
+
} catch {
|
|
766
|
+
return void 0;
|
|
767
|
+
}
|
|
768
|
+
return (url.protocol === "https:" || url.protocol === "http:") && url.origin === prefix.origin && url.pathname.length > prefix.pathname.length && url.pathname.startsWith(prefix.pathname) && !url.username && !url.password && url.href.length <= 512 ? url.href : void 0;
|
|
769
|
+
}
|
|
770
|
+
function githubPreviewImageUrls(body) {
|
|
771
|
+
const sources = [];
|
|
772
|
+
walkTokens(lexer(visibleBody(body), { gfm: true }), (token) => {
|
|
773
|
+
if (token.type === "image") sources.push(token.href);
|
|
774
|
+
if (token.type === "html") sources.push(...htmlImageSources(token.raw));
|
|
775
|
+
});
|
|
776
|
+
return [
|
|
777
|
+
...new Set(
|
|
778
|
+
sources.map(publicArtifactUrl).filter((url) => url !== void 0)
|
|
779
|
+
)
|
|
780
|
+
];
|
|
781
|
+
}
|
|
782
|
+
function withGitHubPreviewImages(facts, urls) {
|
|
783
|
+
let bytes = objectFactsBytes(facts) + ',"previewImageUrls":[]'.length;
|
|
784
|
+
const previewImageUrls = [];
|
|
785
|
+
for (const url of urls) {
|
|
786
|
+
bytes += JSON.stringify(url).length + (previewImageUrls.length ? 1 : 0);
|
|
787
|
+
if (bytes > OBJECT_FACTS_MAX_BYTES) break;
|
|
788
|
+
previewImageUrls.push(url);
|
|
789
|
+
}
|
|
790
|
+
return previewImageUrls.length > 0 ? { ...facts, previewImageUrls } : facts;
|
|
791
|
+
}
|
|
728
792
|
function githubObjectFacts(type, response) {
|
|
729
793
|
const data = responseSchema.parse(response);
|
|
730
794
|
const result = {
|
|
731
795
|
sourceUpdatedAt: data.updated_at,
|
|
732
796
|
description: description(data.body),
|
|
733
|
-
facts: type === "code_change" ?
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
797
|
+
facts: type === "code_change" ? withGitHubPreviewImages(
|
|
798
|
+
{
|
|
799
|
+
type,
|
|
800
|
+
author: short(data.user?.login),
|
|
801
|
+
reviewers: data.requested_reviewers?.slice(0, 5).map((user) => short(user.login)).filter(Boolean),
|
|
802
|
+
sourceBranch: short(data.head?.ref),
|
|
803
|
+
targetBranch: short(data.base?.ref),
|
|
804
|
+
mergeable: data.mergeable ?? void 0,
|
|
805
|
+
changedFiles: data.changed_files,
|
|
806
|
+
additions: data.additions,
|
|
807
|
+
deletions: data.deletions
|
|
808
|
+
},
|
|
809
|
+
githubPreviewImageUrls(data.body)
|
|
810
|
+
) : {
|
|
744
811
|
type,
|
|
745
812
|
assignees: data.assignees?.slice(0, 5).map((user) => short(user.login)).filter(Boolean),
|
|
746
813
|
labels: data.labels?.slice(0, 5).map(
|
|
@@ -949,11 +1016,11 @@ function githubLinkedIssues(body, repositoryFullName) {
|
|
|
949
1016
|
if (!body) return [];
|
|
950
1017
|
const references = /* @__PURE__ */ new Map();
|
|
951
1018
|
const add = (linkedRepository, rawNumber) => {
|
|
952
|
-
const
|
|
953
|
-
if (!Number.isInteger(
|
|
1019
|
+
const number33 = Number.parseInt(rawNumber, 10);
|
|
1020
|
+
if (!Number.isInteger(number33) || number33 <= 0) return;
|
|
954
1021
|
const normalizedRepository = linkedRepository.toLowerCase();
|
|
955
|
-
references.set(`${normalizedRepository}#${
|
|
956
|
-
number:
|
|
1022
|
+
references.set(`${normalizedRepository}#${number33}`, {
|
|
1023
|
+
number: number33,
|
|
957
1024
|
repositoryFullName: linkedRepository
|
|
958
1025
|
});
|
|
959
1026
|
};
|
|
@@ -1526,10 +1593,12 @@ function createGitHubGetIssueTool(ctx) {
|
|
|
1526
1593
|
});
|
|
1527
1594
|
}
|
|
1528
1595
|
function issueRepoRef(repositoryUrl) {
|
|
1529
|
-
const
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1596
|
+
const url = repositoryUrl ? URL.parse(repositoryUrl) : null;
|
|
1597
|
+
if (url?.origin !== "https://api.github.com" || url.search || url.hash) {
|
|
1598
|
+
return void 0;
|
|
1599
|
+
}
|
|
1600
|
+
const [repos, owner, repo, ...rest] = url.pathname.slice(1).split("/");
|
|
1601
|
+
return repos === "repos" && owner && repo && rest.length === 0 ? `${owner}/${repo}` : void 0;
|
|
1533
1602
|
}
|
|
1534
1603
|
|
|
1535
1604
|
// src/tools/create-pull-request.ts
|
|
@@ -1537,14 +1606,33 @@ import {
|
|
|
1537
1606
|
objectFactsSchema as objectFactsSchema2,
|
|
1538
1607
|
definePluginTool as definePluginTool8,
|
|
1539
1608
|
EgressAuthRequired as EgressAuthRequired2,
|
|
1540
|
-
PluginToolInputError as
|
|
1609
|
+
PluginToolInputError as PluginToolInputError11,
|
|
1541
1610
|
pluginToolOutputSchema as pluginToolOutputSchema8,
|
|
1542
1611
|
watchResultSchema,
|
|
1543
1612
|
subscribableResourceSchema as subscribableResourceSchema4
|
|
1544
1613
|
} from "@sentry/junior-plugin-api";
|
|
1545
1614
|
import { Type as Type2 } from "@sinclair/typebox";
|
|
1546
1615
|
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
1547
|
-
import * as
|
|
1616
|
+
import * as z13 from "zod";
|
|
1617
|
+
|
|
1618
|
+
// src/pull-request-requesters/draft-reviewers.ts
|
|
1619
|
+
import * as z10 from "zod";
|
|
1620
|
+
var DRAFT_REVIEWERS_TTL_MS = 14 * 24 * 60 * 60 * 1e3;
|
|
1621
|
+
var reviewersSchema = z10.array(z10.string().min(1)).min(1);
|
|
1622
|
+
function draftReviewersKey(target) {
|
|
1623
|
+
return `pull-request-draft-reviewers:${target.repositoryFullName.toLowerCase()}#${target.number}`;
|
|
1624
|
+
}
|
|
1625
|
+
async function saveGitHubDraftReviewers(state, target, reviewers) {
|
|
1626
|
+
await state.set(
|
|
1627
|
+
draftReviewersKey(target),
|
|
1628
|
+
reviewersSchema.parse(reviewers),
|
|
1629
|
+
DRAFT_REVIEWERS_TTL_MS
|
|
1630
|
+
);
|
|
1631
|
+
}
|
|
1632
|
+
async function readGitHubDraftReviewers(state, target) {
|
|
1633
|
+
const saved = await state.get(draftReviewersKey(target));
|
|
1634
|
+
return saved === void 0 ? void 0 : reviewersSchema.parse(saved);
|
|
1635
|
+
}
|
|
1548
1636
|
|
|
1549
1637
|
// src/pull-request-requesters/store.ts
|
|
1550
1638
|
import { and, asc, eq, inArray, lt } from "drizzle-orm";
|
|
@@ -1552,6 +1640,7 @@ import { and, asc, eq, inArray, lt } from "drizzle-orm";
|
|
|
1552
1640
|
// src/db/schema.ts
|
|
1553
1641
|
import { sql } from "drizzle-orm";
|
|
1554
1642
|
import {
|
|
1643
|
+
boolean as boolean3,
|
|
1555
1644
|
index,
|
|
1556
1645
|
integer,
|
|
1557
1646
|
pgTable,
|
|
@@ -1559,18 +1648,18 @@ import {
|
|
|
1559
1648
|
text,
|
|
1560
1649
|
timestamp
|
|
1561
1650
|
} from "drizzle-orm/pg-core";
|
|
1562
|
-
import * as
|
|
1563
|
-
var githubPullRequestStateSchema =
|
|
1651
|
+
import * as z11 from "zod";
|
|
1652
|
+
var githubPullRequestStateSchema = z11.enum([
|
|
1564
1653
|
"closed_unmerged",
|
|
1565
1654
|
"merged",
|
|
1566
1655
|
"open"
|
|
1567
1656
|
]);
|
|
1568
|
-
var githubPullRequestCommitCompositionSchema =
|
|
1657
|
+
var githubPullRequestCommitCompositionSchema = z11.enum([
|
|
1569
1658
|
"junior_only",
|
|
1570
1659
|
"mixed"
|
|
1571
1660
|
]);
|
|
1572
|
-
var githubIssueStateSchema =
|
|
1573
|
-
var githubIssueStateReasonSchema =
|
|
1661
|
+
var githubIssueStateSchema = z11.enum(["closed", "open"]);
|
|
1662
|
+
var githubIssueStateReasonSchema = z11.enum([
|
|
1574
1663
|
"completed",
|
|
1575
1664
|
"duplicate",
|
|
1576
1665
|
"not_planned",
|
|
@@ -1606,6 +1695,8 @@ var juniorGitHubPullRequests = pgTable(
|
|
|
1606
1695
|
state: text("state").$type().notNull(),
|
|
1607
1696
|
commitComposition: text("commit_composition").$type(),
|
|
1608
1697
|
conversationIds: text("conversation_ids").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
1698
|
+
/** The daily reconcile compares this with GitHub. */
|
|
1699
|
+
draft: boolean3("draft").notNull().default(false),
|
|
1609
1700
|
openedAt: timestamp("opened_at", { withTimezone: true }).notNull(),
|
|
1610
1701
|
mergedAt: timestamp("merged_at", { withTimezone: true }),
|
|
1611
1702
|
closedAt: timestamp("closed_at", { withTimezone: true }),
|
|
@@ -1731,32 +1822,32 @@ async function listGitHubPullRequestOpeners(db, input) {
|
|
|
1731
1822
|
}
|
|
1732
1823
|
|
|
1733
1824
|
// src/tools/stack-pull-request.ts
|
|
1734
|
-
import * as
|
|
1825
|
+
import * as z12 from "zod";
|
|
1735
1826
|
var MAX_STACK_DEPTH = 10;
|
|
1736
1827
|
var GITHUB_STACKS_API_VERSION = "2026-03-10";
|
|
1737
|
-
var stackTargetSchema =
|
|
1738
|
-
number:
|
|
1739
|
-
head:
|
|
1740
|
-
ref:
|
|
1741
|
-
repo:
|
|
1828
|
+
var stackTargetSchema = z12.object({
|
|
1829
|
+
number: z12.number().int().positive(),
|
|
1830
|
+
head: z12.object({
|
|
1831
|
+
ref: z12.string().min(1),
|
|
1832
|
+
repo: z12.object({ full_name: z12.string().min(1) }).nullable()
|
|
1742
1833
|
}),
|
|
1743
|
-
base:
|
|
1744
|
-
ref:
|
|
1745
|
-
repo:
|
|
1746
|
-
default_branch:
|
|
1747
|
-
full_name:
|
|
1834
|
+
base: z12.object({
|
|
1835
|
+
ref: z12.string().min(1),
|
|
1836
|
+
repo: z12.object({
|
|
1837
|
+
default_branch: z12.string().min(1),
|
|
1838
|
+
full_name: z12.string().min(1)
|
|
1748
1839
|
})
|
|
1749
1840
|
})
|
|
1750
1841
|
});
|
|
1751
|
-
var openPullRequestsSchema =
|
|
1752
|
-
|
|
1753
|
-
number:
|
|
1754
|
-
base:
|
|
1842
|
+
var openPullRequestsSchema = z12.array(
|
|
1843
|
+
z12.object({
|
|
1844
|
+
number: z12.number().int().positive(),
|
|
1845
|
+
base: z12.object({ ref: z12.string().min(1) })
|
|
1755
1846
|
})
|
|
1756
1847
|
);
|
|
1757
|
-
var stackSchema =
|
|
1758
|
-
number:
|
|
1759
|
-
pull_requests:
|
|
1848
|
+
var stackSchema = z12.object({
|
|
1849
|
+
number: z12.number().int().positive(),
|
|
1850
|
+
pull_requests: z12.array(z12.object({ number: z12.number().int().positive() }))
|
|
1760
1851
|
});
|
|
1761
1852
|
async function stackGitHubPullRequest(ctx, target) {
|
|
1762
1853
|
const repo = target.base.repo.full_name;
|
|
@@ -1766,17 +1857,17 @@ async function stackGitHubPullRequest(ctx, target) {
|
|
|
1766
1857
|
}
|
|
1767
1858
|
const [owner, name] = repo.split("/");
|
|
1768
1859
|
const api = repoPath({ owner, name });
|
|
1769
|
-
const github = async (
|
|
1860
|
+
const github = async (operation2, path, schema, body) => {
|
|
1770
1861
|
const response = await githubApi(ctx.egress, {
|
|
1771
1862
|
apiVersion: GITHUB_STACKS_API_VERSION,
|
|
1772
|
-
operation,
|
|
1863
|
+
operation: operation2,
|
|
1773
1864
|
path,
|
|
1774
1865
|
...body === void 0 ? void 0 : { method: "POST", body }
|
|
1775
1866
|
});
|
|
1776
1867
|
if (!response.ok) {
|
|
1777
1868
|
ctx.log.warn("github.pull_request.stack_after_create.rejected", {
|
|
1778
1869
|
number: target.number,
|
|
1779
|
-
operation,
|
|
1870
|
+
operation: operation2,
|
|
1780
1871
|
repo,
|
|
1781
1872
|
status: response.status
|
|
1782
1873
|
});
|
|
@@ -1804,7 +1895,7 @@ async function stackGitHubPullRequest(ctx, target) {
|
|
|
1804
1895
|
const stacks = await github(
|
|
1805
1896
|
"github.stack.read",
|
|
1806
1897
|
`${api}/stacks?pull_request=${parent.number}`,
|
|
1807
|
-
|
|
1898
|
+
z12.array(stackSchema)
|
|
1808
1899
|
);
|
|
1809
1900
|
if (!stacks) return void 0;
|
|
1810
1901
|
const stack = stacks[0];
|
|
@@ -1841,6 +1932,59 @@ async function stackGitHubPullRequest(ctx, target) {
|
|
|
1841
1932
|
}
|
|
1842
1933
|
}
|
|
1843
1934
|
|
|
1935
|
+
// src/tool-support/pull-request-description.ts
|
|
1936
|
+
import {
|
|
1937
|
+
PluginToolInputError as PluginToolInputError10
|
|
1938
|
+
} from "@sentry/junior-plugin-api";
|
|
1939
|
+
var MISSING_REASON_FIX = "Say why the change is needed.";
|
|
1940
|
+
var DESCRIPTION_CHECKS = [
|
|
1941
|
+
{
|
|
1942
|
+
question: "Does the description report how tests, lint, typecheck, or CI went when the author ran them, passing or failing, locally or in CI, or describe a test plan or test coverage, including what has no tests? Text about what the product does with such commands does not count.",
|
|
1943
|
+
fix: "Remove check results, test plans, test coverage notes, and commands. Reviewers see checks on the pull request."
|
|
1944
|
+
},
|
|
1945
|
+
{
|
|
1946
|
+
question: "Does the description narrate the author's own work session, such as what the author investigated, approaches or names the author tried first and dropped, or how many runs the author looked at? Old behavior compared with new behavior does not count.",
|
|
1947
|
+
fix: "Remove the work log. Describe the change as it is now."
|
|
1948
|
+
},
|
|
1949
|
+
{
|
|
1950
|
+
question: "Does the description mention the request for this pull request, such as who asked for it or a chat message about it? A product feature that involves Slack or chat does not count.",
|
|
1951
|
+
fix: "Remove the conversation. The runtime adds who asked."
|
|
1952
|
+
},
|
|
1953
|
+
{
|
|
1954
|
+
question: "Does the description leave out why the change is needed or what problem it fixes?",
|
|
1955
|
+
fix: MISSING_REASON_FIX
|
|
1956
|
+
}
|
|
1957
|
+
];
|
|
1958
|
+
async function pullRequestDescriptionFixes(decider, body) {
|
|
1959
|
+
if (!body.trim()) {
|
|
1960
|
+
return [MISSING_REASON_FIX];
|
|
1961
|
+
}
|
|
1962
|
+
const answers = await Promise.all(
|
|
1963
|
+
DESCRIPTION_CHECKS.map(
|
|
1964
|
+
({ question }) => decider.decide({
|
|
1965
|
+
criteria: { no: "No.", yes: "Yes." },
|
|
1966
|
+
instructions: `Judge this GitHub pull request description. ${question}`,
|
|
1967
|
+
state: body
|
|
1968
|
+
})
|
|
1969
|
+
)
|
|
1970
|
+
);
|
|
1971
|
+
return DESCRIPTION_CHECKS.filter(
|
|
1972
|
+
(_, index2) => answers[index2].choice === "yes"
|
|
1973
|
+
).map(({ fix }) => fix);
|
|
1974
|
+
}
|
|
1975
|
+
async function checkPullRequestDescription(decider, body) {
|
|
1976
|
+
const fixes = await pullRequestDescriptionFixes(decider, body);
|
|
1977
|
+
if (fixes.length > 0) {
|
|
1978
|
+
throw new PluginToolInputError10(
|
|
1979
|
+
[
|
|
1980
|
+
"Pull request description rejected. Fix it and call the tool again:",
|
|
1981
|
+
...fixes.map((fix) => `- ${fix}`),
|
|
1982
|
+
"Write for a reviewer with no context: what changes and why, whether anything breaks and what to do, linked issues, and open questions. Keep it short."
|
|
1983
|
+
].join("\n")
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1844
1988
|
// src/tools/create-pull-request.ts
|
|
1845
1989
|
var GITHUB_PULL_REQUEST_CREATE_IDEMPOTENCY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1846
1990
|
var GITHUB_PULL_REQUEST_CREATE_LOCK_TTL_MS = 6e4;
|
|
@@ -1852,6 +1996,7 @@ var GitHubPullRequestCreateRejectedError = class extends Error {
|
|
|
1852
1996
|
this.status = status;
|
|
1853
1997
|
}
|
|
1854
1998
|
};
|
|
1999
|
+
var REVIEWERS_DESCRIPTION = "GitHub logins to ask for a review. Set this only when the person names who should review. Without it, Junior asks the requester's linked GitHub account. A draft gets the request when it becomes ready for review.";
|
|
1855
2000
|
var createPullRequestInputSchema = Type2.Object(
|
|
1856
2001
|
{
|
|
1857
2002
|
repo: Type2.String({
|
|
@@ -1875,19 +2020,26 @@ var createPullRequestInputSchema = Type2.Object(
|
|
|
1875
2020
|
Type2.Boolean({
|
|
1876
2021
|
description: "Whether to open the pull request as a draft."
|
|
1877
2022
|
})
|
|
2023
|
+
),
|
|
2024
|
+
reviewers: Type2.Optional(
|
|
2025
|
+
Type2.Array(Type2.String(), {
|
|
2026
|
+
description: REVIEWERS_DESCRIPTION,
|
|
2027
|
+
minItems: 1
|
|
2028
|
+
})
|
|
1878
2029
|
)
|
|
1879
2030
|
},
|
|
1880
2031
|
{ additionalProperties: false }
|
|
1881
2032
|
);
|
|
1882
|
-
var createPullRequestToolInputSchema =
|
|
1883
|
-
repo:
|
|
1884
|
-
title:
|
|
1885
|
-
head:
|
|
1886
|
-
base:
|
|
1887
|
-
body:
|
|
2033
|
+
var createPullRequestToolInputSchema = z13.object({
|
|
2034
|
+
repo: z13.string().describe('Repository in "owner/name" format.'),
|
|
2035
|
+
title: z13.string().describe("Pull request title."),
|
|
2036
|
+
head: z13.string().describe("Head branch or owner:branch ref."),
|
|
2037
|
+
base: z13.string().describe("Base branch."),
|
|
2038
|
+
body: z13.string().describe(
|
|
1888
2039
|
"Pull request body. The runtime appends the conversation footer."
|
|
1889
2040
|
).optional(),
|
|
1890
|
-
draft:
|
|
2041
|
+
draft: z13.boolean().describe("Whether to open the pull request as a draft.").optional(),
|
|
2042
|
+
reviewers: z13.array(z13.string()).min(1).describe(REVIEWERS_DESCRIPTION).optional()
|
|
1891
2043
|
}).strict();
|
|
1892
2044
|
var createPullRequestStateSchema = Type2.Union([
|
|
1893
2045
|
Type2.Object(
|
|
@@ -1912,30 +2064,30 @@ var createPullRequestStateSchema = Type2.Union([
|
|
|
1912
2064
|
{ additionalProperties: false }
|
|
1913
2065
|
)
|
|
1914
2066
|
]);
|
|
1915
|
-
var gitHubPullRequestDataSchema =
|
|
1916
|
-
number:
|
|
1917
|
-
url:
|
|
1918
|
-
stack:
|
|
2067
|
+
var gitHubPullRequestDataSchema = z13.object({
|
|
2068
|
+
number: z13.number(),
|
|
2069
|
+
url: z13.string(),
|
|
2070
|
+
stack: z13.object({ number: z13.number(), pull_requests: z13.array(z13.number()) }).optional(),
|
|
1919
2071
|
subscribable: subscribableResourceSchema4.optional(),
|
|
1920
2072
|
subscription: watchResultSchema.optional()
|
|
1921
2073
|
});
|
|
1922
2074
|
var gitHubPullRequestOutputSchema = pluginToolOutputSchema8.merge(
|
|
1923
2075
|
gitHubPullRequestDataSchema.extend({
|
|
1924
|
-
target:
|
|
2076
|
+
target: z13.literal("createPullRequest")
|
|
1925
2077
|
})
|
|
1926
2078
|
);
|
|
1927
2079
|
function parseCreatePullRequestInput(input) {
|
|
1928
2080
|
try {
|
|
1929
2081
|
return Value2.Parse(createPullRequestInputSchema, input);
|
|
1930
2082
|
} catch (error) {
|
|
1931
|
-
throw new
|
|
2083
|
+
throw new PluginToolInputError11("Invalid GitHub createPullRequest input.", {
|
|
1932
2084
|
cause: error
|
|
1933
2085
|
});
|
|
1934
2086
|
}
|
|
1935
2087
|
}
|
|
1936
2088
|
function nonEmptyString3(value, name) {
|
|
1937
2089
|
if (!value?.trim()) {
|
|
1938
|
-
throw new
|
|
2090
|
+
throw new PluginToolInputError11(`${name} is required`);
|
|
1939
2091
|
}
|
|
1940
2092
|
return value.trim();
|
|
1941
2093
|
}
|
|
@@ -1955,10 +2107,13 @@ function isEgressAuthRequired2(error) {
|
|
|
1955
2107
|
return error instanceof EgressAuthRequired2 || error instanceof Error && error.name === "EgressAuthRequired";
|
|
1956
2108
|
}
|
|
1957
2109
|
function isDefinitiveGitHubPullRequestCreateRejection(error) {
|
|
2110
|
+
if (error instanceof PluginToolInputError11) {
|
|
2111
|
+
return true;
|
|
2112
|
+
}
|
|
1958
2113
|
if (!(error instanceof GitHubPullRequestCreateRejectedError)) {
|
|
1959
2114
|
return false;
|
|
1960
2115
|
}
|
|
1961
|
-
return [400, 401,
|
|
2116
|
+
return [400, 401, 410].includes(error.status);
|
|
1962
2117
|
}
|
|
1963
2118
|
function createGitHubPullRequestRequest(conversationId, input, ctx, requester, dashboardUrl) {
|
|
1964
2119
|
const repo = parseRepo(input.repo);
|
|
@@ -1983,12 +2138,13 @@ async function createGitHubPullRequest(ctx, request) {
|
|
|
1983
2138
|
});
|
|
1984
2139
|
const parsed = response.body;
|
|
1985
2140
|
if (!response.ok) {
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
2141
|
+
const message = `GitHub pull request creation failed with HTTP ${response.status}: ${githubErrorMessage(
|
|
2142
|
+
parsed
|
|
2143
|
+
)}`;
|
|
2144
|
+
if (response.status === 404 || response.status === 422) {
|
|
2145
|
+
throw new PluginToolInputError11(message);
|
|
2146
|
+
}
|
|
2147
|
+
throw new GitHubPullRequestCreateRejectedError(message, response.status);
|
|
1992
2148
|
}
|
|
1993
2149
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1994
2150
|
throw new Error(
|
|
@@ -2049,6 +2205,59 @@ async function assignPullRequestRequester(ctx, input, result, requester) {
|
|
|
2049
2205
|
});
|
|
2050
2206
|
}
|
|
2051
2207
|
}
|
|
2208
|
+
function namedReviewers(input) {
|
|
2209
|
+
return input.reviewers?.map((value) => {
|
|
2210
|
+
const login2 = parseGitHubLogin(value);
|
|
2211
|
+
if (!login2) {
|
|
2212
|
+
throw new PluginToolInputError11(`Invalid GitHub reviewer login: ${value}`);
|
|
2213
|
+
}
|
|
2214
|
+
return login2;
|
|
2215
|
+
});
|
|
2216
|
+
}
|
|
2217
|
+
async function saveNamedDraftReviewers(ctx, input, number33) {
|
|
2218
|
+
const named = namedReviewers(input);
|
|
2219
|
+
if (!input.draft || !named) return;
|
|
2220
|
+
await saveGitHubDraftReviewers(
|
|
2221
|
+
ctx.state,
|
|
2222
|
+
{ number: number33, repositoryFullName: parseRepo(input.repo).ref },
|
|
2223
|
+
named
|
|
2224
|
+
);
|
|
2225
|
+
}
|
|
2226
|
+
async function requestPullRequestReviewers(ctx, input, result, requester) {
|
|
2227
|
+
const named = namedReviewers(input);
|
|
2228
|
+
const repo = parseRepo(input.repo);
|
|
2229
|
+
try {
|
|
2230
|
+
if (input.draft) {
|
|
2231
|
+
await saveNamedDraftReviewers(ctx, input, result.number);
|
|
2232
|
+
return;
|
|
2233
|
+
}
|
|
2234
|
+
const requesterLogin = linkedGitHubLogin(requester?.user);
|
|
2235
|
+
const reviewers = named ?? (requesterLogin ? [requesterLogin] : []);
|
|
2236
|
+
if (reviewers.length === 0) return;
|
|
2237
|
+
const response = await githubApi(ctx.egress, {
|
|
2238
|
+
operation: "github.pull.request_reviewers",
|
|
2239
|
+
method: "POST",
|
|
2240
|
+
path: `${repoPath(repo)}/pulls/${result.number}/requested_reviewers`,
|
|
2241
|
+
body: { reviewers }
|
|
2242
|
+
});
|
|
2243
|
+
if (!response.ok) {
|
|
2244
|
+
ctx.log.warn(
|
|
2245
|
+
"github.pull_request.request_reviewers_after_create.rejected",
|
|
2246
|
+
{
|
|
2247
|
+
number: result.number,
|
|
2248
|
+
repo: input.repo,
|
|
2249
|
+
status: response.status
|
|
2250
|
+
}
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
} catch (error) {
|
|
2254
|
+
ctx.log.warn("github.pull_request.request_reviewers_after_create.failed", {
|
|
2255
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2256
|
+
number: result.number,
|
|
2257
|
+
repo: input.repo
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2052
2261
|
function gitHubPullRequestToolResult(input, result, canSubscribe, omitSuggestedEvents) {
|
|
2053
2262
|
const repo = parseRepo(input.repo);
|
|
2054
2263
|
const subscribable = gitHubPullRequestSubscribable({
|
|
@@ -2090,7 +2299,9 @@ async function gitHubPullRequestStructuredResult(ctx, input, result, subscriptio
|
|
|
2090
2299
|
...stack ? { stack } : void 0
|
|
2091
2300
|
};
|
|
2092
2301
|
}
|
|
2093
|
-
const watch = gitHubPullRequestCreateWatch(subscriptionConfig
|
|
2302
|
+
const watch = gitHubPullRequestCreateWatch(subscriptionConfig, {
|
|
2303
|
+
draft: input.draft === true
|
|
2304
|
+
});
|
|
2094
2305
|
try {
|
|
2095
2306
|
const subscription = await ctx.events.subscribe({
|
|
2096
2307
|
...watch,
|
|
@@ -2123,7 +2334,7 @@ async function gitHubPullRequestStructuredResult(ctx, input, result, subscriptio
|
|
|
2123
2334
|
};
|
|
2124
2335
|
}
|
|
2125
2336
|
}
|
|
2126
|
-
function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
2337
|
+
function createGitHubPullRequestTool(ctx, subscriptionConfig, descriptionDecider) {
|
|
2127
2338
|
return definePluginTool8({
|
|
2128
2339
|
annotations: {
|
|
2129
2340
|
destructiveHint: false,
|
|
@@ -2131,12 +2342,13 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
2131
2342
|
openWorldHint: true,
|
|
2132
2343
|
readOnlyHint: false
|
|
2133
2344
|
},
|
|
2134
|
-
description: "Create a GitHub pull request with a runtime-owned conversation footer
|
|
2345
|
+
description: "Create a GitHub pull request with a runtime-owned conversation footer. It assigns the pull request to the requester's linked GitHub account and asks for a review when available. Use this instead of shelling out to gh pr create when creating pull requests.",
|
|
2135
2346
|
exposure: "direct",
|
|
2136
2347
|
inputSchema: createPullRequestToolInputSchema,
|
|
2137
2348
|
outputSchema: gitHubPullRequestOutputSchema,
|
|
2138
2349
|
async execute(input, options) {
|
|
2139
2350
|
const parsedInput = parseCreatePullRequestInput(input);
|
|
2351
|
+
namedReviewers(parsedInput);
|
|
2140
2352
|
const conversationId = nonEmptyString3(
|
|
2141
2353
|
ctx.conversationId,
|
|
2142
2354
|
"conversationId"
|
|
@@ -2154,6 +2366,7 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
2154
2366
|
conversationId,
|
|
2155
2367
|
identityId: (await resolveGitHubRequester(ctx))?.identity?.id
|
|
2156
2368
|
});
|
|
2369
|
+
await saveNamedDraftReviewers(ctx, completedInput, state.number);
|
|
2157
2370
|
const completedResult = {
|
|
2158
2371
|
facts: state.facts === void 0 ? void 0 : objectFactsSchema2.parse(state.facts),
|
|
2159
2372
|
sourceUpdatedAt: state.sourceUpdatedAt,
|
|
@@ -2173,6 +2386,12 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
2173
2386
|
"GitHub pull request creation for this tool call has an uncertain pending result; refusing to create a duplicate pull request."
|
|
2174
2387
|
);
|
|
2175
2388
|
}
|
|
2389
|
+
if (descriptionDecider) {
|
|
2390
|
+
await checkPullRequestDescription(
|
|
2391
|
+
descriptionDecider,
|
|
2392
|
+
parsedInput.body ?? ""
|
|
2393
|
+
);
|
|
2394
|
+
}
|
|
2176
2395
|
const requester = await resolveGitHubRequester(ctx);
|
|
2177
2396
|
const identityId = requester?.identity?.id;
|
|
2178
2397
|
const request = createGitHubPullRequestRequest(
|
|
@@ -2227,6 +2446,12 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
2227
2446
|
identityId
|
|
2228
2447
|
});
|
|
2229
2448
|
await assignPullRequestRequester(ctx, parsedInput, result, requester);
|
|
2449
|
+
await requestPullRequestReviewers(
|
|
2450
|
+
ctx,
|
|
2451
|
+
parsedInput,
|
|
2452
|
+
result,
|
|
2453
|
+
requester
|
|
2454
|
+
);
|
|
2230
2455
|
const stack = stackTarget ? await stackGitHubPullRequest(ctx, stackTarget) : void 0;
|
|
2231
2456
|
return await gitHubPullRequestStructuredResult(
|
|
2232
2457
|
ctx,
|
|
@@ -2244,33 +2469,322 @@ function createGitHubPullRequestTool(ctx, subscriptionConfig) {
|
|
|
2244
2469
|
// src/tools/get-pull-request.ts
|
|
2245
2470
|
import {
|
|
2246
2471
|
definePluginTool as definePluginTool9,
|
|
2247
|
-
PluginToolInputError as
|
|
2472
|
+
PluginToolInputError as PluginToolInputError12,
|
|
2248
2473
|
pluginToolOutputSchema as pluginToolOutputSchema9
|
|
2249
2474
|
} from "@sentry/junior-plugin-api";
|
|
2250
|
-
import * as
|
|
2475
|
+
import * as z14 from "zod";
|
|
2251
2476
|
import { subscribableResourceSchema as subscribableResourceSchema5 } from "@sentry/junior-plugin-api";
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2477
|
+
|
|
2478
|
+
// src/graphql-documents.ts
|
|
2479
|
+
import {
|
|
2480
|
+
Kind,
|
|
2481
|
+
parse,
|
|
2482
|
+
print,
|
|
2483
|
+
visit
|
|
2484
|
+
} from "@0no-co/graphql.web";
|
|
2485
|
+
function operation(document) {
|
|
2486
|
+
const [definition] = document.definitions;
|
|
2487
|
+
if (definition?.kind !== Kind.OPERATION_DEFINITION || !definition.name) {
|
|
2488
|
+
throw new Error(
|
|
2489
|
+
"GitHub GraphQL document must start with a named operation"
|
|
2490
|
+
);
|
|
2491
|
+
}
|
|
2492
|
+
return { operationName: definition.name.value, query: print(document) };
|
|
2493
|
+
}
|
|
2494
|
+
function githubGraphql(source) {
|
|
2495
|
+
return operation(parse(source));
|
|
2496
|
+
}
|
|
2497
|
+
var ADD_REVIEW_REACTION = githubGraphql(`
|
|
2498
|
+
mutation AddReviewReaction($subjectId: ID!, $content: ReactionContent!) {
|
|
2499
|
+
addReaction(input: { subjectId: $subjectId, content: $content }) {
|
|
2500
|
+
reaction { content }
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
`);
|
|
2504
|
+
var REMOVE_REVIEW_REACTION = githubGraphql(`
|
|
2505
|
+
mutation RemoveReviewReaction($subjectId: ID!, $content: ReactionContent!) {
|
|
2506
|
+
removeReaction(input: { subjectId: $subjectId, content: $content }) {
|
|
2507
|
+
reaction { content }
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
`);
|
|
2511
|
+
var REVIEW_REACTIONS = githubGraphql(`
|
|
2512
|
+
query ReviewReactions($subjectId: ID!) {
|
|
2513
|
+
node(id: $subjectId) {
|
|
2514
|
+
... on PullRequestReview {
|
|
2515
|
+
reactionGroups {
|
|
2516
|
+
content
|
|
2517
|
+
reactors(first: 100) { nodes { ... on Bot { databaseId } } }
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
`);
|
|
2523
|
+
var MARK_PULL_REQUEST_READY_FOR_REVIEW = githubGraphql(`
|
|
2524
|
+
mutation MarkPullRequestReadyForReview($id: ID!) {
|
|
2525
|
+
result: markPullRequestReadyForReview(input: { pullRequestId: $id }) {
|
|
2526
|
+
pullRequest { isDraft }
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
`);
|
|
2530
|
+
var CONVERT_PULL_REQUEST_TO_DRAFT = githubGraphql(`
|
|
2531
|
+
mutation ConvertPullRequestToDraft($id: ID!) {
|
|
2532
|
+
result: convertPullRequestToDraft(input: { pullRequestId: $id }) {
|
|
2533
|
+
pullRequest { isDraft }
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
`);
|
|
2537
|
+
var REVIEW_THREAD_OWNERSHIP = githubGraphql(`
|
|
2538
|
+
query ReviewThreadOwnership($threadId: ID!) {
|
|
2539
|
+
node(id: $threadId) {
|
|
2540
|
+
... on PullRequestReviewThread {
|
|
2541
|
+
id
|
|
2542
|
+
isResolved
|
|
2543
|
+
pullRequest {
|
|
2544
|
+
number
|
|
2545
|
+
repository { nameWithOwner }
|
|
2546
|
+
author { ... on Bot { databaseId } }
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
`);
|
|
2552
|
+
var RESOLVE_REVIEW_THREAD = githubGraphql(`
|
|
2553
|
+
mutation ResolveReviewThread($threadId: ID!) {
|
|
2554
|
+
resolveReviewThread(input: { threadId: $threadId }) {
|
|
2555
|
+
thread { id isResolved }
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
`);
|
|
2559
|
+
var PULL_REQUEST_CHECKS = githubGraphql(`
|
|
2560
|
+
query PullRequestChecks($owner: String!, $name: String!, $number: Int!) {
|
|
2561
|
+
repository(owner: $owner, name: $name) {
|
|
2562
|
+
pullRequest(number: $number) {
|
|
2563
|
+
mergeStateStatus
|
|
2564
|
+
reviewDecision
|
|
2565
|
+
autoMergeRequest { enabledAt }
|
|
2566
|
+
commits(last: 1) {
|
|
2567
|
+
nodes {
|
|
2568
|
+
commit {
|
|
2569
|
+
statusCheckRollup {
|
|
2570
|
+
contexts(first: 100) {
|
|
2571
|
+
pageInfo { hasNextPage }
|
|
2572
|
+
nodes {
|
|
2573
|
+
__typename
|
|
2574
|
+
... on CheckRun {
|
|
2575
|
+
name
|
|
2576
|
+
status
|
|
2577
|
+
conclusion
|
|
2578
|
+
isRequired(pullRequestNumber: $number)
|
|
2579
|
+
}
|
|
2580
|
+
... on StatusContext {
|
|
2581
|
+
context
|
|
2582
|
+
state
|
|
2583
|
+
isRequired(pullRequestNumber: $number)
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
`);
|
|
2595
|
+
var OPEN_PULL_REQUEST_MERGEABILITY = githubGraphql(`
|
|
2596
|
+
query OpenPullRequestMergeability($query: String!, $after: String) {
|
|
2597
|
+
search(query: $query, type: ISSUE, first: 100, after: $after) {
|
|
2598
|
+
pageInfo { hasNextPage endCursor }
|
|
2599
|
+
nodes {
|
|
2600
|
+
... on PullRequest { number state mergeable headRefOid baseRefName url }
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
`);
|
|
2605
|
+
var PULL_REQUEST_LIFECYCLE = githubGraphql(`
|
|
2606
|
+
query PullRequestLifecycles($owner: String!, $name: String!, $number: Int!) {
|
|
2607
|
+
repository(owner: $owner, name: $name) {
|
|
2608
|
+
databaseId
|
|
2609
|
+
nameWithOwner
|
|
2610
|
+
pullRequest(number: $number) { ...Lifecycle }
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
fragment Lifecycle on PullRequest {
|
|
2615
|
+
assignees(first: 20) { nodes { login } }
|
|
2616
|
+
author { __typename login }
|
|
2617
|
+
closedAt
|
|
2618
|
+
createdAt
|
|
2619
|
+
databaseId
|
|
2620
|
+
headRefName
|
|
2621
|
+
isDraft
|
|
2622
|
+
merged
|
|
2623
|
+
mergedAt
|
|
2624
|
+
number
|
|
2625
|
+
state
|
|
2626
|
+
title
|
|
2627
|
+
updatedAt
|
|
2628
|
+
}
|
|
2629
|
+
`);
|
|
2630
|
+
function pullRequestLifecycles(count) {
|
|
2631
|
+
const indexes = Array.from({ length: count }, (_, index2) => index2);
|
|
2632
|
+
const variable = (index2) => ({
|
|
2633
|
+
kind: Kind.VARIABLE,
|
|
2634
|
+
name: { kind: Kind.NAME, value: `n${index2}` }
|
|
2635
|
+
});
|
|
2636
|
+
return operation(
|
|
2637
|
+
visit(parse(PULL_REQUEST_LIFECYCLE.query), {
|
|
2638
|
+
OperationDefinition: (node) => ({
|
|
2639
|
+
...node,
|
|
2640
|
+
variableDefinitions: node.variableDefinitions?.flatMap(
|
|
2641
|
+
(definition) => definition.variable.name.value === "number" ? indexes.map((index2) => ({
|
|
2642
|
+
...definition,
|
|
2643
|
+
variable: variable(index2)
|
|
2644
|
+
})) : [definition]
|
|
2645
|
+
)
|
|
2646
|
+
}),
|
|
2647
|
+
SelectionSet: (node) => ({
|
|
2648
|
+
...node,
|
|
2649
|
+
selections: node.selections.flatMap(
|
|
2650
|
+
(selection) => selection.kind === Kind.FIELD && selection.name.value === "pullRequest" ? indexes.map((index2) => ({
|
|
2651
|
+
...selection,
|
|
2652
|
+
alias: { kind: Kind.NAME, value: `pr${index2}` },
|
|
2653
|
+
arguments: selection.arguments?.map((argument) => ({
|
|
2654
|
+
...argument,
|
|
2655
|
+
value: variable(index2)
|
|
2656
|
+
}))
|
|
2657
|
+
})) : [selection]
|
|
2658
|
+
)
|
|
2659
|
+
})
|
|
2660
|
+
})
|
|
2661
|
+
);
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
// src/tools/get-pull-request.ts
|
|
2665
|
+
var commitShaSchema2 = z14.string().regex(/^[0-9a-f]{40}$/i);
|
|
2666
|
+
var inputSchema7 = z14.object({
|
|
2667
|
+
repo: z14.string().describe('Repository in "owner/name" format.'),
|
|
2668
|
+
number: z14.number().int().positive().describe("Pull request number.")
|
|
2256
2669
|
}).strict();
|
|
2257
|
-
var
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2670
|
+
var checksSchema = z14.object({
|
|
2671
|
+
required: z14.enum(["passing", "failing", "pending", "not_reported"]).describe(
|
|
2672
|
+
"State of the required checks on the head commit. not_reported means no required check has reported yet; it does not mean that none are required."
|
|
2673
|
+
),
|
|
2674
|
+
failing: z14.array(z14.string()).describe("Required checks that failed."),
|
|
2675
|
+
pending: z14.array(z14.string()).describe("Required checks that have not finished."),
|
|
2676
|
+
passing: z14.array(z14.string()).describe("Required checks that passed."),
|
|
2677
|
+
incomplete: z14.literal(true).optional().describe(
|
|
2678
|
+
"Set when the head commit has more than 100 checks, so some required checks are not listed."
|
|
2679
|
+
),
|
|
2680
|
+
merge_state: z14.string().describe(
|
|
2681
|
+
"GitHub mergeStateStatus, such as CLEAN, BLOCKED, BEHIND, DIRTY, UNSTABLE, DRAFT, or UNKNOWN. BLOCKED while the listed required checks pass means a required check that has not started, a review, or another rule blocks the merge."
|
|
2682
|
+
),
|
|
2683
|
+
review_decision: z14.string().nullable().describe(
|
|
2684
|
+
"GitHub reviewDecision: APPROVED, CHANGES_REQUESTED, REVIEW_REQUIRED, or null when no review is required."
|
|
2685
|
+
),
|
|
2686
|
+
auto_merge: z14.boolean().describe("true when auto-merge is on for the pull request.")
|
|
2687
|
+
});
|
|
2688
|
+
var pullRequestSchema = z14.object({
|
|
2689
|
+
base: z14.string(),
|
|
2690
|
+
checks: checksSchema,
|
|
2691
|
+
draft: z14.boolean(),
|
|
2692
|
+
head: z14.string(),
|
|
2261
2693
|
head_sha: commitShaSchema2,
|
|
2262
|
-
merged:
|
|
2263
|
-
number:
|
|
2264
|
-
state:
|
|
2694
|
+
merged: z14.boolean(),
|
|
2695
|
+
number: z14.number(),
|
|
2696
|
+
state: z14.string(),
|
|
2265
2697
|
subscribable: subscribableResourceSchema5.optional(),
|
|
2266
|
-
title:
|
|
2267
|
-
url:
|
|
2698
|
+
title: z14.string(),
|
|
2699
|
+
url: z14.string()
|
|
2268
2700
|
});
|
|
2269
2701
|
var outputSchema7 = pluginToolOutputSchema9.merge(
|
|
2270
2702
|
pullRequestSchema.extend({
|
|
2271
|
-
target:
|
|
2703
|
+
target: z14.literal("getPullRequest")
|
|
2272
2704
|
})
|
|
2273
2705
|
);
|
|
2706
|
+
var checkContextSchema = z14.union([
|
|
2707
|
+
z14.object({
|
|
2708
|
+
__typename: z14.literal("CheckRun"),
|
|
2709
|
+
conclusion: z14.string().nullable(),
|
|
2710
|
+
isRequired: z14.boolean(),
|
|
2711
|
+
name: z14.string(),
|
|
2712
|
+
status: z14.string()
|
|
2713
|
+
}),
|
|
2714
|
+
z14.object({
|
|
2715
|
+
__typename: z14.literal("StatusContext"),
|
|
2716
|
+
context: z14.string(),
|
|
2717
|
+
isRequired: z14.boolean(),
|
|
2718
|
+
state: z14.string()
|
|
2719
|
+
})
|
|
2720
|
+
]);
|
|
2721
|
+
var checksResponseSchema = z14.object({
|
|
2722
|
+
data: z14.object({
|
|
2723
|
+
repository: z14.object({
|
|
2724
|
+
pullRequest: z14.object({
|
|
2725
|
+
autoMergeRequest: z14.object({}).passthrough().nullable(),
|
|
2726
|
+
commits: z14.object({
|
|
2727
|
+
nodes: z14.array(
|
|
2728
|
+
z14.object({
|
|
2729
|
+
commit: z14.object({
|
|
2730
|
+
statusCheckRollup: z14.object({
|
|
2731
|
+
contexts: z14.object({
|
|
2732
|
+
nodes: z14.array(checkContextSchema),
|
|
2733
|
+
pageInfo: z14.object({ hasNextPage: z14.boolean() })
|
|
2734
|
+
})
|
|
2735
|
+
}).nullable()
|
|
2736
|
+
})
|
|
2737
|
+
})
|
|
2738
|
+
)
|
|
2739
|
+
}),
|
|
2740
|
+
mergeStateStatus: z14.string(),
|
|
2741
|
+
reviewDecision: z14.string().nullable()
|
|
2742
|
+
})
|
|
2743
|
+
})
|
|
2744
|
+
})
|
|
2745
|
+
});
|
|
2746
|
+
var PASSING_CONCLUSIONS = /* @__PURE__ */ new Set(["SUCCESS", "NEUTRAL", "SKIPPED"]);
|
|
2747
|
+
function contextState(context) {
|
|
2748
|
+
if (context.__typename === "CheckRun") {
|
|
2749
|
+
if (context.status !== "COMPLETED") return "pending";
|
|
2750
|
+
return PASSING_CONCLUSIONS.has(context.conclusion ?? "") ? "passing" : "failing";
|
|
2751
|
+
}
|
|
2752
|
+
if (context.state === "SUCCESS") return "passing";
|
|
2753
|
+
return context.state === "PENDING" || context.state === "EXPECTED" ? "pending" : "failing";
|
|
2754
|
+
}
|
|
2755
|
+
async function readPullRequestChecks(egress, repo, number33) {
|
|
2756
|
+
const response = await githubApi(egress, {
|
|
2757
|
+
operation: "github.pull.checks.get",
|
|
2758
|
+
method: "POST",
|
|
2759
|
+
path: "/graphql",
|
|
2760
|
+
body: {
|
|
2761
|
+
...PULL_REQUEST_CHECKS,
|
|
2762
|
+
variables: { name: repo.name, number: number33, owner: repo.owner }
|
|
2763
|
+
}
|
|
2764
|
+
});
|
|
2765
|
+
if (!response.ok) {
|
|
2766
|
+
throw new Error(
|
|
2767
|
+
`GitHub pull request checks lookup failed with HTTP ${response.status}`
|
|
2768
|
+
);
|
|
2769
|
+
}
|
|
2770
|
+
const pullRequest = checksResponseSchema.parse(response.body).data.repository.pullRequest;
|
|
2771
|
+
const rollup = pullRequest.commits.nodes[0]?.commit.statusCheckRollup;
|
|
2772
|
+
const checks = { failing: [], pending: [], passing: [] };
|
|
2773
|
+
for (const context of rollup?.contexts.nodes ?? []) {
|
|
2774
|
+
if (!context.isRequired) continue;
|
|
2775
|
+
checks[contextState(context)].push(
|
|
2776
|
+
context.__typename === "CheckRun" ? context.name : context.context
|
|
2777
|
+
);
|
|
2778
|
+
}
|
|
2779
|
+
return {
|
|
2780
|
+
required: checks.failing.length > 0 ? "failing" : checks.pending.length > 0 ? "pending" : checks.passing.length > 0 ? "passing" : "not_reported",
|
|
2781
|
+
...checks,
|
|
2782
|
+
...rollup?.contexts.pageInfo.hasNextPage ? { incomplete: true } : void 0,
|
|
2783
|
+
merge_state: pullRequest.mergeStateStatus,
|
|
2784
|
+
review_decision: pullRequest.reviewDecision,
|
|
2785
|
+
auto_merge: pullRequest.autoMergeRequest !== null
|
|
2786
|
+
};
|
|
2787
|
+
}
|
|
2274
2788
|
function createGitHubGetPullRequestTool(ctx) {
|
|
2275
2789
|
return definePluginTool9({
|
|
2276
2790
|
annotations: {
|
|
@@ -2279,7 +2793,7 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2279
2793
|
openWorldHint: true,
|
|
2280
2794
|
readOnlyHint: true
|
|
2281
2795
|
},
|
|
2282
|
-
description: "Get a GitHub pull request. Use this when an existing PR may need event monitoring; the result includes a subscribable hint when GitHub webhooks are configured.",
|
|
2796
|
+
description: "Get a GitHub pull request with its required checks and merge state. Use this when an existing PR may need event monitoring; the result includes a subscribable hint when GitHub webhooks are configured.",
|
|
2283
2797
|
inputSchema: inputSchema7,
|
|
2284
2798
|
outputSchema: outputSchema7,
|
|
2285
2799
|
async execute(input) {
|
|
@@ -2291,20 +2805,25 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2291
2805
|
if (!response.ok) {
|
|
2292
2806
|
const message = `GitHub pull request lookup failed with HTTP ${response.status}`;
|
|
2293
2807
|
if (response.status === 404) {
|
|
2294
|
-
throw new
|
|
2808
|
+
throw new PluginToolInputError12(message);
|
|
2295
2809
|
}
|
|
2296
2810
|
throw new Error(message);
|
|
2297
2811
|
}
|
|
2298
|
-
const providerResult =
|
|
2299
|
-
base:
|
|
2300
|
-
draft:
|
|
2301
|
-
head:
|
|
2302
|
-
html_url:
|
|
2303
|
-
merged:
|
|
2304
|
-
number:
|
|
2305
|
-
state:
|
|
2306
|
-
title:
|
|
2812
|
+
const providerResult = z14.object({
|
|
2813
|
+
base: z14.object({ ref: z14.string() }),
|
|
2814
|
+
draft: z14.boolean(),
|
|
2815
|
+
head: z14.object({ ref: z14.string(), sha: commitShaSchema2 }),
|
|
2816
|
+
html_url: z14.string(),
|
|
2817
|
+
merged: z14.boolean().optional().default(false),
|
|
2818
|
+
number: z14.number(),
|
|
2819
|
+
state: z14.string(),
|
|
2820
|
+
title: z14.string()
|
|
2307
2821
|
}).parse(response.body);
|
|
2822
|
+
const checks = await readPullRequestChecks(
|
|
2823
|
+
ctx.egress,
|
|
2824
|
+
repo,
|
|
2825
|
+
providerResult.number
|
|
2826
|
+
);
|
|
2308
2827
|
const subscribable = gitHubPullRequestSubscribable({
|
|
2309
2828
|
canSubscribe: ctx.events.canSubscribe,
|
|
2310
2829
|
number: providerResult.number,
|
|
@@ -2312,6 +2831,7 @@ function createGitHubGetPullRequestTool(ctx) {
|
|
|
2312
2831
|
});
|
|
2313
2832
|
const data = {
|
|
2314
2833
|
base: providerResult.base.ref,
|
|
2834
|
+
checks,
|
|
2315
2835
|
draft: providerResult.draft,
|
|
2316
2836
|
head: providerResult.head.ref,
|
|
2317
2837
|
head_sha: providerResult.head.sha.toLowerCase(),
|
|
@@ -2347,45 +2867,45 @@ import {
|
|
|
2347
2867
|
pluginToolOutputSchema as pluginToolOutputSchema10,
|
|
2348
2868
|
subscribableResourceSchema as subscribableResourceSchema6
|
|
2349
2869
|
} from "@sentry/junior-plugin-api";
|
|
2350
|
-
import * as
|
|
2351
|
-
var inputSchema8 =
|
|
2352
|
-
repo:
|
|
2353
|
-
tag:
|
|
2870
|
+
import * as z15 from "zod";
|
|
2871
|
+
var inputSchema8 = z15.object({
|
|
2872
|
+
repo: z15.string().describe('Repository in "owner/name" format.'),
|
|
2873
|
+
tag: z15.string().trim().min(1).describe(
|
|
2354
2874
|
"Optional release tag name. Omit to inspect and watch every published release in the repository."
|
|
2355
2875
|
).optional()
|
|
2356
2876
|
}).strict();
|
|
2357
|
-
var releaseSchema =
|
|
2358
|
-
created_at:
|
|
2359
|
-
draft:
|
|
2360
|
-
html_url:
|
|
2361
|
-
id:
|
|
2362
|
-
name:
|
|
2363
|
-
prerelease:
|
|
2364
|
-
published_at:
|
|
2365
|
-
tag_name:
|
|
2366
|
-
target_commitish:
|
|
2877
|
+
var releaseSchema = z15.object({
|
|
2878
|
+
created_at: z15.string(),
|
|
2879
|
+
draft: z15.boolean(),
|
|
2880
|
+
html_url: z15.string(),
|
|
2881
|
+
id: z15.number(),
|
|
2882
|
+
name: z15.string().nullable(),
|
|
2883
|
+
prerelease: z15.boolean(),
|
|
2884
|
+
published_at: z15.string().nullable(),
|
|
2885
|
+
tag_name: z15.string(),
|
|
2886
|
+
target_commitish: z15.string()
|
|
2367
2887
|
}).strict();
|
|
2368
|
-
var releaseSourceSchema =
|
|
2888
|
+
var releaseSourceSchema = z15.object({
|
|
2369
2889
|
release: releaseSchema.nullable(),
|
|
2370
|
-
repo:
|
|
2890
|
+
repo: z15.string(),
|
|
2371
2891
|
subscribable: subscribableResourceSchema6.optional(),
|
|
2372
|
-
tag:
|
|
2892
|
+
tag: z15.string().nullable()
|
|
2373
2893
|
}).strict();
|
|
2374
2894
|
var outputSchema8 = pluginToolOutputSchema10.merge(
|
|
2375
2895
|
releaseSourceSchema.extend({
|
|
2376
|
-
target:
|
|
2896
|
+
target: z15.literal("getRelease")
|
|
2377
2897
|
})
|
|
2378
2898
|
);
|
|
2379
|
-
var providerReleaseSchema =
|
|
2380
|
-
created_at:
|
|
2381
|
-
draft:
|
|
2382
|
-
html_url:
|
|
2383
|
-
id:
|
|
2384
|
-
name:
|
|
2385
|
-
prerelease:
|
|
2386
|
-
published_at:
|
|
2387
|
-
tag_name:
|
|
2388
|
-
target_commitish:
|
|
2899
|
+
var providerReleaseSchema = z15.object({
|
|
2900
|
+
created_at: z15.string(),
|
|
2901
|
+
draft: z15.boolean(),
|
|
2902
|
+
html_url: z15.string(),
|
|
2903
|
+
id: z15.number(),
|
|
2904
|
+
name: z15.string().nullable(),
|
|
2905
|
+
prerelease: z15.boolean(),
|
|
2906
|
+
published_at: z15.string().nullable(),
|
|
2907
|
+
tag_name: z15.string(),
|
|
2908
|
+
target_commitish: z15.string()
|
|
2389
2909
|
}).passthrough();
|
|
2390
2910
|
function mapRelease(providerRelease) {
|
|
2391
2911
|
return {
|
|
@@ -2464,25 +2984,25 @@ function createGitHubGetReleaseTool(ctx) {
|
|
|
2464
2984
|
// src/tools/get-repository.ts
|
|
2465
2985
|
import {
|
|
2466
2986
|
definePluginTool as definePluginTool11,
|
|
2467
|
-
PluginToolInputError as
|
|
2987
|
+
PluginToolInputError as PluginToolInputError13,
|
|
2468
2988
|
pluginToolOutputSchema as pluginToolOutputSchema11,
|
|
2469
2989
|
subscribableResourceSchema as subscribableResourceSchema7
|
|
2470
2990
|
} from "@sentry/junior-plugin-api";
|
|
2471
|
-
import * as
|
|
2472
|
-
var inputSchema9 =
|
|
2473
|
-
repo:
|
|
2991
|
+
import * as z16 from "zod";
|
|
2992
|
+
var inputSchema9 = z16.object({
|
|
2993
|
+
repo: z16.string().describe('Repository in "owner/name" format.')
|
|
2474
2994
|
}).strict();
|
|
2475
|
-
var repositorySchema =
|
|
2476
|
-
default_branch:
|
|
2477
|
-
description:
|
|
2478
|
-
full_name:
|
|
2479
|
-
private:
|
|
2995
|
+
var repositorySchema = z16.object({
|
|
2996
|
+
default_branch: z16.string(),
|
|
2997
|
+
description: z16.string().nullable(),
|
|
2998
|
+
full_name: z16.string(),
|
|
2999
|
+
private: z16.boolean(),
|
|
2480
3000
|
subscribable: subscribableResourceSchema7.optional(),
|
|
2481
|
-
url:
|
|
3001
|
+
url: z16.string()
|
|
2482
3002
|
});
|
|
2483
3003
|
var outputSchema9 = pluginToolOutputSchema11.merge(
|
|
2484
3004
|
repositorySchema.extend({
|
|
2485
|
-
target:
|
|
3005
|
+
target: z16.literal("getRepository")
|
|
2486
3006
|
})
|
|
2487
3007
|
);
|
|
2488
3008
|
function createGitHubGetRepositoryTool(ctx) {
|
|
@@ -2503,16 +3023,16 @@ function createGitHubGetRepositoryTool(ctx) {
|
|
|
2503
3023
|
path: repoPath(repo)
|
|
2504
3024
|
});
|
|
2505
3025
|
if (!response.ok) {
|
|
2506
|
-
throw new
|
|
3026
|
+
throw new PluginToolInputError13(
|
|
2507
3027
|
`GitHub repository lookup failed with HTTP ${response.status}`
|
|
2508
3028
|
);
|
|
2509
3029
|
}
|
|
2510
|
-
const providerResult =
|
|
2511
|
-
default_branch:
|
|
2512
|
-
description:
|
|
2513
|
-
full_name:
|
|
2514
|
-
html_url:
|
|
2515
|
-
private:
|
|
3030
|
+
const providerResult = z16.object({
|
|
3031
|
+
default_branch: z16.string(),
|
|
3032
|
+
description: z16.string().nullable(),
|
|
3033
|
+
full_name: z16.string(),
|
|
3034
|
+
html_url: z16.string(),
|
|
3035
|
+
private: z16.boolean()
|
|
2516
3036
|
}).parse(response.body);
|
|
2517
3037
|
const subscribable = gitHubRepositorySubscribable({
|
|
2518
3038
|
canSubscribe: ctx.events.canSubscribe,
|
|
@@ -2539,24 +3059,24 @@ import {
|
|
|
2539
3059
|
definePluginTool as definePluginTool12,
|
|
2540
3060
|
pluginToolOutputSchema as pluginToolOutputSchema12
|
|
2541
3061
|
} from "@sentry/junior-plugin-api";
|
|
2542
|
-
import * as
|
|
3062
|
+
import * as z18 from "zod";
|
|
2543
3063
|
|
|
2544
3064
|
// src/github-status.ts
|
|
2545
|
-
import * as
|
|
3065
|
+
import * as z17 from "zod";
|
|
2546
3066
|
var GITHUB_STATUS_INCIDENTS_URL = "https://www.githubstatus.com/api/v2/incidents.json";
|
|
2547
3067
|
var GITHUB_STATUS_TTL_MS = 60 * 1e3;
|
|
2548
3068
|
var GITHUB_STATUS_TIMEOUT_MS = 5e3;
|
|
2549
|
-
var incidentsResponseSchema =
|
|
2550
|
-
incidents:
|
|
2551
|
-
|
|
2552
|
-
components:
|
|
2553
|
-
created_at:
|
|
2554
|
-
impact:
|
|
2555
|
-
name:
|
|
2556
|
-
resolved_at:
|
|
2557
|
-
shortlink:
|
|
2558
|
-
started_at:
|
|
2559
|
-
status:
|
|
3069
|
+
var incidentsResponseSchema = z17.object({
|
|
3070
|
+
incidents: z17.array(
|
|
3071
|
+
z17.object({
|
|
3072
|
+
components: z17.array(z17.object({ name: z17.string() })).default([]),
|
|
3073
|
+
created_at: z17.string(),
|
|
3074
|
+
impact: z17.string(),
|
|
3075
|
+
name: z17.string(),
|
|
3076
|
+
resolved_at: z17.string().nullable(),
|
|
3077
|
+
shortlink: z17.string(),
|
|
3078
|
+
started_at: z17.string().nullable().optional(),
|
|
3079
|
+
status: z17.string()
|
|
2560
3080
|
})
|
|
2561
3081
|
)
|
|
2562
3082
|
});
|
|
@@ -2598,19 +3118,19 @@ async function loadGitHubStatusIncidents(cache, withinMs) {
|
|
|
2598
3118
|
|
|
2599
3119
|
// src/tools/get-status.ts
|
|
2600
3120
|
var RECENT_INCIDENT_MS = 24 * 60 * 60 * 1e3;
|
|
2601
|
-
var inputSchema10 =
|
|
2602
|
-
var incidentSchema =
|
|
2603
|
-
components:
|
|
2604
|
-
impact:
|
|
2605
|
-
name:
|
|
2606
|
-
resolved_at:
|
|
2607
|
-
started_at:
|
|
2608
|
-
status:
|
|
2609
|
-
url:
|
|
3121
|
+
var inputSchema10 = z18.object({}).strict();
|
|
3122
|
+
var incidentSchema = z18.object({
|
|
3123
|
+
components: z18.array(z18.string()),
|
|
3124
|
+
impact: z18.string(),
|
|
3125
|
+
name: z18.string(),
|
|
3126
|
+
resolved_at: z18.string().optional(),
|
|
3127
|
+
started_at: z18.string(),
|
|
3128
|
+
status: z18.string(),
|
|
3129
|
+
url: z18.string()
|
|
2610
3130
|
});
|
|
2611
3131
|
var outputSchema10 = pluginToolOutputSchema12.extend({
|
|
2612
|
-
target:
|
|
2613
|
-
incidents:
|
|
3132
|
+
target: z18.literal("getStatus"),
|
|
3133
|
+
incidents: z18.array(incidentSchema)
|
|
2614
3134
|
});
|
|
2615
3135
|
function createGitHubGetStatusTool(ctx) {
|
|
2616
3136
|
return definePluginTool12({
|
|
@@ -2646,50 +3166,50 @@ function createGitHubGetStatusTool(ctx) {
|
|
|
2646
3166
|
// src/tools/update-issue.ts
|
|
2647
3167
|
import {
|
|
2648
3168
|
definePluginTool as definePluginTool13,
|
|
2649
|
-
PluginToolInputError as
|
|
3169
|
+
PluginToolInputError as PluginToolInputError14,
|
|
2650
3170
|
pluginToolOutputSchema as pluginToolOutputSchema13,
|
|
2651
3171
|
subscribableResourceSchema as subscribableResourceSchema8
|
|
2652
3172
|
} from "@sentry/junior-plugin-api";
|
|
2653
|
-
import * as
|
|
2654
|
-
var inputSchema11 =
|
|
2655
|
-
repo:
|
|
2656
|
-
number:
|
|
2657
|
-
title:
|
|
2658
|
-
body:
|
|
3173
|
+
import * as z19 from "zod";
|
|
3174
|
+
var inputSchema11 = z19.object({
|
|
3175
|
+
repo: z19.string().describe('Repository in "owner/name" format.'),
|
|
3176
|
+
number: z19.number().int().positive().describe("Issue number."),
|
|
3177
|
+
title: z19.string().trim().min(1).optional().describe("Replacement issue title."),
|
|
3178
|
+
body: z19.string().optional().describe(
|
|
2659
3179
|
"Replacement issue body. The runtime appends requester attribution and the conversation footer."
|
|
2660
3180
|
),
|
|
2661
|
-
state:
|
|
2662
|
-
assign_requester:
|
|
3181
|
+
state: z19.enum(["open", "closed"]).optional().describe("Replacement issue state."),
|
|
3182
|
+
assign_requester: z19.boolean().optional().describe(
|
|
2663
3183
|
"Set true to add the requester's linked GitHub account as an assignee. Other assignees stay."
|
|
2664
3184
|
)
|
|
2665
3185
|
}).strict().refine(
|
|
2666
3186
|
({ title, body, state, assign_requester }) => title !== void 0 || body !== void 0 || state !== void 0 || assign_requester === true,
|
|
2667
3187
|
{ message: "At least one issue field must be provided." }
|
|
2668
3188
|
);
|
|
2669
|
-
var issueSchema2 =
|
|
2670
|
-
assignees:
|
|
2671
|
-
body:
|
|
2672
|
-
number:
|
|
2673
|
-
state:
|
|
3189
|
+
var issueSchema2 = z19.object({
|
|
3190
|
+
assignees: z19.array(z19.string()),
|
|
3191
|
+
body: z19.string().nullable(),
|
|
3192
|
+
number: z19.number(),
|
|
3193
|
+
state: z19.string(),
|
|
2674
3194
|
subscribable: subscribableResourceSchema8.optional(),
|
|
2675
|
-
title:
|
|
2676
|
-
url:
|
|
3195
|
+
title: z19.string(),
|
|
3196
|
+
url: z19.string()
|
|
2677
3197
|
});
|
|
2678
3198
|
var outputSchema11 = pluginToolOutputSchema13.merge(
|
|
2679
3199
|
issueSchema2.extend({
|
|
2680
|
-
target:
|
|
3200
|
+
target: z19.literal("updateIssue")
|
|
2681
3201
|
})
|
|
2682
3202
|
);
|
|
2683
|
-
var providerIssueSchema2 =
|
|
2684
|
-
assignees:
|
|
2685
|
-
body:
|
|
2686
|
-
html_url:
|
|
2687
|
-
number:
|
|
2688
|
-
state:
|
|
2689
|
-
title:
|
|
3203
|
+
var providerIssueSchema2 = z19.object({
|
|
3204
|
+
assignees: z19.array(z19.object({ login: z19.string() })).nullish().transform((assignees) => assignees?.map(({ login: login2 }) => login2) ?? []),
|
|
3205
|
+
body: z19.string().nullable().optional().default(null),
|
|
3206
|
+
html_url: z19.string(),
|
|
3207
|
+
number: z19.number(),
|
|
3208
|
+
state: z19.string(),
|
|
3209
|
+
title: z19.string()
|
|
2690
3210
|
});
|
|
2691
3211
|
function nonEmptyString4(value, name) {
|
|
2692
|
-
if (!value?.trim()) throw new
|
|
3212
|
+
if (!value?.trim()) throw new PluginToolInputError14(`${name} is required`);
|
|
2693
3213
|
return value.trim();
|
|
2694
3214
|
}
|
|
2695
3215
|
function createGitHubUpdateIssueTool(ctx) {
|
|
@@ -2706,7 +3226,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2706
3226
|
async execute(input) {
|
|
2707
3227
|
const parsedInput = inputSchema11.safeParse(input);
|
|
2708
3228
|
if (!parsedInput.success) {
|
|
2709
|
-
throw new
|
|
3229
|
+
throw new PluginToolInputError14("Invalid GitHub updateIssue input.", {
|
|
2710
3230
|
cause: parsedInput.error
|
|
2711
3231
|
});
|
|
2712
3232
|
}
|
|
@@ -2715,7 +3235,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2715
3235
|
const requester = update.body !== void 0 || update.assign_requester ? await resolveGitHubRequester(ctx) : void 0;
|
|
2716
3236
|
const assignee = update.assign_requester ? linkedGitHubLogin(requester?.user) : void 0;
|
|
2717
3237
|
if (update.assign_requester && !assignee) {
|
|
2718
|
-
throw new
|
|
3238
|
+
throw new PluginToolInputError14(
|
|
2719
3239
|
"The requester has no linked GitHub account, so Junior cannot assign the issue to them."
|
|
2720
3240
|
);
|
|
2721
3241
|
}
|
|
@@ -2765,7 +3285,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2765
3285
|
if (!response.ok) {
|
|
2766
3286
|
const message = `GitHub issue assignment failed with HTTP ${response.status}: ${githubErrorMessage(parsed)}`;
|
|
2767
3287
|
if (response.status === 404 || response.status === 422) {
|
|
2768
|
-
throw new
|
|
3288
|
+
throw new PluginToolInputError14(message);
|
|
2769
3289
|
}
|
|
2770
3290
|
throw new Error(message);
|
|
2771
3291
|
}
|
|
@@ -2774,7 +3294,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2774
3294
|
if (assignee && !providerResult.assignees.some(
|
|
2775
3295
|
(login2) => login2.toLowerCase() === assignee.toLowerCase()
|
|
2776
3296
|
)) {
|
|
2777
|
-
throw new
|
|
3297
|
+
throw new PluginToolInputError14(
|
|
2778
3298
|
`GitHub did not assign @${assignee} to the issue. They may not have access to ${repo.ref}.`
|
|
2779
3299
|
);
|
|
2780
3300
|
}
|
|
@@ -2811,20 +3331,20 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2811
3331
|
// src/tools/update-issue-comment.ts
|
|
2812
3332
|
import {
|
|
2813
3333
|
definePluginTool as definePluginTool14,
|
|
2814
|
-
PluginToolInputError as
|
|
3334
|
+
PluginToolInputError as PluginToolInputError15,
|
|
2815
3335
|
pluginToolOutputSchema as pluginToolOutputSchema14
|
|
2816
3336
|
} from "@sentry/junior-plugin-api";
|
|
2817
|
-
import * as
|
|
2818
|
-
var inputSchema12 =
|
|
2819
|
-
repo:
|
|
2820
|
-
comment_id:
|
|
2821
|
-
body:
|
|
3337
|
+
import * as z20 from "zod";
|
|
3338
|
+
var inputSchema12 = z20.object({
|
|
3339
|
+
repo: z20.string().describe('Repository in "owner/name" format.'),
|
|
3340
|
+
comment_id: z20.number().int().positive().describe("Issue comment id, as returned by github_commentOnIssue."),
|
|
3341
|
+
body: z20.string().trim().min(1).describe("Replacement comment text.")
|
|
2822
3342
|
}).strict();
|
|
2823
3343
|
var outputSchema12 = pluginToolOutputSchema14.extend({
|
|
2824
|
-
target:
|
|
2825
|
-
repo:
|
|
2826
|
-
comment_id:
|
|
2827
|
-
url:
|
|
3344
|
+
target: z20.literal("updateIssueComment"),
|
|
3345
|
+
repo: z20.string(),
|
|
3346
|
+
comment_id: z20.number(),
|
|
3347
|
+
url: z20.string()
|
|
2828
3348
|
});
|
|
2829
3349
|
function createGitHubUpdateIssueCommentTool(egress, botEmail) {
|
|
2830
3350
|
return definePluginTool14({
|
|
@@ -2850,12 +3370,12 @@ function createGitHubUpdateIssueCommentTool(egress, botEmail) {
|
|
|
2850
3370
|
});
|
|
2851
3371
|
if (!lookup.ok) {
|
|
2852
3372
|
const message = `GitHub issue comment lookup failed with HTTP ${lookup.status}: ${githubErrorMessage(lookup.body)}`;
|
|
2853
|
-
if (lookup.status === 404) throw new
|
|
3373
|
+
if (lookup.status === 404) throw new PluginToolInputError15(message);
|
|
2854
3374
|
throw new Error(message);
|
|
2855
3375
|
}
|
|
2856
|
-
const author =
|
|
3376
|
+
const author = z20.object({ user: z20.object({ id: z20.number() }).nullable() }).safeParse(lookup.body);
|
|
2857
3377
|
if (!author.success || author.data.user?.id !== botUserId) {
|
|
2858
|
-
throw new
|
|
3378
|
+
throw new PluginToolInputError15(
|
|
2859
3379
|
"This bot can only edit issue comments it posted."
|
|
2860
3380
|
);
|
|
2861
3381
|
}
|
|
@@ -2868,11 +3388,11 @@ function createGitHubUpdateIssueCommentTool(egress, botEmail) {
|
|
|
2868
3388
|
if (!response.ok) {
|
|
2869
3389
|
const message = `GitHub issue comment update failed with HTTP ${response.status}: ${githubErrorMessage(response.body)}`;
|
|
2870
3390
|
if (response.status === 404 || response.status === 422) {
|
|
2871
|
-
throw new
|
|
3391
|
+
throw new PluginToolInputError15(message);
|
|
2872
3392
|
}
|
|
2873
3393
|
throw new Error(message);
|
|
2874
3394
|
}
|
|
2875
|
-
const comment =
|
|
3395
|
+
const comment = z20.object({ id: z20.number(), html_url: z20.string() }).parse(response.body);
|
|
2876
3396
|
return {
|
|
2877
3397
|
target: "updateIssueComment",
|
|
2878
3398
|
repo: repo.ref,
|
|
@@ -2886,70 +3406,61 @@ function createGitHubUpdateIssueCommentTool(egress, botEmail) {
|
|
|
2886
3406
|
// src/tools/update-pull-request.ts
|
|
2887
3407
|
import {
|
|
2888
3408
|
definePluginTool as definePluginTool15,
|
|
2889
|
-
PluginToolInputError as
|
|
3409
|
+
PluginToolInputError as PluginToolInputError16,
|
|
2890
3410
|
pluginToolOutputSchema as pluginToolOutputSchema15
|
|
2891
3411
|
} from "@sentry/junior-plugin-api";
|
|
2892
|
-
import * as
|
|
3412
|
+
import * as z21 from "zod";
|
|
2893
3413
|
import { subscribableResourceSchema as subscribableResourceSchema9 } from "@sentry/junior-plugin-api";
|
|
2894
|
-
var inputSchema13 =
|
|
2895
|
-
repo:
|
|
2896
|
-
number:
|
|
2897
|
-
title:
|
|
2898
|
-
body:
|
|
3414
|
+
var inputSchema13 = z21.object({
|
|
3415
|
+
repo: z21.string().describe('Repository in "owner/name" format.'),
|
|
3416
|
+
number: z21.number().int().positive().describe("Pull request number."),
|
|
3417
|
+
title: z21.string().trim().min(1).optional().describe("Replacement pull request title."),
|
|
3418
|
+
body: z21.string().optional().describe(
|
|
2899
3419
|
"Replacement pull request body. The runtime appends requester attribution and the conversation footer."
|
|
2900
3420
|
),
|
|
2901
|
-
base:
|
|
2902
|
-
state:
|
|
2903
|
-
draft:
|
|
3421
|
+
base: z21.string().trim().min(1).optional().describe("Replacement base branch."),
|
|
3422
|
+
state: z21.enum(["open", "closed"]).optional().describe("Replacement pull request state."),
|
|
3423
|
+
draft: z21.boolean().optional().describe(
|
|
2904
3424
|
"Set false to mark a draft pull request ready for review, or true to convert it back to a draft."
|
|
2905
3425
|
)
|
|
2906
3426
|
}).strict().refine(
|
|
2907
3427
|
({ title, body, base, state, draft }) => title !== void 0 || body !== void 0 || base !== void 0 || state !== void 0 || draft !== void 0,
|
|
2908
3428
|
{ message: "At least one pull request field must be provided." }
|
|
2909
3429
|
);
|
|
2910
|
-
var
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
};
|
|
2914
|
-
var CONVERT_TO_DRAFT = {
|
|
2915
|
-
operationName: "ConvertPullRequestToDraft",
|
|
2916
|
-
query: "mutation ConvertPullRequestToDraft($id: ID!) { result: convertPullRequestToDraft(input: {pullRequestId: $id}) { pullRequest { isDraft } } }"
|
|
2917
|
-
};
|
|
2918
|
-
var draftMutationResponseSchema = z20.object({
|
|
2919
|
-
data: z20.object({
|
|
2920
|
-
result: z20.object({ pullRequest: z20.object({ isDraft: z20.boolean() }) })
|
|
3430
|
+
var draftMutationResponseSchema = z21.object({
|
|
3431
|
+
data: z21.object({
|
|
3432
|
+
result: z21.object({ pullRequest: z21.object({ isDraft: z21.boolean() }) })
|
|
2921
3433
|
})
|
|
2922
3434
|
});
|
|
2923
|
-
var pullRequestSchema2 =
|
|
2924
|
-
base:
|
|
2925
|
-
body:
|
|
2926
|
-
draft:
|
|
2927
|
-
number:
|
|
2928
|
-
state:
|
|
3435
|
+
var pullRequestSchema2 = z21.object({
|
|
3436
|
+
base: z21.string(),
|
|
3437
|
+
body: z21.string().nullable(),
|
|
3438
|
+
draft: z21.boolean(),
|
|
3439
|
+
number: z21.number(),
|
|
3440
|
+
state: z21.string(),
|
|
2929
3441
|
subscribable: subscribableResourceSchema9.optional(),
|
|
2930
|
-
title:
|
|
2931
|
-
url:
|
|
3442
|
+
title: z21.string(),
|
|
3443
|
+
url: z21.string()
|
|
2932
3444
|
});
|
|
2933
3445
|
var outputSchema13 = pluginToolOutputSchema15.merge(
|
|
2934
3446
|
pullRequestSchema2.extend({
|
|
2935
|
-
target:
|
|
3447
|
+
target: z21.literal("updatePullRequest")
|
|
2936
3448
|
})
|
|
2937
3449
|
);
|
|
2938
3450
|
function nonEmptyString5(value, name) {
|
|
2939
3451
|
if (!value?.trim()) {
|
|
2940
|
-
throw new
|
|
3452
|
+
throw new PluginToolInputError16(`${name} is required`);
|
|
2941
3453
|
}
|
|
2942
3454
|
return value.trim();
|
|
2943
3455
|
}
|
|
2944
3456
|
async function setPullRequestDraft(input) {
|
|
2945
|
-
const mutation = input.draft ?
|
|
3457
|
+
const mutation = input.draft ? CONVERT_PULL_REQUEST_TO_DRAFT : MARK_PULL_REQUEST_READY_FOR_REVIEW;
|
|
2946
3458
|
const response = await githubApi(input.egress, {
|
|
2947
3459
|
operation: `github.pull.draft.update:${input.repo.toLowerCase()}`,
|
|
2948
3460
|
method: "POST",
|
|
2949
3461
|
path: "/graphql",
|
|
2950
3462
|
body: {
|
|
2951
|
-
|
|
2952
|
-
query: mutation.query,
|
|
3463
|
+
...mutation,
|
|
2953
3464
|
variables: { id: input.nodeId }
|
|
2954
3465
|
}
|
|
2955
3466
|
});
|
|
@@ -2962,7 +3473,7 @@ async function setPullRequestDraft(input) {
|
|
|
2962
3473
|
}
|
|
2963
3474
|
return isDraft;
|
|
2964
3475
|
}
|
|
2965
|
-
function createGitHubUpdatePullRequestTool(ctx) {
|
|
3476
|
+
function createGitHubUpdatePullRequestTool(ctx, descriptionDecider) {
|
|
2966
3477
|
return definePluginTool15({
|
|
2967
3478
|
annotations: {
|
|
2968
3479
|
destructiveHint: true,
|
|
@@ -2976,12 +3487,15 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
2976
3487
|
async execute(input) {
|
|
2977
3488
|
const parsedInput = inputSchema13.safeParse(input);
|
|
2978
3489
|
if (!parsedInput.success) {
|
|
2979
|
-
throw new
|
|
3490
|
+
throw new PluginToolInputError16(
|
|
2980
3491
|
"Invalid GitHub updatePullRequest input.",
|
|
2981
3492
|
{ cause: parsedInput.error }
|
|
2982
3493
|
);
|
|
2983
3494
|
}
|
|
2984
3495
|
const update = parsedInput.data;
|
|
3496
|
+
if (descriptionDecider && update.body !== void 0) {
|
|
3497
|
+
await checkPullRequestDescription(descriptionDecider, update.body);
|
|
3498
|
+
}
|
|
2985
3499
|
const repo = parseRepo(update.repo);
|
|
2986
3500
|
const requester = await resolveGitHubRequester(ctx);
|
|
2987
3501
|
const currentBody = update.body !== void 0 ? await readGitHubBody(ctx.egress, {
|
|
@@ -3013,20 +3527,22 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
3013
3527
|
});
|
|
3014
3528
|
const parsed = response.body;
|
|
3015
3529
|
if (!response.ok) {
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3530
|
+
const message = `GitHub pull request update failed with HTTP ${response.status}: ${githubErrorMessage(parsed)}`;
|
|
3531
|
+
if (response.status === 404 || response.status === 422) {
|
|
3532
|
+
throw new PluginToolInputError16(message);
|
|
3533
|
+
}
|
|
3534
|
+
throw new Error(message);
|
|
3019
3535
|
}
|
|
3020
|
-
const providerResult =
|
|
3021
|
-
base:
|
|
3022
|
-
body:
|
|
3023
|
-
draft:
|
|
3024
|
-
html_url:
|
|
3025
|
-
merged:
|
|
3026
|
-
node_id:
|
|
3027
|
-
number:
|
|
3028
|
-
state:
|
|
3029
|
-
title:
|
|
3536
|
+
const providerResult = z21.object({
|
|
3537
|
+
base: z21.object({ ref: z21.string() }),
|
|
3538
|
+
body: z21.string().nullable().optional().default(null),
|
|
3539
|
+
draft: z21.boolean(),
|
|
3540
|
+
html_url: z21.string(),
|
|
3541
|
+
merged: z21.boolean(),
|
|
3542
|
+
node_id: z21.string().optional(),
|
|
3543
|
+
number: z21.number(),
|
|
3544
|
+
state: z21.string(),
|
|
3545
|
+
title: z21.string()
|
|
3030
3546
|
}).parse(parsed);
|
|
3031
3547
|
if (update.draft !== void 0 && update.draft !== providerResult.draft) {
|
|
3032
3548
|
if (!providerResult.node_id) {
|
|
@@ -3088,10 +3604,10 @@ function createGitHubUpdatePullRequestTool(ctx) {
|
|
|
3088
3604
|
// src/tools/update-pull-request-feedback.ts
|
|
3089
3605
|
import {
|
|
3090
3606
|
definePluginTool as definePluginTool16,
|
|
3091
|
-
PluginToolInputError as
|
|
3607
|
+
PluginToolInputError as PluginToolInputError17,
|
|
3092
3608
|
pluginToolOutputSchema as pluginToolOutputSchema16
|
|
3093
3609
|
} from "@sentry/junior-plugin-api";
|
|
3094
|
-
import * as
|
|
3610
|
+
import * as z22 from "zod";
|
|
3095
3611
|
var STATUS_TO_REACTION_CONTENT = {
|
|
3096
3612
|
reviewing: "eyes",
|
|
3097
3613
|
addressed: "+1",
|
|
@@ -3111,24 +3627,26 @@ var REST_REACTION_CONTENT = new Map(
|
|
|
3111
3627
|
rest
|
|
3112
3628
|
])
|
|
3113
3629
|
);
|
|
3114
|
-
var inputSchema14 =
|
|
3115
|
-
repo:
|
|
3116
|
-
comment_kind:
|
|
3117
|
-
'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment, "review_body" for the body of a submitted review.'
|
|
3630
|
+
var inputSchema14 = z22.object({
|
|
3631
|
+
repo: z22.string().describe('Repository in "owner/name" format.'),
|
|
3632
|
+
comment_kind: z22.enum(["conversation", "review", "review_body"]).describe(
|
|
3633
|
+
'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment, "review_body" for the body of a submitted review. Use the exact value from the event.'
|
|
3634
|
+
),
|
|
3635
|
+
comment_id: z22.number().int().positive().describe(
|
|
3636
|
+
"GitHub comment id (conversation comment id, inline review comment id, or review id). Use the exact value from the event."
|
|
3118
3637
|
),
|
|
3119
|
-
|
|
3120
|
-
"
|
|
3638
|
+
pull_request: z22.number().int().positive().describe(
|
|
3639
|
+
"Pull request number that the comment is on. Use the exact value from the event."
|
|
3121
3640
|
),
|
|
3122
|
-
|
|
3123
|
-
status: z21.enum(["addressed", "declined"]).describe(
|
|
3641
|
+
status: z22.enum(["addressed", "declined"]).describe(
|
|
3124
3642
|
"Feedback outcome. Maps to a reaction: addressed -> +1, declined -> -1."
|
|
3125
3643
|
)
|
|
3126
3644
|
}).strict();
|
|
3127
3645
|
var outputSchema14 = pluginToolOutputSchema16.extend({
|
|
3128
|
-
target:
|
|
3129
|
-
repo:
|
|
3130
|
-
comment_id:
|
|
3131
|
-
status:
|
|
3646
|
+
target: z22.literal("updatePullRequestFeedback"),
|
|
3647
|
+
repo: z22.string(),
|
|
3648
|
+
comment_id: z22.number(),
|
|
3649
|
+
status: z22.enum(["addressed", "declined"])
|
|
3132
3650
|
});
|
|
3133
3651
|
function pullRequestCommentPath(input) {
|
|
3134
3652
|
const segment = input.commentKind === "conversation" ? "issues" : "pulls";
|
|
@@ -3140,10 +3658,10 @@ function pullRequestCommentReactionsPath(input) {
|
|
|
3140
3658
|
function pullRequestFeedbackReactionContent(status) {
|
|
3141
3659
|
return STATUS_TO_REACTION_CONTENT[status];
|
|
3142
3660
|
}
|
|
3143
|
-
var reactionSchema =
|
|
3144
|
-
id:
|
|
3145
|
-
content:
|
|
3146
|
-
user:
|
|
3661
|
+
var reactionSchema = z22.object({
|
|
3662
|
+
id: z22.number(),
|
|
3663
|
+
content: z22.string(),
|
|
3664
|
+
user: z22.object({ id: z22.number() }).nullable()
|
|
3147
3665
|
});
|
|
3148
3666
|
async function commentParentNumber(egress, input) {
|
|
3149
3667
|
const commentResponse = await githubApi(egress, {
|
|
@@ -3153,25 +3671,25 @@ async function commentParentNumber(egress, input) {
|
|
|
3153
3671
|
const commentPayload = commentResponse.body;
|
|
3154
3672
|
if (!commentResponse.ok) {
|
|
3155
3673
|
const message = `GitHub comment lookup failed with HTTP ${commentResponse.status}: ${githubErrorMessage(commentPayload)}`;
|
|
3156
|
-
if (commentResponse.status === 404) throw new
|
|
3674
|
+
if (commentResponse.status === 404) throw new PluginToolInputError17(message);
|
|
3157
3675
|
throw new Error(message);
|
|
3158
3676
|
}
|
|
3159
|
-
const comment =
|
|
3160
|
-
issue_url:
|
|
3161
|
-
pull_request_url:
|
|
3677
|
+
const comment = z22.object({
|
|
3678
|
+
issue_url: z22.string().optional(),
|
|
3679
|
+
pull_request_url: z22.string().optional()
|
|
3162
3680
|
}).safeParse(commentPayload);
|
|
3163
3681
|
const parentUrl = comment.success ? input.commentKind === "conversation" ? comment.data.issue_url : comment.data.pull_request_url : void 0;
|
|
3164
|
-
const
|
|
3165
|
-
if (!
|
|
3682
|
+
const number33 = /\/(?:issues|pulls)\/(\d+)$/.exec(parentUrl ?? "")?.[1];
|
|
3683
|
+
if (!number33) {
|
|
3166
3684
|
throw new Error("GitHub comment did not name its issue or pull request.");
|
|
3167
3685
|
}
|
|
3168
|
-
return
|
|
3686
|
+
return number33;
|
|
3169
3687
|
}
|
|
3170
3688
|
async function assertBotAuthoredPullRequest(egress, input) {
|
|
3171
|
-
const { number:
|
|
3689
|
+
const { number: number33 } = input;
|
|
3172
3690
|
const pullResponse = await githubApi(egress, {
|
|
3173
3691
|
operation: "github.pull.get",
|
|
3174
|
-
path: `${repoPath(input)}/pulls/${
|
|
3692
|
+
path: `${repoPath(input)}/pulls/${number33}`
|
|
3175
3693
|
});
|
|
3176
3694
|
const pullPayload = pullResponse.body;
|
|
3177
3695
|
if (!pullResponse.ok && pullResponse.status !== 404) {
|
|
@@ -3179,9 +3697,9 @@ async function assertBotAuthoredPullRequest(egress, input) {
|
|
|
3179
3697
|
`GitHub pull request lookup failed with HTTP ${pullResponse.status}: ${githubErrorMessage(pullPayload)}`
|
|
3180
3698
|
);
|
|
3181
3699
|
}
|
|
3182
|
-
const pull =
|
|
3700
|
+
const pull = z22.object({ user: z22.object({ id: z22.number() }).nullable() }).safeParse(pullPayload);
|
|
3183
3701
|
if (!pullResponse.ok || !pull.success || pull.data.user?.id !== input.botUserId) {
|
|
3184
|
-
throw new
|
|
3702
|
+
throw new PluginToolInputError17(
|
|
3185
3703
|
"This bot can only set feedback status on comments on pull requests it authored."
|
|
3186
3704
|
);
|
|
3187
3705
|
}
|
|
@@ -3192,34 +3710,14 @@ function pullRequestReviewPath(input) {
|
|
|
3192
3710
|
function graphqlReactionContent(content) {
|
|
3193
3711
|
return GRAPHQL_REACTION_CONTENT[content] ?? content;
|
|
3194
3712
|
}
|
|
3195
|
-
var
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
}
|
|
3204
|
-
}`;
|
|
3205
|
-
var REVIEW_REACTIONS_QUERY = `query ReviewReactions($subjectId: ID!) {
|
|
3206
|
-
node(id: $subjectId) {
|
|
3207
|
-
... on PullRequestReview {
|
|
3208
|
-
reactionGroups {
|
|
3209
|
-
content
|
|
3210
|
-
reactors(first: 100) { nodes { ... on Bot { databaseId } } }
|
|
3211
|
-
}
|
|
3212
|
-
}
|
|
3213
|
-
}
|
|
3214
|
-
}`;
|
|
3215
|
-
var reviewReactionsSchema = z21.object({
|
|
3216
|
-
data: z21.object({
|
|
3217
|
-
node: z21.object({
|
|
3218
|
-
reactionGroups: z21.array(
|
|
3219
|
-
z21.object({
|
|
3220
|
-
content: z21.string(),
|
|
3221
|
-
reactors: z21.object({
|
|
3222
|
-
nodes: z21.array(z21.object({ databaseId: z21.number().optional() }))
|
|
3713
|
+
var reviewReactionsSchema = z22.object({
|
|
3714
|
+
data: z22.object({
|
|
3715
|
+
node: z22.object({
|
|
3716
|
+
reactionGroups: z22.array(
|
|
3717
|
+
z22.object({
|
|
3718
|
+
content: z22.string(),
|
|
3719
|
+
reactors: z22.object({
|
|
3720
|
+
nodes: z22.array(z22.object({ databaseId: z22.number().optional() }))
|
|
3223
3721
|
})
|
|
3224
3722
|
})
|
|
3225
3723
|
)
|
|
@@ -3229,7 +3727,7 @@ var reviewReactionsSchema = z21.object({
|
|
|
3229
3727
|
async function commentReactions(egress, input) {
|
|
3230
3728
|
const parentNumber = await commentParentNumber(egress, input);
|
|
3231
3729
|
if (parentNumber !== String(input.pullRequest)) {
|
|
3232
|
-
throw new
|
|
3730
|
+
throw new PluginToolInputError17(
|
|
3233
3731
|
`GitHub comment ${input.commentId} is not on pull request ${input.pullRequest}.`
|
|
3234
3732
|
);
|
|
3235
3733
|
}
|
|
@@ -3239,7 +3737,7 @@ async function commentReactions(egress, input) {
|
|
|
3239
3737
|
operation: "github.pull.comment-reaction.list",
|
|
3240
3738
|
path: `${path}?per_page=100`
|
|
3241
3739
|
}),
|
|
3242
|
-
botReactions: (body) =>
|
|
3740
|
+
botReactions: (body) => z22.array(reactionSchema).parse(body).filter((reaction) => reaction.user?.id === input.botUserId),
|
|
3243
3741
|
remove: (reaction) => githubApi(egress, {
|
|
3244
3742
|
operation: "github.pull.comment-reaction.delete",
|
|
3245
3743
|
method: "DELETE",
|
|
@@ -3260,24 +3758,21 @@ async function reviewBodyReactions(egress, input) {
|
|
|
3260
3758
|
});
|
|
3261
3759
|
if (!reviewResponse.ok) {
|
|
3262
3760
|
const message = `GitHub review lookup failed with HTTP ${reviewResponse.status}: ${githubErrorMessage(reviewResponse.body)}`;
|
|
3263
|
-
if (reviewResponse.status === 404) throw new
|
|
3761
|
+
if (reviewResponse.status === 404) throw new PluginToolInputError17(message);
|
|
3264
3762
|
throw new Error(message);
|
|
3265
3763
|
}
|
|
3266
|
-
const subjectId =
|
|
3267
|
-
const graphql = (
|
|
3268
|
-
operation,
|
|
3764
|
+
const subjectId = z22.object({ node_id: z22.string().min(1) }).parse(reviewResponse.body).node_id;
|
|
3765
|
+
const graphql = (operation2, document, variables) => githubApi(egress, {
|
|
3766
|
+
operation: operation2,
|
|
3269
3767
|
method: "POST",
|
|
3270
3768
|
path: "/graphql",
|
|
3271
|
-
body: {
|
|
3769
|
+
body: { ...document, variables }
|
|
3272
3770
|
});
|
|
3273
3771
|
const update = `github.pull.review-reaction.update:${input.owner}/${input.name}`.toLowerCase();
|
|
3274
3772
|
return {
|
|
3275
|
-
list: () => graphql(
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
REVIEW_REACTIONS_QUERY,
|
|
3279
|
-
{ subjectId }
|
|
3280
|
-
),
|
|
3773
|
+
list: () => graphql("github.pull.review-reaction.list", REVIEW_REACTIONS, {
|
|
3774
|
+
subjectId
|
|
3775
|
+
}),
|
|
3281
3776
|
botReactions: (body) => reviewReactionsSchema.parse(body).data.node.reactionGroups.filter(
|
|
3282
3777
|
(group) => group.reactors.nodes.some(
|
|
3283
3778
|
(reactor) => reactor.databaseId === input.botUserId
|
|
@@ -3285,11 +3780,11 @@ async function reviewBodyReactions(egress, input) {
|
|
|
3285
3780
|
).map((group) => ({
|
|
3286
3781
|
content: REST_REACTION_CONTENT.get(group.content) ?? group.content
|
|
3287
3782
|
})),
|
|
3288
|
-
remove: (reaction) => graphql(update,
|
|
3783
|
+
remove: (reaction) => graphql(update, REMOVE_REVIEW_REACTION, {
|
|
3289
3784
|
subjectId,
|
|
3290
3785
|
content: graphqlReactionContent(reaction.content)
|
|
3291
3786
|
}),
|
|
3292
|
-
add: (content) => graphql(update,
|
|
3787
|
+
add: (content) => graphql(update, ADD_REVIEW_REACTION, {
|
|
3293
3788
|
subjectId,
|
|
3294
3789
|
content: graphqlReactionContent(content)
|
|
3295
3790
|
})
|
|
@@ -3310,14 +3805,14 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3310
3805
|
openWorldHint: true,
|
|
3311
3806
|
readOnlyHint: false
|
|
3312
3807
|
},
|
|
3313
|
-
description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1).
|
|
3808
|
+
description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1). Call it after acting on the feedback. Replaces only your prior status reaction on that comment. Only works on pull requests the bot authored.",
|
|
3314
3809
|
exposure: "direct",
|
|
3315
3810
|
inputSchema: inputSchema14,
|
|
3316
3811
|
outputSchema: outputSchema14,
|
|
3317
3812
|
async execute(input) {
|
|
3318
3813
|
const parsedInput = inputSchema14.safeParse(input);
|
|
3319
3814
|
if (!parsedInput.success) {
|
|
3320
|
-
throw new
|
|
3815
|
+
throw new PluginToolInputError17(
|
|
3321
3816
|
"Invalid GitHub updatePullRequestFeedback input.",
|
|
3322
3817
|
{ cause: parsedInput.error }
|
|
3323
3818
|
);
|
|
@@ -3393,24 +3888,24 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3393
3888
|
// src/tools/resolve-pull-request-review-thread.ts
|
|
3394
3889
|
import {
|
|
3395
3890
|
definePluginTool as definePluginTool17,
|
|
3396
|
-
PluginToolInputError as
|
|
3891
|
+
PluginToolInputError as PluginToolInputError18,
|
|
3397
3892
|
pluginToolOutputSchema as pluginToolOutputSchema17
|
|
3398
3893
|
} from "@sentry/junior-plugin-api";
|
|
3399
|
-
import * as
|
|
3400
|
-
var inputSchema15 =
|
|
3401
|
-
repo:
|
|
3894
|
+
import * as z23 from "zod";
|
|
3895
|
+
var inputSchema15 = z23.object({
|
|
3896
|
+
repo: z23.string().describe(
|
|
3402
3897
|
'Repository in "owner/name" format. Required because GraphQL has no repo path.'
|
|
3403
3898
|
),
|
|
3404
|
-
thread_id:
|
|
3899
|
+
thread_id: z23.string().trim().min(1).describe(
|
|
3405
3900
|
"GitHub pull request review thread node ID (the `threadId` / `id` variable used by `gh api graphql` resolveReviewThread)."
|
|
3406
3901
|
)
|
|
3407
3902
|
}).strict();
|
|
3408
3903
|
var outputSchema15 = pluginToolOutputSchema17.extend({
|
|
3409
|
-
target:
|
|
3410
|
-
repo:
|
|
3411
|
-
number:
|
|
3412
|
-
thread_id:
|
|
3413
|
-
resolved:
|
|
3904
|
+
target: z23.literal("resolvePullRequestReviewThread"),
|
|
3905
|
+
repo: z23.string(),
|
|
3906
|
+
number: z23.number(),
|
|
3907
|
+
thread_id: z23.string(),
|
|
3908
|
+
resolved: z23.boolean()
|
|
3414
3909
|
});
|
|
3415
3910
|
function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
3416
3911
|
return definePluginTool17({
|
|
@@ -3431,7 +3926,7 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3431
3926
|
async execute(input) {
|
|
3432
3927
|
const parsedInput = inputSchema15.safeParse(input);
|
|
3433
3928
|
if (!parsedInput.success) {
|
|
3434
|
-
throw new
|
|
3929
|
+
throw new PluginToolInputError18(
|
|
3435
3930
|
"Invalid GitHub resolvePullRequestReviewThread input.",
|
|
3436
3931
|
{ cause: parsedInput.error }
|
|
3437
3932
|
);
|
|
@@ -3441,26 +3936,12 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3441
3936
|
if (botUserId === void 0) {
|
|
3442
3937
|
throw new Error("GitHub App bot identity is not configured.");
|
|
3443
3938
|
}
|
|
3444
|
-
const query = `query ReviewThreadOwnership($threadId: ID!) {
|
|
3445
|
-
node(id: $threadId) {
|
|
3446
|
-
... on PullRequestReviewThread {
|
|
3447
|
-
id
|
|
3448
|
-
isResolved
|
|
3449
|
-
pullRequest {
|
|
3450
|
-
number
|
|
3451
|
-
repository { nameWithOwner }
|
|
3452
|
-
author { ... on Bot { databaseId } }
|
|
3453
|
-
}
|
|
3454
|
-
}
|
|
3455
|
-
}
|
|
3456
|
-
}`;
|
|
3457
3939
|
const lookupResponse = await githubApi(ctx.egress, {
|
|
3458
3940
|
operation: "github.pull.review-thread.get",
|
|
3459
3941
|
method: "POST",
|
|
3460
3942
|
path: "/graphql",
|
|
3461
3943
|
body: {
|
|
3462
|
-
|
|
3463
|
-
query,
|
|
3944
|
+
...REVIEW_THREAD_OWNERSHIP,
|
|
3464
3945
|
variables: { threadId: parsedInput.data.thread_id }
|
|
3465
3946
|
}
|
|
3466
3947
|
});
|
|
@@ -3470,31 +3951,31 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3470
3951
|
`GitHub review thread lookup failed with HTTP ${lookupResponse.status}: ${githubErrorMessage(lookupPayload)}`
|
|
3471
3952
|
);
|
|
3472
3953
|
}
|
|
3473
|
-
const threadNodeSchema =
|
|
3474
|
-
id:
|
|
3475
|
-
isResolved:
|
|
3476
|
-
pullRequest:
|
|
3477
|
-
author:
|
|
3478
|
-
number:
|
|
3479
|
-
repository:
|
|
3954
|
+
const threadNodeSchema = z23.object({
|
|
3955
|
+
id: z23.string(),
|
|
3956
|
+
isResolved: z23.boolean(),
|
|
3957
|
+
pullRequest: z23.object({
|
|
3958
|
+
author: z23.object({ databaseId: z23.number().optional() }).passthrough().nullable(),
|
|
3959
|
+
number: z23.number(),
|
|
3960
|
+
repository: z23.object({ nameWithOwner: z23.string() }).passthrough()
|
|
3480
3961
|
}).passthrough()
|
|
3481
3962
|
}).passthrough();
|
|
3482
|
-
const lookupResultSchema =
|
|
3483
|
-
data:
|
|
3484
|
-
node:
|
|
3963
|
+
const lookupResultSchema = z23.object({
|
|
3964
|
+
data: z23.object({
|
|
3965
|
+
node: z23.unknown().nullable().optional()
|
|
3485
3966
|
}).passthrough()
|
|
3486
3967
|
}).passthrough();
|
|
3487
3968
|
const lookupResult = lookupResultSchema.safeParse(lookupPayload);
|
|
3488
3969
|
const rawNode = lookupResult.success ? lookupResult.data.data.node : void 0;
|
|
3489
3970
|
const parsedNode = rawNode == null ? void 0 : threadNodeSchema.safeParse(rawNode);
|
|
3490
3971
|
if (!parsedNode?.success) {
|
|
3491
|
-
throw new
|
|
3972
|
+
throw new PluginToolInputError18("GitHub review thread was not found.");
|
|
3492
3973
|
}
|
|
3493
3974
|
const thread = parsedNode.data;
|
|
3494
3975
|
const pullRequest = thread.pullRequest;
|
|
3495
3976
|
const ownsPullRequest = pullRequest.repository.nameWithOwner.toLowerCase() === repo.ref.toLowerCase() && pullRequest.author?.databaseId === botUserId;
|
|
3496
3977
|
if (!ownsPullRequest) {
|
|
3497
|
-
throw new
|
|
3978
|
+
throw new PluginToolInputError18(
|
|
3498
3979
|
"This bot can only resolve review threads on pull requests it authored."
|
|
3499
3980
|
);
|
|
3500
3981
|
}
|
|
@@ -3507,18 +3988,12 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3507
3988
|
resolved: true
|
|
3508
3989
|
};
|
|
3509
3990
|
}
|
|
3510
|
-
const mutation = `mutation ResolveReviewThread($threadId: ID!) {
|
|
3511
|
-
resolveReviewThread(input: {threadId: $threadId}) {
|
|
3512
|
-
thread { id isResolved }
|
|
3513
|
-
}
|
|
3514
|
-
}`;
|
|
3515
3991
|
const resolveResponse = await githubApi(ctx.egress, {
|
|
3516
3992
|
operation: `github.pull.review-thread.resolve:${repo.ref.toLowerCase()}`,
|
|
3517
3993
|
method: "POST",
|
|
3518
3994
|
path: "/graphql",
|
|
3519
3995
|
body: {
|
|
3520
|
-
|
|
3521
|
-
query: mutation,
|
|
3996
|
+
...RESOLVE_REVIEW_THREAD,
|
|
3522
3997
|
variables: { threadId: thread.id }
|
|
3523
3998
|
}
|
|
3524
3999
|
});
|
|
@@ -3528,10 +4003,10 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3528
4003
|
`GitHub review thread resolution failed with HTTP ${resolveResponse.status}: ${githubErrorMessage(resolvePayload)}`
|
|
3529
4004
|
);
|
|
3530
4005
|
}
|
|
3531
|
-
const resolveResultSchema =
|
|
3532
|
-
data:
|
|
3533
|
-
resolveReviewThread:
|
|
3534
|
-
thread:
|
|
4006
|
+
const resolveResultSchema = z23.object({
|
|
4007
|
+
data: z23.object({
|
|
4008
|
+
resolveReviewThread: z23.object({
|
|
4009
|
+
thread: z23.object({ id: z23.string(), isResolved: z23.boolean() }).passthrough()
|
|
3535
4010
|
}).passthrough()
|
|
3536
4011
|
}).passthrough()
|
|
3537
4012
|
}).passthrough();
|
|
@@ -3560,40 +4035,40 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
|
|
|
3560
4035
|
// src/tools/submit-pull-request-review.ts
|
|
3561
4036
|
import {
|
|
3562
4037
|
definePluginTool as definePluginTool18,
|
|
3563
|
-
PluginToolInputError as
|
|
4038
|
+
PluginToolInputError as PluginToolInputError19,
|
|
3564
4039
|
pluginToolOutputSchema as pluginToolOutputSchema18
|
|
3565
4040
|
} from "@sentry/junior-plugin-api";
|
|
3566
|
-
import * as
|
|
3567
|
-
var reviewCommentSchema =
|
|
3568
|
-
path:
|
|
3569
|
-
body:
|
|
3570
|
-
line:
|
|
3571
|
-
side:
|
|
3572
|
-
start_line:
|
|
3573
|
-
start_side:
|
|
4041
|
+
import * as z24 from "zod";
|
|
4042
|
+
var reviewCommentSchema = z24.object({
|
|
4043
|
+
path: z24.string().trim().min(1).describe("File path in the pull request."),
|
|
4044
|
+
body: z24.string().trim().min(1).describe("Inline review comment."),
|
|
4045
|
+
line: z24.number().int().positive().describe("Line in the pull request diff."),
|
|
4046
|
+
side: z24.enum(["LEFT", "RIGHT"]).describe("Side of the pull request diff."),
|
|
4047
|
+
start_line: z24.number().int().positive().optional().describe("First line of a multi-line comment."),
|
|
4048
|
+
start_side: z24.enum(["LEFT", "RIGHT"]).optional().describe("First side of a multi-line comment.")
|
|
3574
4049
|
}).strict().refine(
|
|
3575
4050
|
({ start_line, start_side }) => start_line === void 0 === (start_side === void 0),
|
|
3576
4051
|
{ message: "start_line and start_side must be provided together." }
|
|
3577
4052
|
);
|
|
3578
|
-
var inputSchema16 =
|
|
3579
|
-
repo:
|
|
3580
|
-
number:
|
|
3581
|
-
event:
|
|
3582
|
-
body:
|
|
3583
|
-
comments:
|
|
4053
|
+
var inputSchema16 = z24.object({
|
|
4054
|
+
repo: z24.string().describe('Repository in "owner/name" format.'),
|
|
4055
|
+
number: z24.number().int().positive().describe("Pull request number."),
|
|
4056
|
+
event: z24.enum(["COMMENT", "REQUEST_CHANGES"]).describe("Review result. You cannot approve pull requests."),
|
|
4057
|
+
body: z24.string().trim().min(1).describe("Review summary."),
|
|
4058
|
+
comments: z24.array(reviewCommentSchema).optional().describe("Optional inline review comments.")
|
|
3584
4059
|
}).strict();
|
|
3585
4060
|
var outputSchema16 = pluginToolOutputSchema18.extend({
|
|
3586
|
-
target:
|
|
3587
|
-
repo:
|
|
3588
|
-
number:
|
|
3589
|
-
review_id:
|
|
3590
|
-
state:
|
|
3591
|
-
url:
|
|
4061
|
+
target: z24.literal("submitPullRequestReview"),
|
|
4062
|
+
repo: z24.string(),
|
|
4063
|
+
number: z24.number(),
|
|
4064
|
+
review_id: z24.number(),
|
|
4065
|
+
state: z24.string(),
|
|
4066
|
+
url: z24.string()
|
|
3592
4067
|
});
|
|
3593
4068
|
function throwReviewError(status, body) {
|
|
3594
4069
|
const message = `GitHub pull request review failed with HTTP ${status}: ${githubErrorMessage(body)}`;
|
|
3595
4070
|
if (status === 404 || status === 422) {
|
|
3596
|
-
throw new
|
|
4071
|
+
throw new PluginToolInputError19(message);
|
|
3597
4072
|
}
|
|
3598
4073
|
throw new Error(message);
|
|
3599
4074
|
}
|
|
@@ -3631,7 +4106,7 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
3631
4106
|
if (!response.ok) {
|
|
3632
4107
|
throwReviewError(response.status, response.body);
|
|
3633
4108
|
}
|
|
3634
|
-
const providerResult =
|
|
4109
|
+
const providerResult = z24.object({ id: z24.number(), html_url: z24.string(), state: z24.string() }).parse(response.body);
|
|
3635
4110
|
return {
|
|
3636
4111
|
target: "submitPullRequestReview",
|
|
3637
4112
|
repo: repo.ref,
|
|
@@ -3646,7 +4121,8 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
3646
4121
|
}
|
|
3647
4122
|
|
|
3648
4123
|
// src/tools.ts
|
|
3649
|
-
function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
4124
|
+
function createGitHubTools(ctx, botEmail, pullRequestSubscription, experimental = {}) {
|
|
4125
|
+
const descriptionDecider = experimental.pullRequestDescriptionChecks ? ctx.decider : void 0;
|
|
3650
4126
|
return {
|
|
3651
4127
|
reactToIssue: createGitHubReactToIssueTool(ctx.egress),
|
|
3652
4128
|
cloneRepository: createGitHubCloneRepositoryTool(ctx),
|
|
@@ -3655,7 +4131,8 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
|
3655
4131
|
createIssue: createGitHubIssueTool(ctx),
|
|
3656
4132
|
createPullRequest: createGitHubPullRequestTool(
|
|
3657
4133
|
ctx,
|
|
3658
|
-
pullRequestSubscription
|
|
4134
|
+
pullRequestSubscription,
|
|
4135
|
+
descriptionDecider
|
|
3659
4136
|
),
|
|
3660
4137
|
getDeployment: createGitHubGetDeploymentTool(ctx),
|
|
3661
4138
|
getIssue: createGitHubGetIssueTool(ctx),
|
|
@@ -3672,7 +4149,10 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
|
3672
4149
|
ctx.egress,
|
|
3673
4150
|
botEmail
|
|
3674
4151
|
),
|
|
3675
|
-
updatePullRequest: createGitHubUpdatePullRequestTool(
|
|
4152
|
+
updatePullRequest: createGitHubUpdatePullRequestTool(
|
|
4153
|
+
ctx,
|
|
4154
|
+
descriptionDecider
|
|
4155
|
+
),
|
|
3676
4156
|
updatePullRequestFeedback: createGitHubUpdatePullRequestFeedbackTool(
|
|
3677
4157
|
ctx,
|
|
3678
4158
|
botEmail
|
|
@@ -3682,26 +4162,26 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
|
3682
4162
|
|
|
3683
4163
|
// src/webhooks/handler.ts
|
|
3684
4164
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
3685
|
-
import * as
|
|
4165
|
+
import * as z40 from "zod";
|
|
3686
4166
|
|
|
3687
4167
|
// src/issue-outcomes/store.ts
|
|
3688
4168
|
import { and as and2, eq as eq2, lte, sql as sql2 } from "drizzle-orm";
|
|
3689
|
-
import * as
|
|
3690
|
-
var githubIssueOutcomeInputSchema =
|
|
3691
|
-
candidateOwned:
|
|
3692
|
-
closedAt:
|
|
3693
|
-
issueId:
|
|
3694
|
-
number:
|
|
3695
|
-
openedAt:
|
|
3696
|
-
repositoryFullName:
|
|
3697
|
-
repositoryId:
|
|
4169
|
+
import * as z25 from "zod";
|
|
4170
|
+
var githubIssueOutcomeInputSchema = z25.object({
|
|
4171
|
+
candidateOwned: z25.boolean(),
|
|
4172
|
+
closedAt: z25.date().optional(),
|
|
4173
|
+
issueId: z25.string().min(1),
|
|
4174
|
+
number: z25.number().int().positive(),
|
|
4175
|
+
openedAt: z25.date(),
|
|
4176
|
+
repositoryFullName: z25.string().min(1),
|
|
4177
|
+
repositoryId: z25.string().min(1),
|
|
3698
4178
|
state: githubIssueStateSchema,
|
|
3699
4179
|
stateReason: githubIssueStateReasonSchema.optional(),
|
|
3700
|
-
updatedAt:
|
|
4180
|
+
updatedAt: z25.date()
|
|
3701
4181
|
}).strict();
|
|
3702
|
-
var githubIssueConversationsInputSchema =
|
|
3703
|
-
conversationIds:
|
|
3704
|
-
issueId:
|
|
4182
|
+
var githubIssueConversationsInputSchema = z25.object({
|
|
4183
|
+
conversationIds: z25.array(z25.string().min(1)).min(1),
|
|
4184
|
+
issueId: z25.string().min(1)
|
|
3705
4185
|
}).strict();
|
|
3706
4186
|
function projectionValues(input) {
|
|
3707
4187
|
return {
|
|
@@ -3765,38 +4245,41 @@ async function recordGitHubIssueConversations(db, input) {
|
|
|
3765
4245
|
|
|
3766
4246
|
// src/pull-request-outcomes/store.ts
|
|
3767
4247
|
import { and as and3, eq as eq3, lt as lt2, lte as lte2, ne, sql as sql3 } from "drizzle-orm";
|
|
3768
|
-
import * as
|
|
3769
|
-
var githubPullRequestOutcomeInputSchema =
|
|
3770
|
-
candidateOwned:
|
|
3771
|
-
closedAt:
|
|
4248
|
+
import * as z26 from "zod";
|
|
4249
|
+
var githubPullRequestOutcomeInputSchema = z26.object({
|
|
4250
|
+
candidateOwned: z26.boolean(),
|
|
4251
|
+
closedAt: z26.date().optional(),
|
|
3772
4252
|
commitComposition: githubPullRequestCommitCompositionSchema.optional(),
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
4253
|
+
/** When omitted, the stored draft state does not change. */
|
|
4254
|
+
draft: z26.boolean().optional(),
|
|
4255
|
+
mergedAt: z26.date().optional(),
|
|
4256
|
+
number: z26.number().int().positive(),
|
|
4257
|
+
openedAt: z26.date(),
|
|
4258
|
+
pullRequestId: z26.string().min(1),
|
|
4259
|
+
repositoryFullName: z26.string().min(1),
|
|
4260
|
+
repositoryId: z26.string().min(1),
|
|
3779
4261
|
state: githubPullRequestStateSchema,
|
|
3780
|
-
title:
|
|
3781
|
-
updatedAt:
|
|
4262
|
+
title: z26.string().min(1).optional(),
|
|
4263
|
+
updatedAt: z26.date()
|
|
3782
4264
|
}).strict();
|
|
3783
|
-
var githubPullRequestConversationsInputSchema =
|
|
3784
|
-
conversationIds:
|
|
3785
|
-
pullRequestId:
|
|
4265
|
+
var githubPullRequestConversationsInputSchema = z26.object({
|
|
4266
|
+
conversationIds: z26.array(z26.string().min(1)).min(1),
|
|
4267
|
+
pullRequestId: z26.string().min(1)
|
|
3786
4268
|
}).strict();
|
|
3787
|
-
var githubPullRequestLinkedIssuesInputSchema =
|
|
3788
|
-
linkedIssues:
|
|
3789
|
-
|
|
3790
|
-
number:
|
|
3791
|
-
repositoryFullName:
|
|
4269
|
+
var githubPullRequestLinkedIssuesInputSchema = z26.object({
|
|
4270
|
+
linkedIssues: z26.array(
|
|
4271
|
+
z26.object({
|
|
4272
|
+
number: z26.number().int().positive(),
|
|
4273
|
+
repositoryFullName: z26.string().min(1)
|
|
3792
4274
|
}).strict()
|
|
3793
4275
|
).min(1),
|
|
3794
|
-
pullRequestId:
|
|
4276
|
+
pullRequestId: z26.string().min(1)
|
|
3795
4277
|
}).strict();
|
|
3796
4278
|
function projectionValues2(input) {
|
|
3797
4279
|
return {
|
|
3798
4280
|
closedAt: input.closedAt ?? null,
|
|
3799
4281
|
...input.commitComposition ? { commitComposition: input.commitComposition } : void 0,
|
|
4282
|
+
...input.draft !== void 0 ? { draft: input.draft } : void 0,
|
|
3800
4283
|
mergedAt: input.mergedAt ?? null,
|
|
3801
4284
|
number: input.number,
|
|
3802
4285
|
openedAt: input.openedAt,
|
|
@@ -3903,7 +4386,12 @@ async function listGitHubFinishedWork(db, conversationIds) {
|
|
|
3903
4386
|
}
|
|
3904
4387
|
async function listGitHubStaleOpenPullRequests(db, before) {
|
|
3905
4388
|
const t = juniorGitHubPullRequests;
|
|
3906
|
-
return await db.select({
|
|
4389
|
+
return await db.select({
|
|
4390
|
+
draft: t.draft,
|
|
4391
|
+
number: t.number,
|
|
4392
|
+
repositoryFullName: t.repositoryFullName,
|
|
4393
|
+
repositoryId: t.repositoryId
|
|
4394
|
+
}).from(t).where(and3(eq3(t.state, "open"), lt2(t.updatedAt, before))).orderBy(t.updatedAt);
|
|
3907
4395
|
}
|
|
3908
4396
|
async function listGitHubAssignedWork(db, conversationIds) {
|
|
3909
4397
|
if (conversationIds.length === 0) return [];
|
|
@@ -3916,6 +4404,10 @@ async function listGitHubAssignedWork(db, conversationIds) {
|
|
|
3916
4404
|
);
|
|
3917
4405
|
return conversationIdsForPullRequests(rows, conversationIds);
|
|
3918
4406
|
}
|
|
4407
|
+
async function readGitHubPullRequestConversationIds(db, pullRequestId) {
|
|
4408
|
+
const [row] = await db.select({ conversationIds: juniorGitHubPullRequests.conversationIds }).from(juniorGitHubPullRequests).where(eq3(juniorGitHubPullRequests.pullRequestId, pullRequestId)).limit(1);
|
|
4409
|
+
return row?.conversationIds ?? [];
|
|
4410
|
+
}
|
|
3919
4411
|
async function recordGitHubPullRequestConversations(db, input) {
|
|
3920
4412
|
const association = githubPullRequestConversationsInputSchema.parse(input);
|
|
3921
4413
|
const conversationIds = sql3.join(
|
|
@@ -4004,6 +4496,7 @@ function githubCodeChange(outcome, conversationIds) {
|
|
|
4004
4496
|
return {
|
|
4005
4497
|
closedAt: outcome.closedAt,
|
|
4006
4498
|
conversationIds,
|
|
4499
|
+
draft: outcome.draft,
|
|
4007
4500
|
mergedAt: outcome.mergedAt,
|
|
4008
4501
|
number: outcome.number,
|
|
4009
4502
|
openedAt: outcome.openedAt,
|
|
@@ -4043,39 +4536,39 @@ async function applyGitHubPullRequestOutcome(args) {
|
|
|
4043
4536
|
}
|
|
4044
4537
|
|
|
4045
4538
|
// src/webhooks/issue-outcome.ts
|
|
4046
|
-
import * as
|
|
4047
|
-
var canonicalIssueOutcomeSchema =
|
|
4048
|
-
action:
|
|
4049
|
-
issue:
|
|
4050
|
-
body:
|
|
4051
|
-
closed_at:
|
|
4052
|
-
created_at:
|
|
4053
|
-
id:
|
|
4054
|
-
number:
|
|
4539
|
+
import * as z27 from "zod";
|
|
4540
|
+
var canonicalIssueOutcomeSchema = z27.object({
|
|
4541
|
+
action: z27.enum(["opened", "closed", "reopened"]),
|
|
4542
|
+
issue: z27.object({
|
|
4543
|
+
body: z27.string().nullable().optional(),
|
|
4544
|
+
closed_at: z27.string().nullable().optional(),
|
|
4545
|
+
created_at: z27.string(),
|
|
4546
|
+
id: z27.number().int().positive(),
|
|
4547
|
+
number: z27.number().int().positive(),
|
|
4055
4548
|
state_reason: githubIssueStateReasonSchema.nullable().optional(),
|
|
4056
|
-
updated_at:
|
|
4057
|
-
user:
|
|
4549
|
+
updated_at: z27.string(),
|
|
4550
|
+
user: z27.object({ login: z27.string().min(1) }).strict()
|
|
4058
4551
|
}).strict(),
|
|
4059
|
-
repository:
|
|
4060
|
-
full_name:
|
|
4061
|
-
id:
|
|
4552
|
+
repository: z27.object({
|
|
4553
|
+
full_name: z27.string().min(1),
|
|
4554
|
+
id: z27.number().int().positive()
|
|
4062
4555
|
}).strict()
|
|
4063
4556
|
}).strict();
|
|
4064
|
-
var issueOutcomeSchema =
|
|
4065
|
-
action:
|
|
4066
|
-
issue:
|
|
4067
|
-
body:
|
|
4068
|
-
closed_at:
|
|
4069
|
-
created_at:
|
|
4070
|
-
id:
|
|
4071
|
-
number:
|
|
4557
|
+
var issueOutcomeSchema = z27.object({
|
|
4558
|
+
action: z27.enum(["opened", "closed", "reopened"]),
|
|
4559
|
+
issue: z27.object({
|
|
4560
|
+
body: z27.string().nullable().optional(),
|
|
4561
|
+
closed_at: z27.string().nullable().optional(),
|
|
4562
|
+
created_at: z27.string(),
|
|
4563
|
+
id: z27.number().int().positive(),
|
|
4564
|
+
number: z27.number().int().positive(),
|
|
4072
4565
|
state_reason: githubIssueStateReasonSchema.nullable().optional(),
|
|
4073
|
-
updated_at:
|
|
4074
|
-
user:
|
|
4566
|
+
updated_at: z27.string(),
|
|
4567
|
+
user: z27.object({ login: z27.string().min(1) }).passthrough()
|
|
4075
4568
|
}).passthrough(),
|
|
4076
|
-
repository:
|
|
4077
|
-
full_name:
|
|
4078
|
-
id:
|
|
4569
|
+
repository: z27.object({
|
|
4570
|
+
full_name: z27.string().min(1),
|
|
4571
|
+
id: z27.number().int().positive()
|
|
4079
4572
|
}).passthrough()
|
|
4080
4573
|
}).passthrough().transform(
|
|
4081
4574
|
(provider) => canonicalIssueOutcomeSchema.parse({
|
|
@@ -4096,7 +4589,7 @@ var issueOutcomeSchema = z26.object({
|
|
|
4096
4589
|
}
|
|
4097
4590
|
})
|
|
4098
4591
|
);
|
|
4099
|
-
var issueLifecycleActionSchema =
|
|
4592
|
+
var issueLifecycleActionSchema = z27.object({ action: z27.string() }).passthrough();
|
|
4100
4593
|
function timestamp2(value) {
|
|
4101
4594
|
if (!value) return void 0;
|
|
4102
4595
|
const parsed = new Date(value);
|
|
@@ -4140,21 +4633,21 @@ function normalizeGitHubIssueOutcome(args) {
|
|
|
4140
4633
|
updatedAt
|
|
4141
4634
|
};
|
|
4142
4635
|
}
|
|
4143
|
-
var canonicalIssueConversationSchema =
|
|
4144
|
-
issue:
|
|
4145
|
-
body:
|
|
4146
|
-
id:
|
|
4147
|
-
user:
|
|
4636
|
+
var canonicalIssueConversationSchema = z27.object({
|
|
4637
|
+
issue: z27.object({
|
|
4638
|
+
body: z27.string().nullable().optional(),
|
|
4639
|
+
id: z27.number().int().positive(),
|
|
4640
|
+
user: z27.object({ login: z27.string().min(1) }).strict()
|
|
4148
4641
|
}).strict(),
|
|
4149
|
-
sender:
|
|
4642
|
+
sender: z27.object({ login: z27.string().min(1) }).strict().optional()
|
|
4150
4643
|
}).strict();
|
|
4151
|
-
var issueConversationSchema =
|
|
4152
|
-
issue:
|
|
4153
|
-
body:
|
|
4154
|
-
id:
|
|
4155
|
-
user:
|
|
4644
|
+
var issueConversationSchema = z27.object({
|
|
4645
|
+
issue: z27.object({
|
|
4646
|
+
body: z27.string().nullable().optional(),
|
|
4647
|
+
id: z27.number().int().positive(),
|
|
4648
|
+
user: z27.object({ login: z27.string().min(1) }).passthrough()
|
|
4156
4649
|
}).passthrough(),
|
|
4157
|
-
sender:
|
|
4650
|
+
sender: z27.object({ login: z27.string().min(1) }).passthrough().optional()
|
|
4158
4651
|
}).passthrough().transform(
|
|
4159
4652
|
(provider) => canonicalIssueConversationSchema.parse({
|
|
4160
4653
|
issue: {
|
|
@@ -4181,43 +4674,52 @@ function normalizeGitHubIssueConversations(args) {
|
|
|
4181
4674
|
}
|
|
4182
4675
|
|
|
4183
4676
|
// src/webhooks/pull-request-outcome.ts
|
|
4184
|
-
import * as
|
|
4185
|
-
var
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4677
|
+
import * as z28 from "zod";
|
|
4678
|
+
var pullRequestLifecycleActionsSchema = z28.enum([
|
|
4679
|
+
"opened",
|
|
4680
|
+
"closed",
|
|
4681
|
+
"reopened",
|
|
4682
|
+
"ready_for_review",
|
|
4683
|
+
"converted_to_draft"
|
|
4684
|
+
]);
|
|
4685
|
+
var canonicalPullRequestOutcomeSchema = z28.object({
|
|
4686
|
+
action: pullRequestLifecycleActionsSchema,
|
|
4687
|
+
pull_request: z28.object({
|
|
4688
|
+
body: z28.string().nullable().optional(),
|
|
4689
|
+
closed_at: z28.string().nullable().optional(),
|
|
4690
|
+
created_at: z28.string(),
|
|
4691
|
+
draft: z28.boolean().optional(),
|
|
4692
|
+
id: z28.number().int().positive(),
|
|
4693
|
+
merged: z28.boolean(),
|
|
4694
|
+
merged_at: z28.string().nullable().optional(),
|
|
4695
|
+
number: z28.number().int().positive(),
|
|
4696
|
+
title: z28.string().min(1).optional(),
|
|
4697
|
+
updated_at: z28.string(),
|
|
4698
|
+
user: z28.object({ login: z28.string().min(1) }).strict()
|
|
4198
4699
|
}).strict(),
|
|
4199
|
-
repository:
|
|
4200
|
-
full_name:
|
|
4201
|
-
id:
|
|
4700
|
+
repository: z28.object({
|
|
4701
|
+
full_name: z28.string().min(1),
|
|
4702
|
+
id: z28.number().int().positive()
|
|
4202
4703
|
}).strict()
|
|
4203
4704
|
}).strict();
|
|
4204
|
-
var pullRequestOutcomeSchema =
|
|
4205
|
-
action:
|
|
4206
|
-
pull_request:
|
|
4207
|
-
body:
|
|
4208
|
-
closed_at:
|
|
4209
|
-
created_at:
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4705
|
+
var pullRequestOutcomeSchema = z28.object({
|
|
4706
|
+
action: pullRequestLifecycleActionsSchema,
|
|
4707
|
+
pull_request: z28.object({
|
|
4708
|
+
body: z28.string().nullable().optional(),
|
|
4709
|
+
closed_at: z28.string().nullable().optional(),
|
|
4710
|
+
created_at: z28.string(),
|
|
4711
|
+
draft: z28.boolean().optional(),
|
|
4712
|
+
id: z28.number().int().positive(),
|
|
4713
|
+
merged: z28.boolean(),
|
|
4714
|
+
merged_at: z28.string().nullable().optional(),
|
|
4715
|
+
number: z28.number().int().positive(),
|
|
4716
|
+
title: z28.string().min(1).optional(),
|
|
4717
|
+
updated_at: z28.string(),
|
|
4718
|
+
user: z28.object({ login: z28.string().min(1) }).passthrough()
|
|
4217
4719
|
}).passthrough(),
|
|
4218
|
-
repository:
|
|
4219
|
-
full_name:
|
|
4220
|
-
id:
|
|
4720
|
+
repository: z28.object({
|
|
4721
|
+
full_name: z28.string().min(1),
|
|
4722
|
+
id: z28.number().int().positive()
|
|
4221
4723
|
}).passthrough()
|
|
4222
4724
|
}).passthrough().transform(
|
|
4223
4725
|
(provider) => canonicalPullRequestOutcomeSchema.parse({
|
|
@@ -4226,6 +4728,7 @@ var pullRequestOutcomeSchema = z27.object({
|
|
|
4226
4728
|
body: provider.pull_request.body,
|
|
4227
4729
|
closed_at: provider.pull_request.closed_at,
|
|
4228
4730
|
created_at: provider.pull_request.created_at,
|
|
4731
|
+
draft: provider.pull_request.draft,
|
|
4229
4732
|
id: provider.pull_request.id,
|
|
4230
4733
|
merged: provider.pull_request.merged,
|
|
4231
4734
|
merged_at: provider.pull_request.merged_at,
|
|
@@ -4240,24 +4743,24 @@ var pullRequestOutcomeSchema = z27.object({
|
|
|
4240
4743
|
}
|
|
4241
4744
|
})
|
|
4242
4745
|
);
|
|
4243
|
-
var pullRequestLifecycleActionSchema =
|
|
4244
|
-
var canonicalPullRequestConversationSchema =
|
|
4245
|
-
pull_request:
|
|
4246
|
-
body:
|
|
4247
|
-
id:
|
|
4248
|
-
user:
|
|
4746
|
+
var pullRequestLifecycleActionSchema = z28.object({ action: z28.string() }).passthrough();
|
|
4747
|
+
var canonicalPullRequestConversationSchema = z28.object({
|
|
4748
|
+
pull_request: z28.object({
|
|
4749
|
+
body: z28.string().nullable().optional(),
|
|
4750
|
+
id: z28.number().int().positive(),
|
|
4751
|
+
user: z28.object({ login: z28.string().min(1) }).strict()
|
|
4249
4752
|
}).strict(),
|
|
4250
|
-
repository:
|
|
4251
|
-
sender:
|
|
4753
|
+
repository: z28.object({ full_name: z28.string().min(1) }).strict(),
|
|
4754
|
+
sender: z28.object({ login: z28.string().min(1) }).strict()
|
|
4252
4755
|
}).strict();
|
|
4253
|
-
var pullRequestConversationSchema =
|
|
4254
|
-
pull_request:
|
|
4255
|
-
body:
|
|
4256
|
-
id:
|
|
4257
|
-
user:
|
|
4756
|
+
var pullRequestConversationSchema = z28.object({
|
|
4757
|
+
pull_request: z28.object({
|
|
4758
|
+
body: z28.string().nullable().optional(),
|
|
4759
|
+
id: z28.number().int().positive(),
|
|
4760
|
+
user: z28.object({ login: z28.string().min(1) }).passthrough()
|
|
4258
4761
|
}).passthrough(),
|
|
4259
|
-
repository:
|
|
4260
|
-
sender:
|
|
4762
|
+
repository: z28.object({ full_name: z28.string().min(1) }).passthrough(),
|
|
4763
|
+
sender: z28.object({ login: z28.string().min(1) }).passthrough()
|
|
4261
4764
|
}).passthrough().transform(
|
|
4262
4765
|
(provider) => canonicalPullRequestConversationSchema.parse({
|
|
4263
4766
|
pull_request: {
|
|
@@ -4276,7 +4779,7 @@ function timestamp3(value) {
|
|
|
4276
4779
|
}
|
|
4277
4780
|
function normalizeGitHubPullRequestOutcome(args) {
|
|
4278
4781
|
const lifecycle = pullRequestLifecycleActionSchema.safeParse(args.body);
|
|
4279
|
-
if (!lifecycle.success || !
|
|
4782
|
+
if (!lifecycle.success || !pullRequestLifecycleActionsSchema.safeParse(lifecycle.data.action).success) {
|
|
4280
4783
|
return void 0;
|
|
4281
4784
|
}
|
|
4282
4785
|
const parsed = pullRequestOutcomeSchema.parse(args.body);
|
|
@@ -4302,6 +4805,8 @@ function normalizeGitHubPullRequestOutcome(args) {
|
|
|
4302
4805
|
return {
|
|
4303
4806
|
candidateOwned,
|
|
4304
4807
|
closedAt,
|
|
4808
|
+
// A close keeps the stored draft state.
|
|
4809
|
+
draft: closed ? void 0 : pullRequest.draft,
|
|
4305
4810
|
mergedAt,
|
|
4306
4811
|
number: pullRequest.number,
|
|
4307
4812
|
openedAt,
|
|
@@ -4342,17 +4847,17 @@ function normalizeGitHubPullRequestLinkedIssues(args) {
|
|
|
4342
4847
|
}
|
|
4343
4848
|
|
|
4344
4849
|
// src/webhooks/pull-request-activity.ts
|
|
4345
|
-
import * as
|
|
4346
|
-
var timestampSchema =
|
|
4347
|
-
var numberSchema =
|
|
4348
|
-
var repositorySchema2 =
|
|
4349
|
-
var senderSchema =
|
|
4850
|
+
import * as z29 from "zod";
|
|
4851
|
+
var timestampSchema = z29.iso.datetime({ offset: true });
|
|
4852
|
+
var numberSchema = z29.number().int().positive();
|
|
4853
|
+
var repositorySchema2 = z29.object({ id: numberSchema });
|
|
4854
|
+
var senderSchema = z29.object({ type: z29.string() });
|
|
4350
4855
|
var activitySchemas = {
|
|
4351
|
-
issue_comment:
|
|
4352
|
-
action:
|
|
4353
|
-
comment:
|
|
4856
|
+
issue_comment: z29.object({
|
|
4857
|
+
action: z29.literal("created"),
|
|
4858
|
+
comment: z29.object({ created_at: timestampSchema }),
|
|
4354
4859
|
// Only comments on a pull request carry `issue.pull_request`.
|
|
4355
|
-
issue:
|
|
4860
|
+
issue: z29.object({ number: numberSchema, pull_request: z29.object({}) }),
|
|
4356
4861
|
repository: repositorySchema2,
|
|
4357
4862
|
sender: senderSchema
|
|
4358
4863
|
}).transform((event) => ({
|
|
@@ -4361,9 +4866,9 @@ var activitySchemas = {
|
|
|
4361
4866
|
repositoryProviderId: String(event.repository.id),
|
|
4362
4867
|
senderType: event.sender.type
|
|
4363
4868
|
})),
|
|
4364
|
-
pull_request:
|
|
4365
|
-
action:
|
|
4366
|
-
pull_request:
|
|
4869
|
+
pull_request: z29.object({
|
|
4870
|
+
action: z29.literal("synchronize"),
|
|
4871
|
+
pull_request: z29.object({
|
|
4367
4872
|
number: numberSchema,
|
|
4368
4873
|
updated_at: timestampSchema
|
|
4369
4874
|
}),
|
|
@@ -4375,11 +4880,11 @@ var activitySchemas = {
|
|
|
4375
4880
|
repositoryProviderId: String(event.repository.id),
|
|
4376
4881
|
senderType: event.sender.type
|
|
4377
4882
|
})),
|
|
4378
|
-
pull_request_review:
|
|
4379
|
-
action:
|
|
4380
|
-
pull_request:
|
|
4883
|
+
pull_request_review: z29.object({
|
|
4884
|
+
action: z29.literal("submitted"),
|
|
4885
|
+
pull_request: z29.object({ number: numberSchema }),
|
|
4381
4886
|
repository: repositorySchema2,
|
|
4382
|
-
review:
|
|
4887
|
+
review: z29.object({ submitted_at: timestampSchema }),
|
|
4383
4888
|
sender: senderSchema
|
|
4384
4889
|
}).transform((event) => ({
|
|
4385
4890
|
at: new Date(event.review.submitted_at),
|
|
@@ -4387,10 +4892,10 @@ var activitySchemas = {
|
|
|
4387
4892
|
repositoryProviderId: String(event.repository.id),
|
|
4388
4893
|
senderType: event.sender.type
|
|
4389
4894
|
})),
|
|
4390
|
-
pull_request_review_comment:
|
|
4391
|
-
action:
|
|
4392
|
-
comment:
|
|
4393
|
-
pull_request:
|
|
4895
|
+
pull_request_review_comment: z29.object({
|
|
4896
|
+
action: z29.literal("created"),
|
|
4897
|
+
comment: z29.object({ created_at: timestampSchema }),
|
|
4898
|
+
pull_request: z29.object({ number: numberSchema }),
|
|
4394
4899
|
repository: repositorySchema2,
|
|
4395
4900
|
sender: senderSchema
|
|
4396
4901
|
}).transform((event) => ({
|
|
@@ -4408,21 +4913,84 @@ function normalizeGitHubPullRequestActivity(input) {
|
|
|
4408
4913
|
return senderType === "Bot" ? void 0 : activity;
|
|
4409
4914
|
}
|
|
4410
4915
|
|
|
4916
|
+
// src/webhooks/pull-request-preview.ts
|
|
4917
|
+
import * as z30 from "zod";
|
|
4918
|
+
var previewWebhookSchema = z30.object({
|
|
4919
|
+
action: z30.enum(["opened", "edited", "synchronize", "ready_for_review"]),
|
|
4920
|
+
pull_request: z30.object({
|
|
4921
|
+
body: z30.string().nullable().optional(),
|
|
4922
|
+
id: z30.number().int().positive(),
|
|
4923
|
+
number: z30.number().int().positive(),
|
|
4924
|
+
updated_at: z30.iso.datetime({ offset: true })
|
|
4925
|
+
}),
|
|
4926
|
+
repository: z30.object({ full_name: z30.string().min(1) })
|
|
4927
|
+
});
|
|
4928
|
+
async function refreshGitHubPullRequestPreview(args) {
|
|
4929
|
+
const parsed = previewWebhookSchema.safeParse(args.body);
|
|
4930
|
+
if (!parsed.success) return;
|
|
4931
|
+
const { pull_request: pullRequest, repository: repository2 } = parsed.data;
|
|
4932
|
+
const conversationIds = await readGitHubPullRequestConversationIds(
|
|
4933
|
+
args.db,
|
|
4934
|
+
String(pullRequest.id)
|
|
4935
|
+
);
|
|
4936
|
+
if (conversationIds.length === 0) return;
|
|
4937
|
+
const key = `${repository2.full_name.toLowerCase()}#${pullRequest.number}`;
|
|
4938
|
+
const previewImageUrls = githubPreviewImageUrls(pullRequest.body);
|
|
4939
|
+
const updatedAt = Date.parse(pullRequest.updated_at);
|
|
4940
|
+
const results = await Promise.allSettled(
|
|
4941
|
+
conversationIds.map(async (conversationId) => {
|
|
4942
|
+
const store = args.annotations.forConversation(conversationId);
|
|
4943
|
+
const current = (await store.list()).find(
|
|
4944
|
+
(annotation2) => annotation2.key === key
|
|
4945
|
+
);
|
|
4946
|
+
if (current?.kind !== "object" || current.facts?.type !== "code_change") {
|
|
4947
|
+
return;
|
|
4948
|
+
}
|
|
4949
|
+
const storedAt = current.sourceUpdatedAt ? Date.parse(current.sourceUpdatedAt) : void 0;
|
|
4950
|
+
if (storedAt !== void 0 && storedAt > updatedAt) return;
|
|
4951
|
+
const {
|
|
4952
|
+
plugin: _plugin,
|
|
4953
|
+
createdAt: _createdAt,
|
|
4954
|
+
updatedAt: _updatedAt,
|
|
4955
|
+
facts: { previewImageUrls: previous, ...facts },
|
|
4956
|
+
...annotation
|
|
4957
|
+
} = current;
|
|
4958
|
+
const next = withGitHubPreviewImages(facts, previewImageUrls);
|
|
4959
|
+
if (previous?.join("\n") === next.previewImageUrls?.join("\n") && storedAt === updatedAt) {
|
|
4960
|
+
return;
|
|
4961
|
+
}
|
|
4962
|
+
await store.upsert({
|
|
4963
|
+
...annotation,
|
|
4964
|
+
facts: next,
|
|
4965
|
+
sourceUpdatedAt: pullRequest.updated_at
|
|
4966
|
+
});
|
|
4967
|
+
})
|
|
4968
|
+
);
|
|
4969
|
+
for (const result of results) {
|
|
4970
|
+
if (result.status === "fulfilled") continue;
|
|
4971
|
+
args.log?.error("GitHub pull request preview update failed", {
|
|
4972
|
+
errorType: result.reason instanceof Error ? result.reason.name : "UnknownError",
|
|
4973
|
+
number: pullRequest.number,
|
|
4974
|
+
repository: repository2.full_name
|
|
4975
|
+
});
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
|
|
4411
4979
|
// src/webhooks/merge-conflict.ts
|
|
4412
|
-
import * as
|
|
4980
|
+
import * as z31 from "zod";
|
|
4413
4981
|
var EVENT_TYPE = "pull_request.merge_conflict";
|
|
4414
4982
|
var CLOSED_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
4415
4983
|
"pull_request.closed_unmerged",
|
|
4416
4984
|
"pull_request.merged"
|
|
4417
4985
|
]);
|
|
4418
|
-
var pullRequestSchema3 =
|
|
4419
|
-
base:
|
|
4420
|
-
number:
|
|
4421
|
-
head:
|
|
4422
|
-
html_url:
|
|
4423
|
-
mergeable:
|
|
4424
|
-
mergeable_state:
|
|
4425
|
-
state:
|
|
4986
|
+
var pullRequestSchema3 = z31.object({
|
|
4987
|
+
base: z31.object({ ref: z31.string().min(1) }),
|
|
4988
|
+
number: z31.number().int().positive().optional(),
|
|
4989
|
+
head: z31.object({ sha: z31.string().min(1) }),
|
|
4990
|
+
html_url: z31.string().min(1).optional(),
|
|
4991
|
+
mergeable: z31.boolean().nullable().optional(),
|
|
4992
|
+
mergeable_state: z31.string().optional(),
|
|
4993
|
+
state: z31.string()
|
|
4426
4994
|
});
|
|
4427
4995
|
function gitHubMergeConflictEvents(input) {
|
|
4428
4996
|
const { conflict } = input;
|
|
@@ -4456,7 +5024,7 @@ function pullRequestRefs(events) {
|
|
|
4456
5024
|
return [...refs.values()];
|
|
4457
5025
|
}
|
|
4458
5026
|
function deliveredPullRequest(payload, ref) {
|
|
4459
|
-
const parsed =
|
|
5027
|
+
const parsed = z31.object({ pull_request: pullRequestSchema3 }).safeParse(payload);
|
|
4460
5028
|
const pullRequest = parsed.success ? parsed.data.pull_request : void 0;
|
|
4461
5029
|
return pullRequest?.number === ref.number && typeof pullRequest.mergeable === "boolean" ? pullRequest : void 0;
|
|
4462
5030
|
}
|
|
@@ -4482,28 +5050,32 @@ async function loadGitHubMergeConflictEvents(args) {
|
|
|
4482
5050
|
})
|
|
4483
5051
|
);
|
|
4484
5052
|
} catch (error) {
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
5053
|
+
logFailOpenFailure(
|
|
5054
|
+
args.log,
|
|
5055
|
+
"GitHub pull request merge conflict check failed",
|
|
5056
|
+
error,
|
|
5057
|
+
{
|
|
5058
|
+
deliveryId: args.deliveryId,
|
|
5059
|
+
pullRequest: ref.number,
|
|
5060
|
+
repository: ref.repositoryFullName
|
|
5061
|
+
}
|
|
5062
|
+
);
|
|
4491
5063
|
}
|
|
4492
5064
|
}
|
|
4493
5065
|
return conflicts;
|
|
4494
5066
|
}
|
|
4495
5067
|
|
|
4496
5068
|
// src/merge-conflict-checks/webhooks.ts
|
|
4497
|
-
import * as
|
|
5069
|
+
import * as z33 from "zod";
|
|
4498
5070
|
|
|
4499
5071
|
// src/merge-conflict-checks/store.ts
|
|
4500
5072
|
import { and as and4, eq as eq4 } from "drizzle-orm";
|
|
4501
|
-
import * as
|
|
5073
|
+
import * as z32 from "zod";
|
|
4502
5074
|
var CHECK_TTL_MS = 30 * 6e4;
|
|
4503
|
-
var repeatSchema =
|
|
5075
|
+
var repeatSchema = z32.object({
|
|
4504
5076
|
/** Checks since the last push that ended with an unknown answer. */
|
|
4505
|
-
attempts:
|
|
4506
|
-
dueAtMs:
|
|
5077
|
+
attempts: z32.number().int().positive(),
|
|
5078
|
+
dueAtMs: z32.number()
|
|
4507
5079
|
});
|
|
4508
5080
|
function pushKey(repositoryFullName) {
|
|
4509
5081
|
return `merge-conflict-check:push:${repositoryFullName}`;
|
|
@@ -4571,12 +5143,12 @@ async function settleGitHubConflictCheck(state, check, retryAtMs) {
|
|
|
4571
5143
|
|
|
4572
5144
|
// src/merge-conflict-checks/webhooks.ts
|
|
4573
5145
|
var CONFLICT_CHECK_DELAY_MS = 2 * 6e4;
|
|
4574
|
-
var pushSchema =
|
|
4575
|
-
deleted:
|
|
4576
|
-
ref:
|
|
4577
|
-
repository:
|
|
4578
|
-
default_branch:
|
|
4579
|
-
full_name:
|
|
5146
|
+
var pushSchema = z33.object({
|
|
5147
|
+
deleted: z33.boolean().optional(),
|
|
5148
|
+
ref: z33.string(),
|
|
5149
|
+
repository: z33.object({
|
|
5150
|
+
default_branch: z33.string().min(1),
|
|
5151
|
+
full_name: z33.string().min(1)
|
|
4580
5152
|
})
|
|
4581
5153
|
});
|
|
4582
5154
|
async function scheduleGitHubPushConflictCheck(args) {
|
|
@@ -4593,10 +5165,10 @@ async function scheduleGitHubPushConflictCheck(args) {
|
|
|
4593
5165
|
}
|
|
4594
5166
|
|
|
4595
5167
|
// src/webhooks/pull-request-ready.ts
|
|
4596
|
-
import * as
|
|
5168
|
+
import * as z35 from "zod";
|
|
4597
5169
|
|
|
4598
5170
|
// src/webhooks/installation-requests.ts
|
|
4599
|
-
import * as
|
|
5171
|
+
import * as z34 from "zod";
|
|
4600
5172
|
function splitRepository(fullName, label) {
|
|
4601
5173
|
const [owner, name, ...extra] = fullName.split("/");
|
|
4602
5174
|
if (!owner || !name || extra.length > 0) {
|
|
@@ -4636,28 +5208,46 @@ async function loadPullRequest(env, pullRequest) {
|
|
|
4636
5208
|
{ token: token.token }
|
|
4637
5209
|
);
|
|
4638
5210
|
}
|
|
5211
|
+
var GitHubRepositoryUnreachableError = class extends Error {
|
|
5212
|
+
constructor(repositoryId) {
|
|
5213
|
+
super(`GitHub repository ${repositoryId} is not reachable`);
|
|
5214
|
+
this.name = "GitHubRepositoryUnreachableError";
|
|
5215
|
+
}
|
|
5216
|
+
};
|
|
5217
|
+
var UNREACHABLE_REPOSITORY_MESSAGE = /does not exist or is not accessible/i;
|
|
4639
5218
|
async function loadPullRequestLifecycles(env, input) {
|
|
5219
|
+
let token;
|
|
5220
|
+
try {
|
|
5221
|
+
token = await issueInstallationToken({
|
|
5222
|
+
...env,
|
|
5223
|
+
permissions: { pull_requests: "read" },
|
|
5224
|
+
repositoryIds: [input.repositoryId]
|
|
5225
|
+
});
|
|
5226
|
+
} catch (error) {
|
|
5227
|
+
if (error instanceof GitHubRequestError && error.status === 422 && UNREACHABLE_REPOSITORY_MESSAGE.test(error.message)) {
|
|
5228
|
+
throw new GitHubRepositoryUnreachableError(input.repositoryId);
|
|
5229
|
+
}
|
|
5230
|
+
throw error;
|
|
5231
|
+
}
|
|
5232
|
+
const repository2 = z34.object({ full_name: z34.string().min(1) }).parse(
|
|
5233
|
+
await githubRequest(
|
|
5234
|
+
"https://api.github.com",
|
|
5235
|
+
`/repositories/${input.repositoryId}`,
|
|
5236
|
+
{ token: token.token }
|
|
5237
|
+
)
|
|
5238
|
+
);
|
|
4640
5239
|
const { owner, name } = splitRepository(
|
|
4641
|
-
|
|
5240
|
+
repository2.full_name,
|
|
4642
5241
|
"pull request lifecycle"
|
|
4643
5242
|
);
|
|
4644
|
-
const token = await issueInstallationToken({
|
|
4645
|
-
...env,
|
|
4646
|
-
permissions: { pull_requests: "read" },
|
|
4647
|
-
repositories: [name]
|
|
4648
|
-
});
|
|
4649
|
-
const variables = input.numbers.map((_, index2) => `$n${index2}: Int!`);
|
|
4650
|
-
const pullRequests = input.numbers.map(
|
|
4651
|
-
(_, index2) => `pr${index2}: pullRequest(number: $n${index2}) { ...lifecycle }`
|
|
4652
|
-
);
|
|
4653
5243
|
return await githubRequest("https://api.github.com", "/graphql", {
|
|
4654
5244
|
body: {
|
|
4655
|
-
|
|
5245
|
+
...pullRequestLifecycles(input.numbers.length),
|
|
4656
5246
|
variables: {
|
|
4657
5247
|
name,
|
|
4658
5248
|
owner,
|
|
4659
5249
|
...Object.fromEntries(
|
|
4660
|
-
input.numbers.map((
|
|
5250
|
+
input.numbers.map((number33, index2) => [`n${index2}`, number33])
|
|
4661
5251
|
)
|
|
4662
5252
|
}
|
|
4663
5253
|
},
|
|
@@ -4677,7 +5267,7 @@ async function searchOpenPullRequestMergeability(env, input) {
|
|
|
4677
5267
|
});
|
|
4678
5268
|
return await githubRequest("https://api.github.com", "/graphql", {
|
|
4679
5269
|
body: {
|
|
4680
|
-
|
|
5270
|
+
...OPEN_PULL_REQUEST_MERGEABILITY,
|
|
4681
5271
|
variables: {
|
|
4682
5272
|
after: input.after ?? null,
|
|
4683
5273
|
query: `repo:${input.repositoryFullName} is:pr is:open author:${input.author}`
|
|
@@ -4687,6 +5277,26 @@ async function searchOpenPullRequestMergeability(env, input) {
|
|
|
4687
5277
|
token: token.token
|
|
4688
5278
|
});
|
|
4689
5279
|
}
|
|
5280
|
+
async function requestPullRequestReviewers2(env, input) {
|
|
5281
|
+
const { owner, name } = splitRepository(
|
|
5282
|
+
input.repositoryFullName,
|
|
5283
|
+
"pull request review request"
|
|
5284
|
+
);
|
|
5285
|
+
const token = await issueInstallationToken({
|
|
5286
|
+
...env,
|
|
5287
|
+
permissions: { pull_requests: "write" },
|
|
5288
|
+
repositories: [name]
|
|
5289
|
+
});
|
|
5290
|
+
await githubRequest(
|
|
5291
|
+
"https://api.github.com",
|
|
5292
|
+
`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${input.number}/requested_reviewers`,
|
|
5293
|
+
{
|
|
5294
|
+
body: { reviewers: input.reviewers },
|
|
5295
|
+
method: "POST",
|
|
5296
|
+
token: token.token
|
|
5297
|
+
}
|
|
5298
|
+
);
|
|
5299
|
+
}
|
|
4690
5300
|
async function markPullRequestFeedbackReviewing(env, target) {
|
|
4691
5301
|
const { owner, name } = splitRepository(target.repo, "pull request feedback");
|
|
4692
5302
|
const token = await issueInstallationToken({
|
|
@@ -4695,7 +5305,7 @@ async function markPullRequestFeedbackReviewing(env, target) {
|
|
|
4695
5305
|
});
|
|
4696
5306
|
const content = pullRequestFeedbackReactionContent("reviewing");
|
|
4697
5307
|
if (target.commentKind === "review_body") {
|
|
4698
|
-
const review =
|
|
5308
|
+
const review = z34.object({ node_id: z34.string().min(1) }).parse(
|
|
4699
5309
|
await githubRequest(
|
|
4700
5310
|
"https://api.github.com",
|
|
4701
5311
|
pullRequestReviewPath({
|
|
@@ -4707,11 +5317,10 @@ async function markPullRequestFeedbackReviewing(env, target) {
|
|
|
4707
5317
|
{ token: token.token }
|
|
4708
5318
|
)
|
|
4709
5319
|
);
|
|
4710
|
-
const result =
|
|
5320
|
+
const result = z34.object({ errors: z34.array(z34.unknown()).optional() }).parse(
|
|
4711
5321
|
await githubRequest("https://api.github.com", "/graphql", {
|
|
4712
5322
|
body: {
|
|
4713
|
-
|
|
4714
|
-
query: ADD_REVIEW_REACTION_MUTATION,
|
|
5323
|
+
...ADD_REVIEW_REACTION,
|
|
4715
5324
|
variables: {
|
|
4716
5325
|
content: graphqlReactionContent(content),
|
|
4717
5326
|
subjectId: review.node_id
|
|
@@ -4743,9 +5352,9 @@ async function markPullRequestFeedbackReviewing(env, target) {
|
|
|
4743
5352
|
}
|
|
4744
5353
|
);
|
|
4745
5354
|
}
|
|
4746
|
-
var repositoryPermissionSchema =
|
|
4747
|
-
permission:
|
|
4748
|
-
role_name:
|
|
5355
|
+
var repositoryPermissionSchema = z34.object({
|
|
5356
|
+
permission: z34.string().min(1),
|
|
5357
|
+
role_name: z34.string().optional()
|
|
4749
5358
|
});
|
|
4750
5359
|
var REPOSITORY_ROLE_TTL_MS = 10 * 60 * 1e3;
|
|
4751
5360
|
async function loadRepositoryRole(env, cache, target) {
|
|
@@ -4775,19 +5384,19 @@ async function loadRepositoryRole(env, cache, target) {
|
|
|
4775
5384
|
}
|
|
4776
5385
|
);
|
|
4777
5386
|
}
|
|
4778
|
-
var pullRequestSchema4 =
|
|
4779
|
-
auto_merge:
|
|
4780
|
-
draft:
|
|
4781
|
-
html_url:
|
|
4782
|
-
mergeable_state:
|
|
4783
|
-
merged:
|
|
4784
|
-
state:
|
|
4785
|
-
title:
|
|
5387
|
+
var pullRequestSchema4 = z34.object({
|
|
5388
|
+
auto_merge: z34.object({}).nullable().optional(),
|
|
5389
|
+
draft: z34.boolean().optional(),
|
|
5390
|
+
html_url: z34.string().url(),
|
|
5391
|
+
mergeable_state: z34.string().nullable().optional(),
|
|
5392
|
+
merged: z34.boolean(),
|
|
5393
|
+
state: z34.enum(["open", "closed"]),
|
|
5394
|
+
title: z34.string()
|
|
4786
5395
|
});
|
|
4787
|
-
var reviewsSchema =
|
|
4788
|
-
|
|
4789
|
-
state:
|
|
4790
|
-
user:
|
|
5396
|
+
var reviewsSchema = z34.array(
|
|
5397
|
+
z34.object({
|
|
5398
|
+
state: z34.string(),
|
|
5399
|
+
user: z34.object({ login: z34.string() }).nullable()
|
|
4791
5400
|
})
|
|
4792
5401
|
);
|
|
4793
5402
|
async function loadPullRequestMergeState(env, pullRequest) {
|
|
@@ -4855,10 +5464,10 @@ var READY_ACTIONS = {
|
|
|
4855
5464
|
]),
|
|
4856
5465
|
pull_request_review: /* @__PURE__ */ new Set(["dismissed", "submitted"])
|
|
4857
5466
|
};
|
|
4858
|
-
var pullRequestWebhookSchema =
|
|
4859
|
-
action:
|
|
4860
|
-
pull_request:
|
|
4861
|
-
repository:
|
|
5467
|
+
var pullRequestWebhookSchema = z35.object({
|
|
5468
|
+
action: z35.string(),
|
|
5469
|
+
pull_request: z35.object({ number: z35.number().int().positive() }),
|
|
5470
|
+
repository: z35.object({ full_name: z35.string().min(1) })
|
|
4862
5471
|
});
|
|
4863
5472
|
function pullRequestReadyTargets(eventName, body) {
|
|
4864
5473
|
if (eventName === "check_suite") return checkSuitePullRequests(body);
|
|
@@ -4921,7 +5530,12 @@ async function syncOne(args, target) {
|
|
|
4921
5530
|
assigneeIdentityIds: [opener.identityId],
|
|
4922
5531
|
body: `**${state.title}** is approved, and GitHub says that it can merge: ${state.url}`,
|
|
4923
5532
|
dedupeKey,
|
|
4924
|
-
|
|
5533
|
+
// The number stays visible where a view shows only the subject.
|
|
5534
|
+
subject: {
|
|
5535
|
+
id: state.url,
|
|
5536
|
+
title: `${state.title} (#${target.number})`,
|
|
5537
|
+
url: state.url
|
|
5538
|
+
},
|
|
4925
5539
|
title: `Ready to merge \xB7 #${target.number}`,
|
|
4926
5540
|
waitsOnAssignees: true
|
|
4927
5541
|
});
|
|
@@ -4946,43 +5560,83 @@ async function syncGitHubPullRequestReadyNotices(args) {
|
|
|
4946
5560
|
try {
|
|
4947
5561
|
await syncOne(args, target);
|
|
4948
5562
|
} catch (error) {
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
5563
|
+
logFailOpenFailure(
|
|
5564
|
+
args.log,
|
|
5565
|
+
"GitHub pull request ready notice failed",
|
|
5566
|
+
error,
|
|
5567
|
+
{
|
|
5568
|
+
deliveryId: args.deliveryId,
|
|
5569
|
+
number: target.number,
|
|
5570
|
+
repository: target.repositoryFullName
|
|
5571
|
+
}
|
|
5572
|
+
);
|
|
4955
5573
|
}
|
|
4956
5574
|
}
|
|
4957
5575
|
}
|
|
4958
5576
|
|
|
5577
|
+
// src/webhooks/pull-request-ready-reviewers.ts
|
|
5578
|
+
import * as z36 from "zod";
|
|
5579
|
+
var readyForReviewSchema = z36.object({
|
|
5580
|
+
action: z36.literal("ready_for_review"),
|
|
5581
|
+
pull_request: z36.object({ number: z36.number().int().positive() }),
|
|
5582
|
+
repository: z36.object({ full_name: z36.string().min(1) })
|
|
5583
|
+
});
|
|
5584
|
+
async function requestGitHubReviewersWhenReady(args) {
|
|
5585
|
+
if (args.eventName !== "pull_request") return;
|
|
5586
|
+
const parsed = readyForReviewSchema.safeParse(args.body);
|
|
5587
|
+
if (!parsed.success) return;
|
|
5588
|
+
const target = {
|
|
5589
|
+
number: parsed.data.pull_request.number,
|
|
5590
|
+
repositoryFullName: parsed.data.repository.full_name
|
|
5591
|
+
};
|
|
5592
|
+
try {
|
|
5593
|
+
const opener = (await listGitHubPullRequestOpeners(args.db, {
|
|
5594
|
+
numbers: [target.number],
|
|
5595
|
+
repositoryFullName: target.repositoryFullName
|
|
5596
|
+
})).get(target.number);
|
|
5597
|
+
if (!opener?.conversationId) return;
|
|
5598
|
+
const named = await readGitHubDraftReviewers(args.state, target);
|
|
5599
|
+
const requester = named ? void 0 : await args.loadGitHubLogin?.(opener.identityId);
|
|
5600
|
+
const reviewers = named ?? (requester ? [requester] : []);
|
|
5601
|
+
if (reviewers.length === 0) return;
|
|
5602
|
+
await requestPullRequestReviewers2(args.env, { ...target, reviewers });
|
|
5603
|
+
} catch (error) {
|
|
5604
|
+
args.log?.warn("GitHub pull request review request failed", {
|
|
5605
|
+
deliveryId: args.deliveryId,
|
|
5606
|
+
errorType: error instanceof Error ? error.name : "UnknownError",
|
|
5607
|
+
number: target.number,
|
|
5608
|
+
repository: target.repositoryFullName
|
|
5609
|
+
});
|
|
5610
|
+
}
|
|
5611
|
+
}
|
|
5612
|
+
|
|
4959
5613
|
// src/webhooks/pull-request-review-request.ts
|
|
4960
|
-
import * as
|
|
4961
|
-
var login =
|
|
4962
|
-
var pullRequestEventSchema =
|
|
4963
|
-
action:
|
|
5614
|
+
import * as z37 from "zod";
|
|
5615
|
+
var login = z37.object({ login: z37.string().min(1) });
|
|
5616
|
+
var pullRequestEventSchema = z37.object({
|
|
5617
|
+
action: z37.enum([
|
|
4964
5618
|
"closed",
|
|
4965
5619
|
"reopened",
|
|
4966
5620
|
"review_request_removed",
|
|
4967
5621
|
"review_requested"
|
|
4968
5622
|
]),
|
|
4969
|
-
pull_request:
|
|
4970
|
-
html_url:
|
|
4971
|
-
merged:
|
|
4972
|
-
number:
|
|
5623
|
+
pull_request: z37.object({
|
|
5624
|
+
html_url: z37.string().url(),
|
|
5625
|
+
merged: z37.boolean().optional(),
|
|
5626
|
+
number: z37.number().int().positive(),
|
|
4973
5627
|
// The people whose review is still requested. Teams are listed apart.
|
|
4974
|
-
requested_reviewers:
|
|
4975
|
-
title:
|
|
5628
|
+
requested_reviewers: z37.array(login).optional(),
|
|
5629
|
+
title: z37.string()
|
|
4976
5630
|
}),
|
|
4977
|
-
repository:
|
|
5631
|
+
repository: z37.object({ full_name: z37.string().min(1) }),
|
|
4978
5632
|
// A team request has `requested_team` instead.
|
|
4979
5633
|
requested_reviewer: login.optional()
|
|
4980
5634
|
});
|
|
4981
|
-
var reviewEventSchema =
|
|
4982
|
-
action:
|
|
4983
|
-
pull_request:
|
|
4984
|
-
repository:
|
|
4985
|
-
review:
|
|
5635
|
+
var reviewEventSchema = z37.object({
|
|
5636
|
+
action: z37.literal("submitted"),
|
|
5637
|
+
pull_request: z37.object({ number: z37.number().int().positive() }),
|
|
5638
|
+
repository: z37.object({ full_name: z37.string().min(1) }),
|
|
5639
|
+
review: z37.object({ user: login })
|
|
4986
5640
|
});
|
|
4987
5641
|
function reviewRequestChange(eventName, body) {
|
|
4988
5642
|
if (eventName === "pull_request_review") {
|
|
@@ -5063,14 +5717,14 @@ function sameLogin(left, right) {
|
|
|
5063
5717
|
async function syncGitHubPullRequestReviewRequest(args) {
|
|
5064
5718
|
const parsed = reviewRequestChange(args.eventName, args.body);
|
|
5065
5719
|
if (!parsed) return;
|
|
5066
|
-
const { change, number:
|
|
5720
|
+
const { change, number: number33, repository: repository2 } = parsed;
|
|
5067
5721
|
try {
|
|
5068
5722
|
const opener = (await listGitHubPullRequestOpeners(args.db, {
|
|
5069
|
-
numbers: [
|
|
5723
|
+
numbers: [number33],
|
|
5070
5724
|
repositoryFullName: repository2
|
|
5071
|
-
})).get(
|
|
5725
|
+
})).get(number33);
|
|
5072
5726
|
if (!opener?.conversationId) return;
|
|
5073
|
-
const name = `${repository2}#${
|
|
5727
|
+
const name = `${repository2}#${number33}`;
|
|
5074
5728
|
const dedupeKey = `pull-request-review-requested:${name.toLowerCase()}`;
|
|
5075
5729
|
const items = args.reviewItems.forConversation(opener.conversationId);
|
|
5076
5730
|
const reviewers = change.kind === "requested" ? change.reviewers : change.reviewer === void 0 ? void 0 : [change.reviewer];
|
|
@@ -5092,22 +5746,27 @@ async function syncGitHubPullRequestReviewRequest(args) {
|
|
|
5092
5746
|
assigneeIdentityIds: [opener.identityId],
|
|
5093
5747
|
body: `GitHub asks you to review **${change.title}**: ${change.url}`,
|
|
5094
5748
|
dedupeKey,
|
|
5095
|
-
|
|
5096
|
-
|
|
5749
|
+
// The number stays visible where a view shows only the subject title.
|
|
5750
|
+
subject: {
|
|
5751
|
+
id: change.url,
|
|
5752
|
+
title: `${change.title} (#${number33})`,
|
|
5753
|
+
url: change.url
|
|
5754
|
+
},
|
|
5755
|
+
title: `Review requested \xB7 #${number33}`,
|
|
5097
5756
|
waitsOnAssignees: true
|
|
5098
5757
|
});
|
|
5099
5758
|
} catch (error) {
|
|
5100
5759
|
args.log?.error("GitHub pull request review request failed", {
|
|
5101
5760
|
deliveryId: args.deliveryId,
|
|
5102
5761
|
errorType: error instanceof Error ? error.name : "UnknownError",
|
|
5103
|
-
number:
|
|
5762
|
+
number: number33,
|
|
5104
5763
|
repository: repository2
|
|
5105
5764
|
});
|
|
5106
5765
|
}
|
|
5107
5766
|
}
|
|
5108
5767
|
|
|
5109
5768
|
// src/webhooks/pull-request-match-data.ts
|
|
5110
|
-
import * as
|
|
5769
|
+
import * as z38 from "zod";
|
|
5111
5770
|
var LOOKUPS_BY_MATCH_KEY = {
|
|
5112
5771
|
authors: ["authors"],
|
|
5113
5772
|
openerEmail: ["opener"],
|
|
@@ -5115,22 +5774,22 @@ var LOOKUPS_BY_MATCH_KEY = {
|
|
|
5115
5774
|
openerUsername: ["opener"]
|
|
5116
5775
|
};
|
|
5117
5776
|
var ALL_LOOKUPS = ["authors", "opener", "openerRole"];
|
|
5118
|
-
var lookupDataSchema =
|
|
5119
|
-
authors:
|
|
5120
|
-
openerRole:
|
|
5121
|
-
openerUsername:
|
|
5777
|
+
var lookupDataSchema = z38.object({
|
|
5778
|
+
authors: z38.array(z38.string().min(1)).min(1).optional(),
|
|
5779
|
+
openerRole: z38.string().min(1).optional(),
|
|
5780
|
+
openerUsername: z38.string().min(1).optional()
|
|
5122
5781
|
}).strict();
|
|
5123
5782
|
function lookupData(input) {
|
|
5124
5783
|
return lookupDataSchema.parse(definedValues(input));
|
|
5125
5784
|
}
|
|
5126
|
-
var webhookSchema =
|
|
5127
|
-
repository:
|
|
5785
|
+
var webhookSchema = z38.object({
|
|
5786
|
+
repository: z38.object({ full_name: z38.string().min(1) })
|
|
5128
5787
|
});
|
|
5129
5788
|
function pullRequestNumbers(events) {
|
|
5130
5789
|
const numbers = /* @__PURE__ */ new Map();
|
|
5131
5790
|
for (const event of events) {
|
|
5132
|
-
const
|
|
5133
|
-
if (typeof
|
|
5791
|
+
const number33 = event.data?.pullRequest;
|
|
5792
|
+
if (typeof number33 === "number") numbers.set(event.eventKey, number33);
|
|
5134
5793
|
}
|
|
5135
5794
|
return numbers;
|
|
5136
5795
|
}
|
|
@@ -5144,8 +5803,8 @@ function logFailure(context, lookup, error) {
|
|
|
5144
5803
|
}
|
|
5145
5804
|
async function withJuniorOpeners(context, events) {
|
|
5146
5805
|
const botNumber = (event) => {
|
|
5147
|
-
const
|
|
5148
|
-
return
|
|
5806
|
+
const number33 = context.numbers.get(event.eventKey);
|
|
5807
|
+
return number33 !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number33 : void 0;
|
|
5149
5808
|
};
|
|
5150
5809
|
const numbers = events.flatMap((event) => botNumber(event) ?? []);
|
|
5151
5810
|
if (numbers.length === 0) return events;
|
|
@@ -5164,9 +5823,9 @@ async function withJuniorOpeners(context, events) {
|
|
|
5164
5823
|
}
|
|
5165
5824
|
}
|
|
5166
5825
|
return events.map((event) => {
|
|
5167
|
-
const
|
|
5168
|
-
if (
|
|
5169
|
-
const identityId = openers.get(
|
|
5826
|
+
const number33 = botNumber(event);
|
|
5827
|
+
if (number33 === void 0) return event;
|
|
5828
|
+
const identityId = openers.get(number33)?.identityId;
|
|
5170
5829
|
const login2 = identityId ? logins.get(identityId) : void 0;
|
|
5171
5830
|
const {
|
|
5172
5831
|
openerEmail: _email,
|
|
@@ -5188,8 +5847,8 @@ async function withRolesAndAuthors(context, events, lookups) {
|
|
|
5188
5847
|
if (!loadRole && !loadAuthors) return events;
|
|
5189
5848
|
return await Promise.all(
|
|
5190
5849
|
events.map(async (event) => {
|
|
5191
|
-
const
|
|
5192
|
-
if (
|
|
5850
|
+
const number33 = context.numbers.get(event.eventKey);
|
|
5851
|
+
if (number33 === void 0) return event;
|
|
5193
5852
|
const login2 = event.data?.openerUsername;
|
|
5194
5853
|
if (loadRole && typeof login2 === "string" && !roles.has(login2)) {
|
|
5195
5854
|
roles.set(
|
|
@@ -5199,16 +5858,16 @@ async function withRolesAndAuthors(context, events, lookups) {
|
|
|
5199
5858
|
)
|
|
5200
5859
|
);
|
|
5201
5860
|
}
|
|
5202
|
-
if (loadAuthors && !authors.has(
|
|
5861
|
+
if (loadAuthors && !authors.has(number33)) {
|
|
5203
5862
|
authors.set(
|
|
5204
|
-
|
|
5205
|
-
loadAuthors({ number:
|
|
5863
|
+
number33,
|
|
5864
|
+
loadAuthors({ number: number33, repositoryFullName }).catch(
|
|
5206
5865
|
(error) => logFailure(context, "authors", error)
|
|
5207
5866
|
)
|
|
5208
5867
|
);
|
|
5209
5868
|
}
|
|
5210
5869
|
const role = loadRole && typeof login2 === "string" ? await roles.get(login2) : void 0;
|
|
5211
|
-
const logins = loadAuthors ? await authors.get(
|
|
5870
|
+
const logins = loadAuthors ? await authors.get(number33) : void 0;
|
|
5212
5871
|
if (!role && !logins?.length) return event;
|
|
5213
5872
|
return {
|
|
5214
5873
|
...event,
|
|
@@ -5265,7 +5924,7 @@ async function withGitHubPullRequestMatchData(args) {
|
|
|
5265
5924
|
}
|
|
5266
5925
|
|
|
5267
5926
|
// src/webhooks/pull-request-people.ts
|
|
5268
|
-
import * as
|
|
5927
|
+
import * as z39 from "zod";
|
|
5269
5928
|
var PEOPLE_EVENTS = /* @__PURE__ */ new Set([
|
|
5270
5929
|
"pull_request.review.approved",
|
|
5271
5930
|
"pull_request.merged"
|
|
@@ -5275,18 +5934,18 @@ var PAGE_SIZE = 100;
|
|
|
5275
5934
|
var MAX_PAGES = 3;
|
|
5276
5935
|
var CO_AUTHOR_TRAILER = /^co-authored-by:[^<\n]*<([^>\s]+@[^>\s]+)>\s*$/gim;
|
|
5277
5936
|
var GITHUB_NOREPLY_EMAIL = /^(?:\d+\+)?(?<login>[^@+]+)@users\.noreply\.github\.com$/i;
|
|
5278
|
-
var webhookSchema2 =
|
|
5279
|
-
pull_request:
|
|
5280
|
-
assignees:
|
|
5281
|
-
number:
|
|
5282
|
-
user:
|
|
5937
|
+
var webhookSchema2 = z39.object({
|
|
5938
|
+
pull_request: z39.object({
|
|
5939
|
+
assignees: z39.array(z39.object({ login: z39.string().min(1) })).nullish(),
|
|
5940
|
+
number: z39.number(),
|
|
5941
|
+
user: z39.object({ login: z39.string().min(1) }).nullish()
|
|
5283
5942
|
}),
|
|
5284
|
-
repository:
|
|
5943
|
+
repository: z39.object({ full_name: z39.string().min(1) })
|
|
5285
5944
|
});
|
|
5286
|
-
var commitPageSchema =
|
|
5287
|
-
|
|
5288
|
-
author:
|
|
5289
|
-
commit:
|
|
5945
|
+
var commitPageSchema = z39.array(
|
|
5946
|
+
z39.object({
|
|
5947
|
+
author: z39.object({ login: z39.string().min(1) }).nullish(),
|
|
5948
|
+
commit: z39.object({ message: z39.string() })
|
|
5290
5949
|
})
|
|
5291
5950
|
);
|
|
5292
5951
|
function shareCommitPages(load) {
|
|
@@ -5308,11 +5967,11 @@ function shareCommitPages(load) {
|
|
|
5308
5967
|
return await result;
|
|
5309
5968
|
};
|
|
5310
5969
|
}
|
|
5311
|
-
async function forEachCommit(loadPage,
|
|
5970
|
+
async function forEachCommit(loadPage, visit2) {
|
|
5312
5971
|
for (let page = 1; page <= MAX_PAGES; page += 1) {
|
|
5313
5972
|
const commits = commitPageSchema.parse(await loadPage(page, PAGE_SIZE));
|
|
5314
5973
|
for (const commit of commits) {
|
|
5315
|
-
|
|
5974
|
+
visit2({
|
|
5316
5975
|
coAuthorEmails: [
|
|
5317
5976
|
...commit.commit.message.matchAll(CO_AUTHOR_TRAILER)
|
|
5318
5977
|
].map((match) => match[1]),
|
|
@@ -5428,11 +6087,11 @@ function webhookInstallationId(body) {
|
|
|
5428
6087
|
}
|
|
5429
6088
|
return parseInstallationId(installation.id);
|
|
5430
6089
|
}
|
|
5431
|
-
var feedbackTargetSchema =
|
|
5432
|
-
commentId:
|
|
5433
|
-
commentKind:
|
|
5434
|
-
pullRequest:
|
|
5435
|
-
repo:
|
|
6090
|
+
var feedbackTargetSchema = z40.object({
|
|
6091
|
+
commentId: z40.number(),
|
|
6092
|
+
commentKind: z40.enum(["conversation", "review", "review_body"]),
|
|
6093
|
+
pullRequest: z40.number(),
|
|
6094
|
+
repo: z40.string().min(1)
|
|
5436
6095
|
});
|
|
5437
6096
|
function pullRequestFeedbackTarget(events) {
|
|
5438
6097
|
for (const event of events) {
|
|
@@ -5545,6 +6204,14 @@ function createGitHubWebhookRoute(args) {
|
|
|
5545
6204
|
providerId: pullRequestConversations.pullRequestId
|
|
5546
6205
|
});
|
|
5547
6206
|
}
|
|
6207
|
+
if (eventName === "pull_request") {
|
|
6208
|
+
await refreshGitHubPullRequestPreview({
|
|
6209
|
+
annotations: args.annotations,
|
|
6210
|
+
body,
|
|
6211
|
+
db: args.db,
|
|
6212
|
+
log: args.log
|
|
6213
|
+
});
|
|
6214
|
+
}
|
|
5548
6215
|
const pullRequestActivity = normalizeGitHubPullRequestActivity({
|
|
5549
6216
|
body,
|
|
5550
6217
|
eventName
|
|
@@ -5646,6 +6313,20 @@ function createGitHubWebhookRoute(args) {
|
|
|
5646
6313
|
reviewItems: args.reviewItems,
|
|
5647
6314
|
targets: pullRequestReadyTargets(eventName, body)
|
|
5648
6315
|
});
|
|
6316
|
+
await requestGitHubReviewersWhenReady({
|
|
6317
|
+
body,
|
|
6318
|
+
db: args.db,
|
|
6319
|
+
deliveryId,
|
|
6320
|
+
env: {
|
|
6321
|
+
appIdEnv: args.appIdEnv,
|
|
6322
|
+
installationIdEnv: args.installationIdEnv,
|
|
6323
|
+
privateKeyEnv: args.privateKeyEnv
|
|
6324
|
+
},
|
|
6325
|
+
eventName,
|
|
6326
|
+
loadGitHubLogin: args.loadGitHubLogin,
|
|
6327
|
+
log: args.log,
|
|
6328
|
+
state: args.state
|
|
6329
|
+
});
|
|
5649
6330
|
await syncGitHubPullRequestReviewRequest({
|
|
5650
6331
|
body,
|
|
5651
6332
|
db: args.db,
|
|
@@ -5664,30 +6345,30 @@ function createGitHubWebhookRoute(args) {
|
|
|
5664
6345
|
}
|
|
5665
6346
|
|
|
5666
6347
|
// src/merge-conflict-checks/heartbeat.ts
|
|
5667
|
-
import * as
|
|
6348
|
+
import * as z41 from "zod";
|
|
5668
6349
|
var CHECK_LIMIT = 10;
|
|
5669
6350
|
var MAX_PAGES2 = 5;
|
|
5670
6351
|
var CLAIM_MS = 5 * 6e4;
|
|
5671
6352
|
var UNKNOWN_RETRY_MS = 6e4;
|
|
5672
6353
|
var MAX_ATTEMPTS = 5;
|
|
5673
|
-
var searchNodeSchema =
|
|
5674
|
-
|
|
5675
|
-
baseRefName:
|
|
5676
|
-
headRefOid:
|
|
5677
|
-
mergeable:
|
|
5678
|
-
number:
|
|
5679
|
-
state:
|
|
5680
|
-
url:
|
|
6354
|
+
var searchNodeSchema = z41.union([
|
|
6355
|
+
z41.object({
|
|
6356
|
+
baseRefName: z41.string().min(1),
|
|
6357
|
+
headRefOid: z41.string().min(1),
|
|
6358
|
+
mergeable: z41.enum(["CONFLICTING", "MERGEABLE", "UNKNOWN"]),
|
|
6359
|
+
number: z41.number().int().positive(),
|
|
6360
|
+
state: z41.string(),
|
|
6361
|
+
url: z41.string().min(1)
|
|
5681
6362
|
}),
|
|
5682
|
-
|
|
6363
|
+
z41.object({}).strict()
|
|
5683
6364
|
]);
|
|
5684
|
-
var searchResponseSchema =
|
|
5685
|
-
data:
|
|
5686
|
-
search:
|
|
5687
|
-
nodes:
|
|
5688
|
-
pageInfo:
|
|
5689
|
-
endCursor:
|
|
5690
|
-
hasNextPage:
|
|
6365
|
+
var searchResponseSchema = z41.object({
|
|
6366
|
+
data: z41.object({
|
|
6367
|
+
search: z41.object({
|
|
6368
|
+
nodes: z41.array(searchNodeSchema.nullable()),
|
|
6369
|
+
pageInfo: z41.object({
|
|
6370
|
+
endCursor: z41.string().nullable(),
|
|
6371
|
+
hasNextPage: z41.boolean()
|
|
5691
6372
|
})
|
|
5692
6373
|
})
|
|
5693
6374
|
})
|
|
@@ -5761,40 +6442,40 @@ async function runGitHubConflictChecks(args) {
|
|
|
5761
6442
|
}
|
|
5762
6443
|
|
|
5763
6444
|
// src/pull-request-outcomes/reconcile.ts
|
|
5764
|
-
import * as
|
|
6445
|
+
import * as z42 from "zod";
|
|
5765
6446
|
var RECONCILE_MS = 24 * 60 * 6e4;
|
|
5766
6447
|
var REPOSITORY_LIMIT = 1;
|
|
5767
6448
|
var PULL_REQUESTS_PER_QUERY = 100;
|
|
5768
|
-
var lifecycleSchema =
|
|
5769
|
-
assignees:
|
|
5770
|
-
nodes:
|
|
6449
|
+
var lifecycleSchema = z42.object({
|
|
6450
|
+
assignees: z42.object({
|
|
6451
|
+
nodes: z42.array(z42.object({ login: z42.string().min(1) }).nullable())
|
|
5771
6452
|
}),
|
|
5772
6453
|
// GraphQL omits the `[bot]` suffix that REST and webhooks give an app.
|
|
5773
|
-
author:
|
|
5774
|
-
closedAt:
|
|
5775
|
-
createdAt:
|
|
5776
|
-
databaseId:
|
|
5777
|
-
headRefName:
|
|
5778
|
-
isDraft:
|
|
5779
|
-
merged:
|
|
5780
|
-
mergedAt:
|
|
5781
|
-
number:
|
|
5782
|
-
state:
|
|
5783
|
-
title:
|
|
5784
|
-
updatedAt:
|
|
6454
|
+
author: z42.object({ __typename: z42.string(), login: z42.string().min(1) }).nullable(),
|
|
6455
|
+
closedAt: z42.string().nullable(),
|
|
6456
|
+
createdAt: z42.string(),
|
|
6457
|
+
databaseId: z42.number().int().positive(),
|
|
6458
|
+
headRefName: z42.string(),
|
|
6459
|
+
isDraft: z42.boolean(),
|
|
6460
|
+
merged: z42.boolean(),
|
|
6461
|
+
mergedAt: z42.string().nullable(),
|
|
6462
|
+
number: z42.number().int().positive(),
|
|
6463
|
+
state: z42.enum(["OPEN", "CLOSED", "MERGED"]),
|
|
6464
|
+
title: z42.string(),
|
|
6465
|
+
updatedAt: z42.string()
|
|
5785
6466
|
});
|
|
5786
|
-
var lifecyclesResponseSchema =
|
|
5787
|
-
data:
|
|
5788
|
-
repository:
|
|
5789
|
-
databaseId:
|
|
5790
|
-
nameWithOwner:
|
|
6467
|
+
var lifecyclesResponseSchema = z42.object({
|
|
6468
|
+
data: z42.object({
|
|
6469
|
+
repository: z42.object({
|
|
6470
|
+
databaseId: z42.number().int().positive(),
|
|
6471
|
+
nameWithOwner: z42.string().min(1)
|
|
5791
6472
|
}).catchall(lifecycleSchema.nullable())
|
|
5792
6473
|
})
|
|
5793
6474
|
});
|
|
5794
|
-
function
|
|
6475
|
+
function webhookBody(action, repository2, pullRequest) {
|
|
5795
6476
|
const login2 = pullRequest.author?.login ?? "ghost";
|
|
5796
6477
|
return {
|
|
5797
|
-
action
|
|
6478
|
+
action,
|
|
5798
6479
|
pull_request: {
|
|
5799
6480
|
assignees: pullRequest.assignees.nodes.flatMap(
|
|
5800
6481
|
(assignee) => assignee ? [{ login: assignee.login }] : []
|
|
@@ -5819,17 +6500,65 @@ function closedWebhookBody(repository2, pullRequest) {
|
|
|
5819
6500
|
}
|
|
5820
6501
|
};
|
|
5821
6502
|
}
|
|
5822
|
-
async function
|
|
6503
|
+
async function reconcileDraft(args, repository2, pullRequest) {
|
|
6504
|
+
const outcome = normalizeGitHubPullRequestOutcome({
|
|
6505
|
+
body: webhookBody(
|
|
6506
|
+
pullRequest.isDraft ? "converted_to_draft" : "ready_for_review",
|
|
6507
|
+
repository2,
|
|
6508
|
+
pullRequest
|
|
6509
|
+
),
|
|
6510
|
+
botEmail: args.botEmail
|
|
6511
|
+
});
|
|
6512
|
+
if (!outcome) return;
|
|
6513
|
+
await applyGitHubPullRequestOutcome({
|
|
6514
|
+
annotations: args.annotations,
|
|
6515
|
+
codeChanges: args.codeChanges,
|
|
6516
|
+
db: args.db,
|
|
6517
|
+
log: args.log,
|
|
6518
|
+
outcome
|
|
6519
|
+
});
|
|
6520
|
+
}
|
|
6521
|
+
async function reconcileRepository(args, repositoryId, drafts) {
|
|
6522
|
+
const numbers = [...drafts.keys()];
|
|
5823
6523
|
for (let start = 0; start < numbers.length; start += PULL_REQUESTS_PER_QUERY) {
|
|
5824
6524
|
const { databaseId, nameWithOwner, ...pullRequests } = lifecyclesResponseSchema.parse(
|
|
5825
6525
|
await args.loadLifecycles({
|
|
5826
6526
|
numbers: numbers.slice(start, start + PULL_REQUESTS_PER_QUERY),
|
|
5827
|
-
|
|
6527
|
+
repositoryId
|
|
5828
6528
|
})
|
|
5829
6529
|
).data.repository;
|
|
5830
6530
|
for (const pullRequest of Object.values(pullRequests)) {
|
|
5831
|
-
if (!pullRequest
|
|
5832
|
-
|
|
6531
|
+
if (!pullRequest) continue;
|
|
6532
|
+
if (pullRequest.state === "OPEN") {
|
|
6533
|
+
if (pullRequest.isDraft !== drafts.get(pullRequest.number)) {
|
|
6534
|
+
await reconcileDraft(
|
|
6535
|
+
args,
|
|
6536
|
+
{ databaseId, nameWithOwner },
|
|
6537
|
+
pullRequest
|
|
6538
|
+
);
|
|
6539
|
+
continue;
|
|
6540
|
+
}
|
|
6541
|
+
await args.codeChanges.record(
|
|
6542
|
+
githubCodeChange(
|
|
6543
|
+
{
|
|
6544
|
+
candidateOwned: false,
|
|
6545
|
+
draft: pullRequest.isDraft,
|
|
6546
|
+
number: pullRequest.number,
|
|
6547
|
+
openedAt: new Date(pullRequest.createdAt),
|
|
6548
|
+
pullRequestId: String(pullRequest.databaseId),
|
|
6549
|
+
repositoryFullName: nameWithOwner,
|
|
6550
|
+
repositoryId: String(databaseId),
|
|
6551
|
+
state: "open",
|
|
6552
|
+
title: pullRequest.title,
|
|
6553
|
+
updatedAt: new Date(pullRequest.updatedAt)
|
|
6554
|
+
},
|
|
6555
|
+
[]
|
|
6556
|
+
)
|
|
6557
|
+
);
|
|
6558
|
+
continue;
|
|
6559
|
+
}
|
|
6560
|
+
const body = webhookBody(
|
|
6561
|
+
"closed",
|
|
5833
6562
|
{ databaseId, nameWithOwner },
|
|
5834
6563
|
pullRequest
|
|
5835
6564
|
);
|
|
@@ -5863,32 +6592,45 @@ async function reconcileRepository(args, repositoryFullName, numbers) {
|
|
|
5863
6592
|
}
|
|
5864
6593
|
}
|
|
5865
6594
|
async function reconcileGitHubPullRequests(args) {
|
|
5866
|
-
const
|
|
6595
|
+
const repositories = /* @__PURE__ */ new Map();
|
|
5867
6596
|
for (const row of await listGitHubStaleOpenPullRequests(
|
|
5868
6597
|
args.db,
|
|
5869
6598
|
new Date(args.nowMs - RECONCILE_MS)
|
|
5870
6599
|
)) {
|
|
5871
|
-
const
|
|
5872
|
-
|
|
5873
|
-
|
|
6600
|
+
const repository2 = repositories.get(row.repositoryId) ?? {
|
|
6601
|
+
drafts: /* @__PURE__ */ new Map(),
|
|
6602
|
+
name: row.repositoryFullName
|
|
6603
|
+
};
|
|
6604
|
+
repository2.drafts.set(row.number, row.draft);
|
|
6605
|
+
repositories.set(row.repositoryId, repository2);
|
|
5874
6606
|
}
|
|
5875
6607
|
let reconciled = 0;
|
|
5876
|
-
for (const [
|
|
6608
|
+
for (const [
|
|
6609
|
+
repositoryId,
|
|
6610
|
+
{ drafts, name: repositoryFullName }
|
|
6611
|
+
] of repositories) {
|
|
5877
6612
|
if (reconciled >= REPOSITORY_LIMIT) break;
|
|
5878
6613
|
const claimed = await args.state.setIfNotExists(
|
|
5879
|
-
`pull-request-reconcile:${
|
|
6614
|
+
`pull-request-reconcile:${repositoryId}`,
|
|
5880
6615
|
args.nowMs,
|
|
5881
6616
|
RECONCILE_MS
|
|
5882
6617
|
);
|
|
5883
6618
|
if (!claimed) continue;
|
|
5884
6619
|
reconciled += 1;
|
|
5885
6620
|
try {
|
|
5886
|
-
await reconcileRepository(args,
|
|
6621
|
+
await reconcileRepository(args, Number(repositoryId), drafts);
|
|
5887
6622
|
} catch (error) {
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
6623
|
+
if (error instanceof GitHubRepositoryUnreachableError) {
|
|
6624
|
+
args.log.warn("GitHub pull request reconcile skipped a repository", {
|
|
6625
|
+
repository: repositoryFullName,
|
|
6626
|
+
repositoryId
|
|
6627
|
+
});
|
|
6628
|
+
} else {
|
|
6629
|
+
args.log.error("GitHub pull request reconcile failed", {
|
|
6630
|
+
errorType: error instanceof Error ? error.name : "UnknownError",
|
|
6631
|
+
repository: repositoryFullName
|
|
6632
|
+
});
|
|
6633
|
+
}
|
|
5892
6634
|
}
|
|
5893
6635
|
}
|
|
5894
6636
|
}
|
|
@@ -5917,30 +6659,30 @@ function gitHubResourceUrl(input) {
|
|
|
5917
6659
|
if (input.resourceType === "repository") {
|
|
5918
6660
|
return `https://github.com/${input.identifier}`;
|
|
5919
6661
|
}
|
|
5920
|
-
const [repo,
|
|
5921
|
-
if (!repo || !
|
|
6662
|
+
const [repo, number33] = input.identifier.split("#");
|
|
6663
|
+
if (!repo || !number33) return void 0;
|
|
5922
6664
|
if (input.resourceType === "pull_request") {
|
|
5923
|
-
return `https://github.com/${repo}/pull/${
|
|
6665
|
+
return `https://github.com/${repo}/pull/${number33}`;
|
|
5924
6666
|
}
|
|
5925
6667
|
if (input.resourceType === "issue") {
|
|
5926
|
-
return `https://github.com/${repo}/issues/${
|
|
6668
|
+
return `https://github.com/${repo}/issues/${number33}`;
|
|
5927
6669
|
}
|
|
5928
6670
|
return void 0;
|
|
5929
6671
|
}
|
|
5930
6672
|
|
|
5931
6673
|
// src/pull-request-outcomes/commit-composition.ts
|
|
5932
|
-
import * as
|
|
5933
|
-
var canonicalCommitSchema =
|
|
5934
|
-
authorEmail:
|
|
5935
|
-
authorLogin:
|
|
6674
|
+
import * as z43 from "zod";
|
|
6675
|
+
var canonicalCommitSchema = z43.object({
|
|
6676
|
+
authorEmail: z43.string().nullable(),
|
|
6677
|
+
authorLogin: z43.string().nullable()
|
|
5936
6678
|
}).strict();
|
|
5937
|
-
var providerCommitSchema =
|
|
5938
|
-
author:
|
|
5939
|
-
commit:
|
|
5940
|
-
author:
|
|
6679
|
+
var providerCommitSchema = z43.object({
|
|
6680
|
+
author: z43.object({ login: z43.string() }).passthrough().nullable(),
|
|
6681
|
+
commit: z43.object({
|
|
6682
|
+
author: z43.object({ email: z43.string() }).passthrough().nullable()
|
|
5941
6683
|
}).passthrough()
|
|
5942
6684
|
}).passthrough();
|
|
5943
|
-
var commitPageSchema2 =
|
|
6685
|
+
var commitPageSchema2 = z43.array(providerCommitSchema).transform(
|
|
5944
6686
|
(commits) => commits.map(
|
|
5945
6687
|
(commit) => canonicalCommitSchema.parse({
|
|
5946
6688
|
authorEmail: commit.commit.author?.email ?? null,
|
|
@@ -6437,18 +7179,19 @@ function linkifyLine(line) {
|
|
|
6437
7179
|
continue;
|
|
6438
7180
|
}
|
|
6439
7181
|
if (line.startsWith("https://", index2) || line.startsWith("http://", index2)) {
|
|
6440
|
-
const
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
7182
|
+
const url = /^\S+/.exec(line.slice(index2))[0];
|
|
7183
|
+
const scheme = line.startsWith("https://", index2) ? 8 : 7;
|
|
7184
|
+
if (url.length > scheme) {
|
|
7185
|
+
output += url;
|
|
7186
|
+
index2 += url.length;
|
|
6444
7187
|
continue;
|
|
6445
7188
|
}
|
|
6446
7189
|
}
|
|
6447
7190
|
if (isReferenceBoundary(index2 === 0 ? void 0 : line[index2 - 1])) {
|
|
6448
7191
|
const match = GITHUB_ISSUE_REFERENCE_PATTERN.exec(line.slice(index2));
|
|
6449
7192
|
if (match) {
|
|
6450
|
-
const [reference, owner, repository2,
|
|
6451
|
-
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${
|
|
7193
|
+
const [reference, owner, repository2, number33] = match;
|
|
7194
|
+
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number33})`;
|
|
6452
7195
|
index2 += reference.length;
|
|
6453
7196
|
continue;
|
|
6454
7197
|
}
|
|
@@ -6590,9 +7333,9 @@ function parseGitHubReferences(text2, config) {
|
|
|
6590
7333
|
}
|
|
6591
7334
|
return [...references.values()];
|
|
6592
7335
|
}
|
|
6593
|
-
function objectTitle(kind,
|
|
6594
|
-
if (!isRecord(
|
|
6595
|
-
const raw = kind === "commit" ? isRecord(
|
|
7336
|
+
function objectTitle(kind, object43) {
|
|
7337
|
+
if (!isRecord(object43)) return void 0;
|
|
7338
|
+
const raw = kind === "commit" ? isRecord(object43.commit) && typeof object43.commit.message === "string" ? object43.commit.message.split("\n")[0] : void 0 : typeof object43.title === "string" ? object43.title : void 0;
|
|
6596
7339
|
return raw?.replace(/\s+/g, " ").trim() || void 0;
|
|
6597
7340
|
}
|
|
6598
7341
|
async function loadGitHubConversationTitleContext(args) {
|
|
@@ -6871,9 +7614,9 @@ import {
|
|
|
6871
7614
|
} from "@sentry/junior-plugin-api";
|
|
6872
7615
|
|
|
6873
7616
|
// src/default-branch.ts
|
|
6874
|
-
import * as
|
|
7617
|
+
import * as z44 from "zod";
|
|
6875
7618
|
var DEFAULT_BRANCH_TTL_MS = 10 * 60 * 1e3;
|
|
6876
|
-
var repositorySchema3 =
|
|
7619
|
+
var repositorySchema3 = z44.object({ default_branch: z44.string().min(1) });
|
|
6877
7620
|
async function loadDefaultBranch(env, cache, repository2) {
|
|
6878
7621
|
const { owner, name } = repository2;
|
|
6879
7622
|
return await cache.getOrLoad(
|
|
@@ -7057,7 +7800,10 @@ function githubErrorMessage2(bodyText) {
|
|
|
7057
7800
|
async function githubForbiddenPermissionDeniedMessage(ctx) {
|
|
7058
7801
|
const sso = ctx.response.headers.get("x-github-sso");
|
|
7059
7802
|
if (sso?.startsWith("required")) {
|
|
7060
|
-
const url = sso.
|
|
7803
|
+
const url = sso.split(";").map((part) => part.trim()).find((part) => part.startsWith("url="))?.slice("url=".length);
|
|
7804
|
+
if (url && URL.parse(url)?.origin !== "https://github.com") {
|
|
7805
|
+
return "GitHub requires SAML SSO authorization for this credential.";
|
|
7806
|
+
}
|
|
7061
7807
|
return `GitHub requires SAML SSO authorization for this credential.${url ? ` Authorize it at ${url}` : ""}`;
|
|
7062
7808
|
}
|
|
7063
7809
|
const message = githubErrorMessage2(
|
|
@@ -7088,8 +7834,8 @@ var ISSUE_PATH = /^\/repos\/[^/]+\/[^/]+\/issues\/\d+$/;
|
|
|
7088
7834
|
var ISSUE_READ_DENIAL = `Use github_getIssue to read a GitHub issue, not gh issue view or gh api. Read comments with gh api repos/OWNER/REPO/issues/NUMBER/comments. ${CREATE_TOOL_ROUTING_GUIDANCE}`;
|
|
7089
7835
|
function isGitHubIssueRead(input) {
|
|
7090
7836
|
if (isGitHubGraphqlUrl(input.upstreamUrl)) {
|
|
7091
|
-
const
|
|
7092
|
-
return
|
|
7837
|
+
const operation2 = input.method === "POST" ? githubGraphqlOperation(input.graphql) : void 0;
|
|
7838
|
+
return operation2?.fields.some(
|
|
7093
7839
|
(field) => (field.name === "issue" || field.name === "issueOrPullRequest") && field.arguments.length > 0
|
|
7094
7840
|
) ?? false;
|
|
7095
7841
|
}
|
|
@@ -7244,16 +7990,16 @@ var HOST_GRAPHQL_MUTATIONS = [
|
|
|
7244
7990
|
operationPrefix: "github.pull.review-reaction.update:"
|
|
7245
7991
|
}
|
|
7246
7992
|
];
|
|
7247
|
-
function hostGraphqlMutationRepository(
|
|
7248
|
-
if (method !== "POST" || !isGitHubGraphqlUrl(upstreamUrl) || !
|
|
7993
|
+
function hostGraphqlMutationRepository(operation2, method, upstreamUrl, graphql) {
|
|
7994
|
+
if (method !== "POST" || !isGitHubGraphqlUrl(upstreamUrl) || !operation2) {
|
|
7249
7995
|
return void 0;
|
|
7250
7996
|
}
|
|
7251
7997
|
const parsed = githubGraphqlOperation(graphql);
|
|
7252
7998
|
const mutation = HOST_GRAPHQL_MUTATIONS.find(
|
|
7253
|
-
(candidate) =>
|
|
7999
|
+
(candidate) => operation2.startsWith(candidate.operationPrefix) && parsed?.type === "mutation" && parsed.name === candidate.operationName && parsed.rootFields.length === 1 && parsed.rootFields[0] === candidate.field
|
|
7254
8000
|
);
|
|
7255
8001
|
if (!mutation) return void 0;
|
|
7256
|
-
const repository2 =
|
|
8002
|
+
const repository2 = operation2.slice(mutation.operationPrefix.length);
|
|
7257
8003
|
return /^[^/]+\/[^/]+$/.test(repository2) ? repository2 : void 0;
|
|
7258
8004
|
}
|
|
7259
8005
|
function isGitHubGraphqlMutation(method, upstreamUrl, graphql, field) {
|
|
@@ -7556,7 +8302,7 @@ function githubPlugin(options = {}) {
|
|
|
7556
8302
|
log: ctx.log,
|
|
7557
8303
|
text: ctx.text,
|
|
7558
8304
|
loadObject: async (reference) => {
|
|
7559
|
-
const { collection, operation } = {
|
|
8305
|
+
const { collection, operation: operation2 } = {
|
|
7560
8306
|
commit: {
|
|
7561
8307
|
collection: "commits",
|
|
7562
8308
|
operation: "github.commit.get"
|
|
@@ -7568,7 +8314,7 @@ function githubPlugin(options = {}) {
|
|
|
7568
8314
|
}
|
|
7569
8315
|
}[reference.kind];
|
|
7570
8316
|
const response = await githubApi(ctx.egress, {
|
|
7571
|
-
operation,
|
|
8317
|
+
operation: operation2,
|
|
7572
8318
|
path: `${repoPath(reference)}/${collection}/${encodeURIComponent(reference.id)}`,
|
|
7573
8319
|
signal: ctx.signal
|
|
7574
8320
|
});
|
|
@@ -7694,7 +8440,8 @@ function githubPlugin(options = {}) {
|
|
|
7694
8440
|
readEnv(botEmailEnv),
|
|
7695
8441
|
gitHubPullRequestSubscription(
|
|
7696
8442
|
options.pullRequestEvents?.subscribeAfterCreate
|
|
7697
|
-
)
|
|
8443
|
+
),
|
|
8444
|
+
options.experimental
|
|
7698
8445
|
);
|
|
7699
8446
|
},
|
|
7700
8447
|
workspacePrepare: prepareWorkspace,
|