@sentry/junior-github 0.311.0 → 0.313.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/{events-BxioaScB.js → events-mAaCafvx.js} +144 -34
- package/dist/index.js +449 -169
- package/dist/testing.js +1 -1
- package/migrations/0016_pull_request_finished_at.sql +3 -0
- package/migrations/0017_pull_request_lifecycle_copies.sql +5 -0
- package/migrations/meta/0016_snapshot.json +467 -0
- package/migrations/meta/0017_snapshot.json +418 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +5 -3
- package/skills/github-code/SKILL.md +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as GITHUB_DEPLOYMENT_EVENTS, A as requireEnv, B as GITHUB_RELEASE_MATCH_FIELDS, C as githubRepositoryFromUrl, Ct as githubErrorMessage$1, D as listVerifiedUserEmails, E as issueInstallationToken, F as GITHUB_REPOSITORY_EVENTS, G as GITHUB_PULL_REQUEST_IDENTIFIER, H as GITHUB_RELEASE_SUGGESTED_EVENTS, I as GITHUB_REPOSITORY_IDENTIFIER, J as gitHubPullRequestCreateWatch, K as GITHUB_PULL_REQUEST_MATCH_FIELDS, L as GITHUB_REPOSITORY_SUGGESTED_EVENTS, M as botLoginFromEmail, N as botUserIdFromEmail, O as normalizeScopeList, P as isBotLogin, Q as gitHubPullRequestSubscription, R as gitHubRepositorySubscribable, S as githubMessageSchema, St as githubAttachmentLocation, T as issueGitHubCredential, Tt as repoPath, U as gitHubReleaseSourceSubscribable, V as GITHUB_RELEASE_SOURCE_IDENTIFIER, W as GITHUB_PULL_REQUEST_EVENTS, X as gitHubPullRequestResource, Y as gitHubPullRequestEventGuidance, Z as gitHubPullRequestSubscribable, _t as readGitHubBody, a as needsCheckSuitePullRequestFacts, at as GITHUB_ISSUE_IDENTIFIER, b as USER_WRITE_REQUIREMENTS, bt as startedByPerson, c as definedValues, ct as gitHubIssueSubscribable, d as CREATE_TOOL_ROUTING_GUIDANCE, dt as normalizePermissions, et as GITHUB_DEPLOYMENT_MATCH_FIELDS, ft as readGrantPermissions, g as GITHUB_GRAPHQL_RESPONSE_BODY_LIMIT_BYTES, gt as parseGitHubLogin, h as GITHUB_AUTH_TOKEN_PLACEHOLDER, ht as linkedGitHubLogin, i as loadCheckSuiteFacts, it as GITHUB_ISSUE_EVENTS, j as resolveUserAccount, k as readEnv, l as pullRequestTargets, lt as watchGitHubIssue, m as GITHUB_AUTH_TOKEN_ENV, mt as assertGitHubPullRequestRequester, n as normalizeGitHubEvents, nt as GITHUB_DEPLOYMENT_SUGGESTED_EVENTS, o as parseCheckSuitePublishTargets, ot as GITHUB_ISSUE_MATCH_FIELDS, pt as appendGitHubRequesterAttribution, q as GITHUB_PULL_REQUEST_SUGGESTED_EVENTS, r as checkSuitePullRequests, rt as gitHubDeploymentSourceSubscribable, s as wantsCheckSuitePassed, st as GITHUB_ISSUE_SUGGESTED_EVENTS, t as gitHubPullRequestTerminalEvents, tt as GITHUB_DEPLOYMENT_SOURCE_IDENTIFIER, u as logFailOpenFailure, ut as gitHubRepoDataSchema, v as GitHubRequestError, vt as requesterPerson, w as githubRequest, wt as parseRepo$1, x as createPermissionCache, xt as githubApi, y as HTTP_READ_METHODS, yt as resolveGitHubRequester, z as GITHUB_RELEASE_EVENTS } from "./events-
|
|
1
|
+
import { $ as GITHUB_DEPLOYMENT_EVENTS, A as requireEnv, B as GITHUB_RELEASE_MATCH_FIELDS, C as githubRepositoryFromUrl, Ct as githubErrorMessage$1, D as listVerifiedUserEmails, E as issueInstallationToken, F as GITHUB_REPOSITORY_EVENTS, G as GITHUB_PULL_REQUEST_IDENTIFIER, H as GITHUB_RELEASE_SUGGESTED_EVENTS, I as GITHUB_REPOSITORY_IDENTIFIER, J as gitHubPullRequestCreateWatch, K as GITHUB_PULL_REQUEST_MATCH_FIELDS, L as GITHUB_REPOSITORY_SUGGESTED_EVENTS, M as botLoginFromEmail, N as botUserIdFromEmail, O as normalizeScopeList, P as isBotLogin, Q as gitHubPullRequestSubscription, R as gitHubRepositorySubscribable, S as githubMessageSchema, St as githubAttachmentLocation, T as issueGitHubCredential, Tt as repoPath, U as gitHubReleaseSourceSubscribable, V as GITHUB_RELEASE_SOURCE_IDENTIFIER, W as GITHUB_PULL_REQUEST_EVENTS, X as gitHubPullRequestResource, Y as gitHubPullRequestEventGuidance, Z as gitHubPullRequestSubscribable, _t as readGitHubBody, a as needsCheckSuitePullRequestFacts, at as GITHUB_ISSUE_IDENTIFIER, b as USER_WRITE_REQUIREMENTS, bt as startedByPerson, c as definedValues, ct as gitHubIssueSubscribable, d as CREATE_TOOL_ROUTING_GUIDANCE, dt as normalizePermissions, et as GITHUB_DEPLOYMENT_MATCH_FIELDS, ft as readGrantPermissions, g as GITHUB_GRAPHQL_RESPONSE_BODY_LIMIT_BYTES, gt as parseGitHubLogin, h as GITHUB_AUTH_TOKEN_PLACEHOLDER, ht as linkedGitHubLogin, i as loadCheckSuiteFacts, it as GITHUB_ISSUE_EVENTS, j as resolveUserAccount, k as readEnv, l as pullRequestTargets, lt as watchGitHubIssue, m as GITHUB_AUTH_TOKEN_ENV, mt as assertGitHubPullRequestRequester, n as normalizeGitHubEvents, nt as GITHUB_DEPLOYMENT_SUGGESTED_EVENTS, o as parseCheckSuitePublishTargets, ot as GITHUB_ISSUE_MATCH_FIELDS, pt as appendGitHubRequesterAttribution, q as GITHUB_PULL_REQUEST_SUGGESTED_EVENTS, r as checkSuitePullRequests, rt as gitHubDeploymentSourceSubscribable, s as wantsCheckSuitePassed, st as GITHUB_ISSUE_SUGGESTED_EVENTS, t as gitHubPullRequestTerminalEvents, tt as GITHUB_DEPLOYMENT_SOURCE_IDENTIFIER, u as logFailOpenFailure, ut as gitHubRepoDataSchema, v as GitHubRequestError, vt as requesterPerson, w as githubRequest, wt as parseRepo$1, x as createPermissionCache, xt as githubApi, y as HTTP_READ_METHODS, yt as resolveGitHubRequester, z as GITHUB_RELEASE_EVENTS } from "./events-mAaCafvx.js";
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
import pLimit from "p-limit";
|
|
4
4
|
import { EgressAuthRequired, EgressPolicyDenied, OBJECT_FACTS_MAX_BYTES, PluginToolInputError, codeChangeSizeSchema, decodeObjectImageRef, defineJuniorPlugin, definePluginTool, enforceEgressPolicy, mergeEventMatchFields, objectFactsBytes, objectFactsMatchType, objectFactsSchema, parseShellCommands, pluginToolOutputSchema, subscribableResourceSchema, watchResultSchema } from "@sentry/junior-plugin-api";
|
|
@@ -7,10 +7,12 @@ import { parseFragment } from "parse5";
|
|
|
7
7
|
import { Type } from "@sinclair/typebox";
|
|
8
8
|
import { Value } from "@sinclair/typebox/value";
|
|
9
9
|
import { and, asc, eq, inArray, lt, lte, ne, sql } from "drizzle-orm";
|
|
10
|
-
import {
|
|
10
|
+
import { index, integer, jsonb, pgTable, primaryKey, text, timestamp as timestamp$2 } from "drizzle-orm/pg-core";
|
|
11
11
|
import ignore from "ignore";
|
|
12
12
|
import { Kind, parse, print, visit } from "@0no-co/graphql.web";
|
|
13
13
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
14
|
+
import { RE2JS } from "re2js";
|
|
15
|
+
import { parse as parse$1 } from "yaml";
|
|
14
16
|
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
15
17
|
import { gfmFromMarkdown } from "mdast-util-gfm";
|
|
16
18
|
import { gfm } from "micromark-extension-gfm";
|
|
@@ -826,7 +828,7 @@ const gitHubCommentOnPullRequestTool = definePluginTool({
|
|
|
826
828
|
};
|
|
827
829
|
}
|
|
828
830
|
});
|
|
829
|
-
// src/
|
|
831
|
+
// src/conversation-footer.ts
|
|
830
832
|
const GITHUB_SESSION_FOOTER_START = "<!-- junior-session-footer:start -->";
|
|
831
833
|
const GITHUB_SESSION_FOOTER_END = "<!-- junior-session-footer:end -->";
|
|
832
834
|
const GITHUB_CONVERSATION_ID_MARKER = "junior-conversation-id:";
|
|
@@ -954,11 +956,11 @@ const gitHubIssueDataSchema = z.object({
|
|
|
954
956
|
const gitHubIssueOutputSchema = pluginToolOutputSchema.merge(gitHubIssueDataSchema.extend({ target: z.literal("createIssue") }));
|
|
955
957
|
/**
|
|
956
958
|
* Next step after an issue is created. Whether Junior does the work is the
|
|
957
|
-
* requester's decision, so the note asks for
|
|
959
|
+
* requester's decision, so the note asks for an Inbox item. Only a Turn that
|
|
958
960
|
* a person started gets it: no one can answer the item in other runs.
|
|
959
961
|
*/
|
|
960
962
|
function implementIssueNote(issue) {
|
|
961
|
-
return `Unless the requester already asked you to fix ${issue}, ask whether to: the choice is theirs, even if they asked only for the issue. Use
|
|
963
|
+
return `Unless the requester already asked you to fix ${issue}, ask whether to: the choice is theirs, even if they asked only for the issue. Use addInboxItem: question "Start a Thread to implement ${issue}?", choices "Start thread" (recommended) and "Not now", dedupe_key "github-issue-implement:${issue}". If they asked for the fix, start the Thread now. Skip both for issues owned by another team and for security, feedback, or tracking reports. Start the Thread with spawnAgent, kind thread, and this brief: read ${issue} with github_getIssue, follow the github-code workflow, and open a pull request that references it.`;
|
|
962
964
|
}
|
|
963
965
|
async function gitHubIssueToolResult(ctx, input, result) {
|
|
964
966
|
const repo = parseRepo$1(input.repo);
|
|
@@ -1379,11 +1381,13 @@ const juniorGitHubPullRequests = pgTable("junior_github_pull_requests", {
|
|
|
1379
1381
|
state: text("state").$type().notNull(),
|
|
1380
1382
|
commitComposition: text("commit_composition").$type(),
|
|
1381
1383
|
conversationIds: text("conversation_ids").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
1382
|
-
/** The daily reconcile compares this with GitHub. */
|
|
1383
|
-
draft: boolean("draft").notNull().default(false),
|
|
1384
1384
|
openedAt: timestamp$2("opened_at", { withTimezone: true }).notNull(),
|
|
1385
|
-
|
|
1386
|
-
|
|
1385
|
+
/**
|
|
1386
|
+
* When the pull request merged or closed. Null while it is open. The
|
|
1387
|
+
* finished work of a Conversation needs this time for every pull
|
|
1388
|
+
* request of every candidate, so it is stored and not read from GitHub.
|
|
1389
|
+
*/
|
|
1390
|
+
finishedAt: timestamp$2("finished_at", { withTimezone: true }),
|
|
1387
1391
|
updatedAt: timestamp$2("updated_at", { withTimezone: true }).notNull(),
|
|
1388
1392
|
/**
|
|
1389
1393
|
* The requester's next action that Junior last derived from GitHub, and
|
|
@@ -1420,8 +1424,6 @@ const juniorGitHubPullRequests = pgTable("junior_github_pull_requests", {
|
|
|
1420
1424
|
conflictFixes: jsonb("conflict_fixes").$type().notNull().default([])
|
|
1421
1425
|
}, (table) => [
|
|
1422
1426
|
index("junior_github_pull_requests_opened_at_idx").on(table.openedAt),
|
|
1423
|
-
index("junior_github_pull_requests_merged_at_idx").on(table.mergedAt),
|
|
1424
|
-
index("junior_github_pull_requests_closed_at_idx").on(table.closedAt),
|
|
1425
1427
|
index("junior_github_pull_requests_open_idx").on(table.pullRequestId).where(sql`${table.state} = 'open'`),
|
|
1426
1428
|
index("junior_github_pull_requests_unmerged_conversations_idx").using("gin", table.conversationIds).where(sql`${table.state} <> 'merged'`)
|
|
1427
1429
|
]);
|
|
@@ -1518,7 +1520,7 @@ async function listGitHubPullRequestOpeners(db, input) {
|
|
|
1518
1520
|
});
|
|
1519
1521
|
return openers;
|
|
1520
1522
|
}
|
|
1521
|
-
// src/
|
|
1523
|
+
// src/tool-support/stack-pull-request.ts
|
|
1522
1524
|
/** Longest chain of base branches to walk down to the trunk. */
|
|
1523
1525
|
const MAX_STACK_DEPTH = 10;
|
|
1524
1526
|
const GITHUB_STACKS_API_VERSION = "2026-03-10";
|
|
@@ -1682,7 +1684,8 @@ var GitHubPullRequestCreateRejectedError = class extends Error {
|
|
|
1682
1684
|
}
|
|
1683
1685
|
};
|
|
1684
1686
|
const BODY_DESCRIPTION = `Pull request body. ${PULL_REQUEST_BODY_RULES}`;
|
|
1685
|
-
const REVIEWERS_DESCRIPTION = "
|
|
1687
|
+
const REVIEWERS_DESCRIPTION = "People to ask for a review: GitHub logins, emails, Slack mentions, or names. A person maps to their linked GitHub login. Set it only when the person names a reviewer. Without it, the tool asks the requester. A draft is asked once ready.";
|
|
1688
|
+
const ASSIGNEES_DESCRIPTION = "People to assign: GitHub logins, emails, Slack mentions, or names. A person maps to their linked GitHub login. Set this only when the person or instruction names who to assign. Without it, the tool assigns the requester's linked GitHub account.";
|
|
1686
1689
|
const createPullRequestInputSchema = Type.Object({
|
|
1687
1690
|
repo: Type.String({ description: "Repository in \"owner/name\" format." }),
|
|
1688
1691
|
title: Type.String({ description: "Pull request title." }),
|
|
@@ -1693,6 +1696,10 @@ const createPullRequestInputSchema = Type.Object({
|
|
|
1693
1696
|
reviewers: Type.Optional(Type.Array(Type.String(), {
|
|
1694
1697
|
description: REVIEWERS_DESCRIPTION,
|
|
1695
1698
|
minItems: 1
|
|
1699
|
+
})),
|
|
1700
|
+
assignees: Type.Optional(Type.Array(Type.String(), {
|
|
1701
|
+
description: ASSIGNEES_DESCRIPTION,
|
|
1702
|
+
minItems: 1
|
|
1696
1703
|
}))
|
|
1697
1704
|
}, { additionalProperties: false });
|
|
1698
1705
|
const createPullRequestToolInputSchema = z.object({
|
|
@@ -1702,7 +1709,8 @@ const createPullRequestToolInputSchema = z.object({
|
|
|
1702
1709
|
base: z.string().describe("Base branch."),
|
|
1703
1710
|
body: z.string().describe(BODY_DESCRIPTION).optional(),
|
|
1704
1711
|
draft: z.boolean().describe("Whether to open the pull request as a draft.").optional(),
|
|
1705
|
-
reviewers: z.array(z.string()).min(1).describe(REVIEWERS_DESCRIPTION).optional()
|
|
1712
|
+
reviewers: z.array(z.string()).min(1).describe(REVIEWERS_DESCRIPTION).optional(),
|
|
1713
|
+
assignees: z.array(z.string()).min(1).describe(ASSIGNEES_DESCRIPTION).optional()
|
|
1706
1714
|
}).strict();
|
|
1707
1715
|
const createPullRequestStateSchema = Type.Union([Type.Object({
|
|
1708
1716
|
createdAtMs: Type.Number(),
|
|
@@ -1816,17 +1824,21 @@ async function recordOpener(ctx, input, state, requester) {
|
|
|
1816
1824
|
repositoryFullName: repo.ref
|
|
1817
1825
|
});
|
|
1818
1826
|
}
|
|
1819
|
-
/**
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1827
|
+
/**
|
|
1828
|
+
* Assign the named assignees, or else the requester. Assignment is optional:
|
|
1829
|
+
* provider failures must not fail PR creation.
|
|
1830
|
+
*/
|
|
1831
|
+
async function assignPullRequest(ctx, input, result, requester) {
|
|
1832
|
+
const requesterLogin = linkedGitHubLogin(requesterPerson(requester)?.user);
|
|
1833
|
+
const assignees = namedLogins(input.assignees, "assignee") ?? (requesterLogin ? [requesterLogin] : []);
|
|
1834
|
+
if (assignees.length === 0) return;
|
|
1823
1835
|
try {
|
|
1824
1836
|
const repo = parseRepo$1(input.repo);
|
|
1825
1837
|
const response = await githubApi(ctx.egress, {
|
|
1826
1838
|
operation: "github.pull.assign",
|
|
1827
1839
|
method: "POST",
|
|
1828
1840
|
path: `${repoPath(repo)}/issues/${result.number}/assignees`,
|
|
1829
|
-
body: { assignees
|
|
1841
|
+
body: { assignees }
|
|
1830
1842
|
});
|
|
1831
1843
|
if (!response.ok) ctx.log.warn("github.pull_request.assign_after_create.rejected", {
|
|
1832
1844
|
number: result.number,
|
|
@@ -1841,11 +1853,36 @@ async function assignPullRequestRequester(ctx, input, result, requester) {
|
|
|
1841
1853
|
});
|
|
1842
1854
|
}
|
|
1843
1855
|
}
|
|
1844
|
-
/**
|
|
1845
|
-
|
|
1846
|
-
|
|
1856
|
+
/**
|
|
1857
|
+
* Replace each named assignee or reviewer that is not a GitHub login, such as
|
|
1858
|
+
* an email, a Slack mention, or a name, with the linked GitHub login of the
|
|
1859
|
+
* person it names. Reject a value that no linked account verifies, before
|
|
1860
|
+
* GitHub opens the pull request.
|
|
1861
|
+
*/
|
|
1862
|
+
async function resolveNamedPeople(ctx, people) {
|
|
1863
|
+
const [assignees, reviewers] = await Promise.all([resolveLogins(ctx, people.assignees, "assignee"), resolveLogins(ctx, people.reviewers, "reviewer")]);
|
|
1864
|
+
return {
|
|
1865
|
+
...assignees ? { assignees } : void 0,
|
|
1866
|
+
...reviewers ? { reviewers } : void 0
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
const PERSON_LOOKUP_CONCURRENCY = 4;
|
|
1870
|
+
async function resolveLogins(ctx, values, role) {
|
|
1871
|
+
if (!values) return void 0;
|
|
1872
|
+
return await pLimit(PERSON_LOOKUP_CONCURRENCY).map(values, async (value) => {
|
|
1847
1873
|
const login = parseGitHubLogin(value);
|
|
1848
|
-
if (
|
|
1874
|
+
if (login) return login;
|
|
1875
|
+
const lookup = await ctx.users.findLinkedHandle(value, "github");
|
|
1876
|
+
const linked = lookup.status === "found" ? parseGitHubLogin(lookup.handle) : void 0;
|
|
1877
|
+
if (linked) return linked;
|
|
1878
|
+
throw new PluginToolInputError(lookup.status === "ambiguous" ? `More than one person matches ${role} ${value}. Name one person.` : lookup.status === "unlinked" ? `${role} ${value} has no linked GitHub account. Pass their GitHub login.` : `No person matches ${role} ${value}. Pass a GitHub login.`);
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
/** Return the logins of named reviewers or assignees. */
|
|
1882
|
+
function namedLogins(values, role) {
|
|
1883
|
+
return values?.map((value) => {
|
|
1884
|
+
const login = parseGitHubLogin(value);
|
|
1885
|
+
if (!login) throw new PluginToolInputError(`Invalid GitHub ${role} login: ${value}`);
|
|
1849
1886
|
return login;
|
|
1850
1887
|
});
|
|
1851
1888
|
}
|
|
@@ -1854,7 +1891,7 @@ function namedReviewers(input) {
|
|
|
1854
1891
|
* them. With nothing saved, that webhook asks the requester.
|
|
1855
1892
|
*/
|
|
1856
1893
|
async function saveNamedDraftReviewers(ctx, input, number) {
|
|
1857
|
-
const named =
|
|
1894
|
+
const named = namedLogins(input.reviewers, "reviewer");
|
|
1858
1895
|
if (!input.draft || !named) return;
|
|
1859
1896
|
await saveGitHubDraftReviewers(ctx.state, {
|
|
1860
1897
|
number,
|
|
@@ -1867,7 +1904,7 @@ async function saveNamedDraftReviewers(ctx, input, number) {
|
|
|
1867
1904
|
* optional: provider failures must not fail PR creation.
|
|
1868
1905
|
*/
|
|
1869
1906
|
async function requestPullRequestReviewers$1(ctx, input, result, requester) {
|
|
1870
|
-
const named =
|
|
1907
|
+
const named = namedLogins(input.reviewers, "reviewer");
|
|
1871
1908
|
const repo = parseRepo$1(input.repo);
|
|
1872
1909
|
try {
|
|
1873
1910
|
if (input.draft) {
|
|
@@ -1965,13 +2002,20 @@ function createGitHubPullRequestTool(subscriptionConfig, descriptionChecks = fal
|
|
|
1965
2002
|
openWorldHint: true,
|
|
1966
2003
|
readOnlyHint: false
|
|
1967
2004
|
},
|
|
1968
|
-
description: "Create a GitHub pull request with a runtime-owned conversation footer.
|
|
2005
|
+
description: "Create a GitHub pull request with a runtime-owned conversation footer. By default 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.",
|
|
1969
2006
|
exposure: "direct",
|
|
1970
2007
|
inputSchema: createPullRequestToolInputSchema,
|
|
1971
2008
|
outputSchema: gitHubPullRequestOutputSchema,
|
|
1972
2009
|
async execute(input, options, ctx) {
|
|
1973
|
-
const
|
|
1974
|
-
|
|
2010
|
+
const { assignees, reviewers, ...text } = input;
|
|
2011
|
+
const [githubText, people] = await Promise.all([ctx.users.replaceSlackMentions(text, "github"), resolveNamedPeople(ctx, {
|
|
2012
|
+
assignees,
|
|
2013
|
+
reviewers
|
|
2014
|
+
})]);
|
|
2015
|
+
const parsedInput = parseCreatePullRequestInput({
|
|
2016
|
+
...githubText,
|
|
2017
|
+
...people
|
|
2018
|
+
});
|
|
1975
2019
|
const conversationId = nonEmptyString$2(ctx.conversationId, "conversationId");
|
|
1976
2020
|
const key = `createPullRequest:${conversationId}:${nonEmptyString$2(options?.toolCallId, "toolCallId")}`;
|
|
1977
2021
|
const attempt = await ctx.state.withLock(`${key}:lock`, GITHUB_PULL_REQUEST_CREATE_LOCK_TTL_MS, async () => {
|
|
@@ -2030,7 +2074,7 @@ function createGitHubPullRequestTool(subscriptionConfig, descriptionChecks = fal
|
|
|
2030
2074
|
conversationId,
|
|
2031
2075
|
identityId
|
|
2032
2076
|
});
|
|
2033
|
-
await
|
|
2077
|
+
await assignPullRequest(ctx, parsedInput, result, requester);
|
|
2034
2078
|
await requestPullRequestReviewers$1(ctx, parsedInput, result, requester);
|
|
2035
2079
|
const stack = stackTarget ? await stackGitHubPullRequest(ctx, stackTarget) : void 0;
|
|
2036
2080
|
return await gitHubPullRequestStructuredResult(ctx, parsedInput, result, subscriptionConfig, stack);
|
|
@@ -3221,6 +3265,47 @@ function createGitHubUpdatePullRequestTool(descriptionChecks = false) {
|
|
|
3221
3265
|
}
|
|
3222
3266
|
});
|
|
3223
3267
|
}
|
|
3268
|
+
// src/pull-request-feedback.ts
|
|
3269
|
+
/**
|
|
3270
|
+
* GitHub has reactions but no feedback state. `updatePullRequestFeedback` maps
|
|
3271
|
+
* each state to a reaction and keeps at most one state reaction that Junior
|
|
3272
|
+
* owns. It does not change reactions from other users.
|
|
3273
|
+
*/
|
|
3274
|
+
const STATUS_TO_REACTION_CONTENT = {
|
|
3275
|
+
reviewing: "eyes",
|
|
3276
|
+
addressed: "+1",
|
|
3277
|
+
declined: "-1"
|
|
3278
|
+
};
|
|
3279
|
+
/** Every reaction that marks a feedback state. */
|
|
3280
|
+
const FEEDBACK_REACTION_CONTENTS = new Set(Object.values(STATUS_TO_REACTION_CONTENT));
|
|
3281
|
+
const GRAPHQL_REACTION_CONTENT = {
|
|
3282
|
+
eyes: "EYES",
|
|
3283
|
+
"+1": "THUMBS_UP",
|
|
3284
|
+
"-1": "THUMBS_DOWN"
|
|
3285
|
+
};
|
|
3286
|
+
/** REST name of each GraphQL reaction content. */
|
|
3287
|
+
const REST_REACTION_CONTENT = new Map(Object.entries(GRAPHQL_REACTION_CONTENT).map(([rest, graphql]) => [graphql, rest]));
|
|
3288
|
+
/** Build the GitHub API path for one pull request comment. */
|
|
3289
|
+
function pullRequestCommentPath(input) {
|
|
3290
|
+
const segment = input.commentKind === "conversation" ? "issues" : "pulls";
|
|
3291
|
+
return `/repos/${encodeURIComponent(input.owner)}/${encodeURIComponent(input.name)}/${segment}/comments/${input.commentId}`;
|
|
3292
|
+
}
|
|
3293
|
+
/** Build the GitHub API path for one pull request comment's reactions. */
|
|
3294
|
+
function pullRequestCommentReactionsPath(input) {
|
|
3295
|
+
return `${pullRequestCommentPath(input)}/reactions`;
|
|
3296
|
+
}
|
|
3297
|
+
/** Return the GitHub reaction for one feedback state. */
|
|
3298
|
+
function pullRequestFeedbackReactionContent(status) {
|
|
3299
|
+
return STATUS_TO_REACTION_CONTENT[status];
|
|
3300
|
+
}
|
|
3301
|
+
/** Build the GitHub API path for one pull request review. */
|
|
3302
|
+
function pullRequestReviewPath(input) {
|
|
3303
|
+
return `${repoPath(input)}/pulls/${input.pullRequest}/reviews/${input.reviewId}`;
|
|
3304
|
+
}
|
|
3305
|
+
/** Return the GraphQL name of one REST reaction content. */
|
|
3306
|
+
function graphqlReactionContent(content) {
|
|
3307
|
+
return GRAPHQL_REACTION_CONTENT[content] ?? content;
|
|
3308
|
+
}
|
|
3224
3309
|
// src/pull-request-reviews.ts
|
|
3225
3310
|
const REVIEWS_PAGE_SIZE = 100;
|
|
3226
3311
|
const reviewsSchema$1 = z.array(z.object({
|
|
@@ -3243,23 +3328,6 @@ async function loadLatestReviews(readPage) {
|
|
|
3243
3328
|
}
|
|
3244
3329
|
}
|
|
3245
3330
|
// src/tools/update-pull-request-feedback.ts
|
|
3246
|
-
/**
|
|
3247
|
-
* GitHub has reactions but no feedback state. This tool maps each state to a
|
|
3248
|
-
* reaction and keeps at most one state reaction that Junior owns. It does not
|
|
3249
|
-
* change reactions from other users.
|
|
3250
|
-
*/
|
|
3251
|
-
const STATUS_TO_REACTION_CONTENT = {
|
|
3252
|
-
reviewing: "eyes",
|
|
3253
|
-
addressed: "+1",
|
|
3254
|
-
declined: "-1"
|
|
3255
|
-
};
|
|
3256
|
-
const FEEDBACK_REACTION_CONTENTS = new Set(Object.values(STATUS_TO_REACTION_CONTENT));
|
|
3257
|
-
const GRAPHQL_REACTION_CONTENT = {
|
|
3258
|
-
eyes: "EYES",
|
|
3259
|
-
"+1": "THUMBS_UP",
|
|
3260
|
-
"-1": "THUMBS_DOWN"
|
|
3261
|
-
};
|
|
3262
|
-
const REST_REACTION_CONTENT = new Map(Object.entries(GRAPHQL_REACTION_CONTENT).map(([rest, graphql]) => [graphql, rest]));
|
|
3263
3331
|
const inputSchema$2 = z.object({
|
|
3264
3332
|
repo: z.string().describe("Repository in \"owner/name\" format."),
|
|
3265
3333
|
comment_kind: z.enum([
|
|
@@ -3277,18 +3345,6 @@ const outputSchema$2 = pluginToolOutputSchema.extend({
|
|
|
3277
3345
|
comment_id: z.number(),
|
|
3278
3346
|
status: z.enum(["addressed", "declined"])
|
|
3279
3347
|
});
|
|
3280
|
-
function pullRequestCommentPath(input) {
|
|
3281
|
-
const segment = input.commentKind === "conversation" ? "issues" : "pulls";
|
|
3282
|
-
return `/repos/${encodeURIComponent(input.owner)}/${encodeURIComponent(input.name)}/${segment}/comments/${input.commentId}`;
|
|
3283
|
-
}
|
|
3284
|
-
/** Build the GitHub API path for one pull request comment's reactions. */
|
|
3285
|
-
function pullRequestCommentReactionsPath(input) {
|
|
3286
|
-
return `${pullRequestCommentPath(input)}/reactions`;
|
|
3287
|
-
}
|
|
3288
|
-
/** Return the GitHub reaction for one feedback state. */
|
|
3289
|
-
function pullRequestFeedbackReactionContent(status) {
|
|
3290
|
-
return STATUS_TO_REACTION_CONTENT[status];
|
|
3291
|
-
}
|
|
3292
3348
|
const reactionSchema = z.object({
|
|
3293
3349
|
id: z.number(),
|
|
3294
3350
|
content: z.string(),
|
|
@@ -3333,14 +3389,6 @@ async function assertBotAuthoredPullRequest(egress, input) {
|
|
|
3333
3389
|
const pull = z.object({ user: z.object({ id: z.number() }).nullable() }).safeParse(pullPayload);
|
|
3334
3390
|
if (!pullResponse.ok || !pull.success || pull.data.user?.id !== input.botUserId) throw new PluginToolInputError("This bot can only set feedback status on comments on pull requests it authored.");
|
|
3335
3391
|
}
|
|
3336
|
-
/** Build the GitHub API path for one pull request review. */
|
|
3337
|
-
function pullRequestReviewPath(input) {
|
|
3338
|
-
return `${repoPath(input)}/pulls/${input.pullRequest}/reviews/${input.reviewId}`;
|
|
3339
|
-
}
|
|
3340
|
-
/** Return the GraphQL name of one REST reaction content. */
|
|
3341
|
-
function graphqlReactionContent(content) {
|
|
3342
|
-
return GRAPHQL_REACTION_CONTENT[content] ?? content;
|
|
3343
|
-
}
|
|
3344
3392
|
const reviewReactionsSchema = z.object({ data: z.object({ node: z.object({ reactionGroups: z.array(z.object({
|
|
3345
3393
|
content: z.string(),
|
|
3346
3394
|
reactors: z.object({ nodes: z.array(z.object({ databaseId: z.number().optional() })) })
|
|
@@ -3740,26 +3788,28 @@ function withGitHubText(tools) {
|
|
|
3740
3788
|
/** The GitHub plugin's tools for one deployment configuration. */
|
|
3741
3789
|
function createGitHubTools(botEmail, pullRequestSubscription, experimental = {}) {
|
|
3742
3790
|
const descriptionChecks = experimental.pullRequestDescriptionChecks ?? false;
|
|
3743
|
-
return
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3791
|
+
return {
|
|
3792
|
+
...withGitHubText({
|
|
3793
|
+
reactToIssue: gitHubReactToIssueTool,
|
|
3794
|
+
cloneRepository: gitHubCloneRepositoryTool,
|
|
3795
|
+
commentOnIssue: gitHubCommentOnIssueTool,
|
|
3796
|
+
commentOnPullRequest: gitHubCommentOnPullRequestTool,
|
|
3797
|
+
createIssue: gitHubIssueTool,
|
|
3798
|
+
getDeployment: gitHubGetDeploymentTool,
|
|
3799
|
+
getIssue: gitHubGetIssueTool,
|
|
3800
|
+
getPullRequest: gitHubGetPullRequestTool,
|
|
3801
|
+
getRelease: gitHubGetReleaseTool,
|
|
3802
|
+
getRepository: gitHubGetRepositoryTool,
|
|
3803
|
+
getStatus: gitHubGetStatusTool,
|
|
3804
|
+
resolvePullRequestReviewThread: createGitHubResolvePullRequestReviewThreadTool(botEmail),
|
|
3805
|
+
submitPullRequestReview: gitHubSubmitPullRequestReviewTool,
|
|
3806
|
+
updateIssue: gitHubUpdateIssueTool,
|
|
3807
|
+
updateIssueComment: createGitHubUpdateIssueCommentTool(botEmail),
|
|
3808
|
+
updatePullRequest: createGitHubUpdatePullRequestTool(descriptionChecks),
|
|
3809
|
+
updatePullRequestFeedback: createGitHubUpdatePullRequestFeedbackTool(botEmail)
|
|
3810
|
+
}),
|
|
3811
|
+
createPullRequest: createGitHubPullRequestTool(pullRequestSubscription, descriptionChecks)
|
|
3812
|
+
};
|
|
3763
3813
|
}
|
|
3764
3814
|
// src/issue-outcomes/store.ts
|
|
3765
3815
|
const githubIssueOutcomeInputSchema = z.object({
|
|
@@ -3834,12 +3884,221 @@ async function recordGitHubIssueConversations(db, input) {
|
|
|
3834
3884
|
ORDER BY value
|
|
3835
3885
|
)` }).where(eq(juniorGitHubIssues.issueId, association.issueId)).returning({ issueId: juniorGitHubIssues.issueId })).length > 0;
|
|
3836
3886
|
}
|
|
3887
|
+
// src/code-change-titles/parse.ts
|
|
3888
|
+
function nativePattern(source) {
|
|
3889
|
+
const regex = new RegExp(source, "i");
|
|
3890
|
+
return (title) => {
|
|
3891
|
+
const match = regex.exec(title);
|
|
3892
|
+
return match ? {
|
|
3893
|
+
scope: match.groups?.["scope"],
|
|
3894
|
+
type: match.groups?.["type"]
|
|
3895
|
+
} : void 0;
|
|
3896
|
+
};
|
|
3897
|
+
}
|
|
3898
|
+
function defaultCategory(title, sources) {
|
|
3899
|
+
return {
|
|
3900
|
+
custom: false,
|
|
3901
|
+
patterns: sources.map(nativePattern),
|
|
3902
|
+
title
|
|
3903
|
+
};
|
|
3904
|
+
}
|
|
3905
|
+
/** Craft's `DEFAULT_RELEASE_CONFIG` categories, in match order. */
|
|
3906
|
+
const DEFAULT_CODE_CHANGE_CATEGORIES = [
|
|
3907
|
+
defaultCategory("Breaking Changes", [String.raw`^(?<type>\w+(?:\((?<scope>[^)]+)\))?!:\s*)`]),
|
|
3908
|
+
defaultCategory("Security", [String.raw`^(?<type>security(?:\((?<scope>[^)]+)\))?!?:\s*)`]),
|
|
3909
|
+
defaultCategory("New Features", [String.raw`^(?<type>feat(?:\((?<scope>[^)]+)\))?!?:\s*)`]),
|
|
3910
|
+
defaultCategory("Bug Fixes", [String.raw`^(?<type>fix(?:\((?<scope>[^)]+)\))?!?:\s*)`, String.raw`^Revert "`]),
|
|
3911
|
+
defaultCategory("Documentation", [String.raw`^(?<type>docs?(?:\((?<scope>[^)]+)\))?!?:\s*)`]),
|
|
3912
|
+
defaultCategory("Internal Changes", [String.raw`^(?<type>(?:build|refactor|meta|chore|ci|ref|perf|tests?|style)(?:\((?<scope>[^)]+)\))?!?:\s*)`])
|
|
3913
|
+
];
|
|
3914
|
+
const TYPE_WORDS = {
|
|
3915
|
+
build: "Build",
|
|
3916
|
+
chore: "Chore",
|
|
3917
|
+
ci: "CI",
|
|
3918
|
+
doc: "Docs",
|
|
3919
|
+
docs: "Docs",
|
|
3920
|
+
feat: "Feature",
|
|
3921
|
+
fix: "Fix",
|
|
3922
|
+
meta: "Meta",
|
|
3923
|
+
perf: "Perf",
|
|
3924
|
+
ref: "Refactor",
|
|
3925
|
+
refactor: "Refactor",
|
|
3926
|
+
revert: "Revert",
|
|
3927
|
+
security: "Security",
|
|
3928
|
+
style: "Style",
|
|
3929
|
+
test: "Test",
|
|
3930
|
+
tests: "Test"
|
|
3931
|
+
};
|
|
3932
|
+
const BREAKING = /^\w+(?:\([^)]+\))?!:/;
|
|
3933
|
+
const REVERT = /^Revert "/i;
|
|
3934
|
+
const PULL_REQUEST_SUFFIX = /\s*\(#\d+\)$/;
|
|
3935
|
+
/** GitHub titles are at most 256 characters, so this bounds regex work. */
|
|
3936
|
+
const MAX_TITLE_LENGTH = 256;
|
|
3937
|
+
function capitalize(text) {
|
|
3938
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
3939
|
+
}
|
|
3940
|
+
/** A custom category title as one word pill, without emoji or padding. */
|
|
3941
|
+
function categoryWord(title) {
|
|
3942
|
+
const word = title.replace(/[\p{Extended_Pictographic}\u{FE0F}\u{200D}]/gu, "").trim();
|
|
3943
|
+
return word && !/^breaking\b/i.test(word) ? word : void 0;
|
|
3944
|
+
}
|
|
3945
|
+
function typeWord(category, token, title) {
|
|
3946
|
+
const known = token ? TYPE_WORDS[token.toLowerCase()] : void 0;
|
|
3947
|
+
if (known) return known;
|
|
3948
|
+
if (!token && REVERT.test(title)) return "Revert";
|
|
3949
|
+
return category.custom ? categoryWord(category.title) : void 0;
|
|
3950
|
+
}
|
|
3951
|
+
function firstMatch(title, categories) {
|
|
3952
|
+
for (const category of categories) for (const pattern of category.patterns) {
|
|
3953
|
+
const match = pattern(title);
|
|
3954
|
+
if (match) return {
|
|
3955
|
+
category,
|
|
3956
|
+
match
|
|
3957
|
+
};
|
|
3958
|
+
}
|
|
3959
|
+
}
|
|
3960
|
+
/**
|
|
3961
|
+
* Return the title parts of a pull request title, or undefined when the
|
|
3962
|
+
* title has no conventional prefix and no breaking marker. The first
|
|
3963
|
+
* matching category wins, as in Craft.
|
|
3964
|
+
*/
|
|
3965
|
+
function parseCodeChangeTitle(title, categories = DEFAULT_CODE_CHANGE_CATEGORIES) {
|
|
3966
|
+
const bounded = title.slice(0, MAX_TITLE_LENGTH);
|
|
3967
|
+
const breaking = BREAKING.test(bounded);
|
|
3968
|
+
const found = firstMatch(bounded, categories) ?? (breaking ? firstMatch(bounded, DEFAULT_CODE_CHANGE_CATEGORIES.slice(0, 1)) : void 0);
|
|
3969
|
+
if (!found) return void 0;
|
|
3970
|
+
const prefix = found.match.type;
|
|
3971
|
+
const token = prefix ? /^\w+/.exec(prefix)?.[0] : void 0;
|
|
3972
|
+
const rest = (prefix !== void 0 && bounded.startsWith(prefix) ? title.slice(prefix.length) : title).replace(PULL_REQUEST_SUFFIX, "").trim();
|
|
3973
|
+
const type = typeWord(found.category, token, bounded);
|
|
3974
|
+
const scope = found.match.scope?.trim();
|
|
3975
|
+
return {
|
|
3976
|
+
text: rest ? capitalize(rest) : title,
|
|
3977
|
+
...type ? { type } : void 0,
|
|
3978
|
+
...scope ? { scope } : void 0,
|
|
3979
|
+
...breaking ? { breaking: true } : void 0
|
|
3980
|
+
};
|
|
3981
|
+
}
|
|
3982
|
+
// src/code-change-titles/release-config.ts
|
|
3983
|
+
/**
|
|
3984
|
+
* A repository's changelog categories from `.github/release.yml`, the file
|
|
3985
|
+
* that GitHub release notes and Craft read. Craft adds `commit_patterns` to
|
|
3986
|
+
* each category. When the file has categories with patterns, they replace
|
|
3987
|
+
* the default categories, as in Craft.
|
|
3988
|
+
*/
|
|
3989
|
+
const MAX_CONFIG_LENGTH = 65536;
|
|
3990
|
+
const MAX_CATEGORIES = 30;
|
|
3991
|
+
const MAX_PATTERNS = 10;
|
|
3992
|
+
const MAX_PATTERN_LENGTH = 200;
|
|
3993
|
+
const releaseConfigSchema = z.object({ changelog: z.object({ categories: z.array(z.object({
|
|
3994
|
+
commit_patterns: z.array(z.string()).optional(),
|
|
3995
|
+
title: z.string().min(1)
|
|
3996
|
+
})).optional() }).optional() });
|
|
3997
|
+
function compilePattern(source) {
|
|
3998
|
+
if (source.length > MAX_PATTERN_LENGTH) return void 0;
|
|
3999
|
+
let regex;
|
|
4000
|
+
try {
|
|
4001
|
+
regex = RE2JS.compile(source, RE2JS.CASE_INSENSITIVE);
|
|
4002
|
+
} catch {
|
|
4003
|
+
return;
|
|
4004
|
+
}
|
|
4005
|
+
if (regex.matcher("").find()) return void 0;
|
|
4006
|
+
const groups = regex.namedGroups();
|
|
4007
|
+
return (title) => {
|
|
4008
|
+
const match = regex.matcher(title);
|
|
4009
|
+
if (!match.find()) return void 0;
|
|
4010
|
+
return {
|
|
4011
|
+
scope: "scope" in groups ? match.group("scope") ?? void 0 : void 0,
|
|
4012
|
+
type: "type" in groups ? match.group("type") ?? void 0 : void 0
|
|
4013
|
+
};
|
|
4014
|
+
};
|
|
4015
|
+
}
|
|
4016
|
+
/**
|
|
4017
|
+
* Return the changelog categories of a `.github/release.yml` text. A file
|
|
4018
|
+
* with no usable `commit_patterns`, or one that does not parse, gives the
|
|
4019
|
+
* default categories.
|
|
4020
|
+
*/
|
|
4021
|
+
function parseReleaseCategories(text) {
|
|
4022
|
+
if (text.length > MAX_CONFIG_LENGTH) return DEFAULT_CODE_CHANGE_CATEGORIES;
|
|
4023
|
+
let raw;
|
|
4024
|
+
try {
|
|
4025
|
+
raw = parse$1(text, { maxAliasCount: 100 });
|
|
4026
|
+
} catch {
|
|
4027
|
+
return DEFAULT_CODE_CHANGE_CATEGORIES;
|
|
4028
|
+
}
|
|
4029
|
+
const config = releaseConfigSchema.safeParse(raw);
|
|
4030
|
+
if (!config.success) return DEFAULT_CODE_CHANGE_CATEGORIES;
|
|
4031
|
+
const categories = (config.data.changelog?.categories ?? []).slice(0, MAX_CATEGORIES).map((category) => ({
|
|
4032
|
+
custom: true,
|
|
4033
|
+
patterns: (category.commit_patterns ?? []).slice(0, MAX_PATTERNS).map(compilePattern).filter((pattern) => pattern !== void 0),
|
|
4034
|
+
title: category.title
|
|
4035
|
+
})).filter((category) => category.patterns.length > 0);
|
|
4036
|
+
return categories.length > 0 ? categories : DEFAULT_CODE_CHANGE_CATEGORIES;
|
|
4037
|
+
}
|
|
4038
|
+
// src/webhooks/title-parts.ts
|
|
4039
|
+
/** A repository without the file costs at most one read in this time. */
|
|
4040
|
+
const MISSING_TTL_MS = 36e5;
|
|
4041
|
+
const contentsSchema = z.object({
|
|
4042
|
+
content: z.string(),
|
|
4043
|
+
encoding: z.literal("base64")
|
|
4044
|
+
});
|
|
4045
|
+
function missingKey(repositoryFullName) {
|
|
4046
|
+
return `github-release-config-missing:${repositoryFullName.toLowerCase()}`;
|
|
4047
|
+
}
|
|
4048
|
+
/**
|
|
4049
|
+
* Read a repository's changelog categories from GitHub with a read-only
|
|
4050
|
+
* token. The file is read with its ETag, and a missing file is remembered
|
|
4051
|
+
* for an hour in `env.responses`.
|
|
4052
|
+
*/
|
|
4053
|
+
async function loadReleaseCategories(env, repositoryFullName) {
|
|
4054
|
+
const [owner, name] = repositoryFullName.split("/");
|
|
4055
|
+
if (!owner || !name) return DEFAULT_CODE_CHANGE_CATEGORIES;
|
|
4056
|
+
const state = env.responses;
|
|
4057
|
+
if (await state?.get(missingKey(repositoryFullName)).catch(() => void 0)) return DEFAULT_CODE_CHANGE_CATEGORIES;
|
|
4058
|
+
const token = await issueInstallationToken({
|
|
4059
|
+
...env,
|
|
4060
|
+
permissions: { contents: "read" },
|
|
4061
|
+
repositories: [name]
|
|
4062
|
+
});
|
|
4063
|
+
let response;
|
|
4064
|
+
try {
|
|
4065
|
+
response = await githubRequest("https://api.github.com", `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/contents/.github/release.yml`, {
|
|
4066
|
+
responses: state,
|
|
4067
|
+
token: token.token
|
|
4068
|
+
});
|
|
4069
|
+
} catch (error) {
|
|
4070
|
+
if (!(error instanceof GitHubRequestError) || error.status !== 404) throw error;
|
|
4071
|
+
await state?.set(missingKey(repositoryFullName), true, MISSING_TTL_MS).catch(() => void 0);
|
|
4072
|
+
return DEFAULT_CODE_CHANGE_CATEGORIES;
|
|
4073
|
+
}
|
|
4074
|
+
const file = contentsSchema.safeParse(response);
|
|
4075
|
+
if (!file.success) return DEFAULT_CODE_CHANGE_CATEGORIES;
|
|
4076
|
+
return parseReleaseCategories(Buffer.from(file.data.content, "base64").toString("utf8"));
|
|
4077
|
+
}
|
|
4078
|
+
/**
|
|
4079
|
+
* Return the title parts of a pull request title with its repository's
|
|
4080
|
+
* changelog categories. Title parts are optional, so a failed read of the
|
|
4081
|
+
* categories is logged, and the default categories apply.
|
|
4082
|
+
*/
|
|
4083
|
+
async function loadGitHubTitleParts(env, input, log) {
|
|
4084
|
+
let categories;
|
|
4085
|
+
try {
|
|
4086
|
+
categories = await loadReleaseCategories(env, input.repositoryFullName);
|
|
4087
|
+
} catch (error) {
|
|
4088
|
+
logFailOpenFailure(log, "GitHub release config read failed", error, { repository: input.repositoryFullName });
|
|
4089
|
+
categories = DEFAULT_CODE_CHANGE_CATEGORIES;
|
|
4090
|
+
}
|
|
4091
|
+
return parseCodeChangeTitle(input.title, categories);
|
|
4092
|
+
}
|
|
3837
4093
|
// src/pull-request-outcomes/store.ts
|
|
3838
4094
|
const githubPullRequestOutcomeInputSchema = z.object({
|
|
3839
4095
|
candidateOwned: z.boolean(),
|
|
3840
4096
|
closedAt: z.date().optional(),
|
|
3841
4097
|
commitComposition: githubPullRequestCommitCompositionSchema.optional(),
|
|
3842
|
-
/**
|
|
4098
|
+
/**
|
|
4099
|
+
* Written to Junior's code index only. When omitted, the stored draft
|
|
4100
|
+
* state does not change.
|
|
4101
|
+
*/
|
|
3843
4102
|
draft: z.boolean().optional(),
|
|
3844
4103
|
mergedAt: z.date().optional(),
|
|
3845
4104
|
number: z.number().int().positive(),
|
|
@@ -3867,10 +4126,8 @@ const githubPullRequestLinkedIssuesInputSchema = z.object({
|
|
|
3867
4126
|
/** Select mutable lifecycle fields while excluding transient ownership inputs. */
|
|
3868
4127
|
function projectionValues(input) {
|
|
3869
4128
|
return {
|
|
3870
|
-
closedAt: input.closedAt ?? null,
|
|
3871
4129
|
...input.commitComposition ? { commitComposition: input.commitComposition } : void 0,
|
|
3872
|
-
|
|
3873
|
-
mergedAt: input.mergedAt ?? null,
|
|
4130
|
+
finishedAt: input.mergedAt ?? input.closedAt ?? null,
|
|
3874
4131
|
number: input.number,
|
|
3875
4132
|
openedAt: input.openedAt,
|
|
3876
4133
|
repositoryFullName: input.repositoryFullName,
|
|
@@ -3936,14 +4193,13 @@ async function listGitHubFinishedWork(db, conversationIds) {
|
|
|
3936
4193
|
if (conversationIds.length === 0) return {};
|
|
3937
4194
|
const values = sql.join(conversationIds.map((id) => sql`${id}`), sql`, `);
|
|
3938
4195
|
const rows = await db.select({
|
|
3939
|
-
closedAt: juniorGitHubPullRequests.closedAt,
|
|
3940
4196
|
conversationIds: juniorGitHubPullRequests.conversationIds,
|
|
3941
|
-
|
|
4197
|
+
finishedAt: juniorGitHubPullRequests.finishedAt
|
|
3942
4198
|
}).from(juniorGitHubPullRequests).where(and(ne(juniorGitHubPullRequests.state, "open"), sql`${juniorGitHubPullRequests.conversationIds} && ARRAY[${values}]::text[]`));
|
|
3943
4199
|
const candidates = new Set(conversationIds);
|
|
3944
4200
|
const finishedAtById = /* @__PURE__ */ new Map();
|
|
3945
4201
|
for (const row of rows) {
|
|
3946
|
-
const finishedAt = row
|
|
4202
|
+
const { finishedAt } = row;
|
|
3947
4203
|
if (!finishedAt) continue;
|
|
3948
4204
|
for (const conversationId of row.conversationIds) {
|
|
3949
4205
|
if (!candidates.has(conversationId)) continue;
|
|
@@ -3964,7 +4220,6 @@ async function listGitHubFinishedWork(db, conversationIds) {
|
|
|
3964
4220
|
async function listGitHubStaleOpenPullRequests(db, before) {
|
|
3965
4221
|
const t = juniorGitHubPullRequests;
|
|
3966
4222
|
return await db.select({
|
|
3967
|
-
draft: t.draft,
|
|
3968
4223
|
number: t.number,
|
|
3969
4224
|
repositoryFullName: t.repositoryFullName,
|
|
3970
4225
|
repositoryId: t.repositoryId
|
|
@@ -4175,7 +4430,11 @@ async function addUnlandedItem(args) {
|
|
|
4175
4430
|
})).get(ref.number);
|
|
4176
4431
|
if (!opener?.conversationId) return;
|
|
4177
4432
|
const url = conflict.url ?? `https://github.com/${ref.repositoryFullName}/pull/${ref.number}`;
|
|
4178
|
-
await args.
|
|
4433
|
+
const titleParts = title ? await args.loadTitleParts?.({
|
|
4434
|
+
repositoryFullName: ref.repositoryFullName,
|
|
4435
|
+
title
|
|
4436
|
+
}) : void 0;
|
|
4437
|
+
await args.inboxItems.forConversation(opener.conversationId).upsert({
|
|
4179
4438
|
assigneeIdentityIds: [opener.identityId],
|
|
4180
4439
|
body: `#${ref.number} conflicts with \`${conflict.baseBranch}\`, and the last fix did not land. Resume tries again. Dismiss stops these asks for this pull request.`,
|
|
4181
4440
|
choices: [{ label: GITHUB_CONFLICT_RESUME }],
|
|
@@ -4183,6 +4442,7 @@ async function addUnlandedItem(args) {
|
|
|
4183
4442
|
subject: {
|
|
4184
4443
|
id: url,
|
|
4185
4444
|
title: title ? `${title} (#${ref.number})` : url,
|
|
4445
|
+
...titleParts ? { titleParts } : void 0,
|
|
4186
4446
|
url
|
|
4187
4447
|
},
|
|
4188
4448
|
title: `Merge conflict · #${ref.number}`
|
|
@@ -4191,7 +4451,7 @@ async function addUnlandedItem(args) {
|
|
|
4191
4451
|
/**
|
|
4192
4452
|
* Return the merge conflict events to publish for one conflicted pull
|
|
4193
4453
|
* request that a Watch or event automation wants. A fix returns `events`.
|
|
4194
|
-
* An ask adds the
|
|
4454
|
+
* An ask adds the Inbox item and returns no events. The item is optional,
|
|
4195
4455
|
* so a failure is logged, and the next check tries again.
|
|
4196
4456
|
*/
|
|
4197
4457
|
async function applyGitHubConflictPolicy(args) {
|
|
@@ -4245,7 +4505,7 @@ async function closeGitHubConflictItem(args) {
|
|
|
4245
4505
|
repositoryFullName: ref.repositoryFullName
|
|
4246
4506
|
})).get(ref.number);
|
|
4247
4507
|
if (!opener?.conversationId) return;
|
|
4248
|
-
await args.
|
|
4508
|
+
await args.inboxItems.forConversation(opener.conversationId).close({
|
|
4249
4509
|
dedupeKey: gitHubConflictItemKey(ref),
|
|
4250
4510
|
reason: args.reason,
|
|
4251
4511
|
status: args.status
|
|
@@ -4254,7 +4514,9 @@ async function closeGitHubConflictItem(args) {
|
|
|
4254
4514
|
/**
|
|
4255
4515
|
* Close the merge conflict items of some Junior pull requests, such
|
|
4256
4516
|
* as ones that GitHub reports as mergeable. An item is optional, so a failed
|
|
4257
|
-
* close is logged, and the next check closes it again.
|
|
4517
|
+
* close is logged, and the next check closes it again. When an open item
|
|
4518
|
+
* closes, the ask was not dismissed, so a later fix that does not land asks
|
|
4519
|
+
* again.
|
|
4258
4520
|
*/
|
|
4259
4521
|
async function closeGitHubConflictItems(args) {
|
|
4260
4522
|
if (args.numbers.length === 0) return;
|
|
@@ -4266,14 +4528,17 @@ async function closeGitHubConflictItems(args) {
|
|
|
4266
4528
|
const limit = pLimit(ITEM_CLOSE_CONCURRENCY);
|
|
4267
4529
|
const close = async (number, conversationId) => {
|
|
4268
4530
|
try {
|
|
4269
|
-
await args.
|
|
4531
|
+
if (await args.inboxItems.forConversation(conversationId).close({
|
|
4270
4532
|
dedupeKey: gitHubConflictItemKey({
|
|
4271
4533
|
number,
|
|
4272
4534
|
repositoryFullName
|
|
4273
4535
|
}),
|
|
4274
4536
|
reason: args.reason,
|
|
4275
4537
|
status: args.status
|
|
4276
|
-
})
|
|
4538
|
+
})) await args.db.update(juniorGitHubPullRequests).set({ conflictFixAskedAt: null }).where(pullRequestRow({
|
|
4539
|
+
number,
|
|
4540
|
+
repositoryFullName
|
|
4541
|
+
}));
|
|
4277
4542
|
} catch (error) {
|
|
4278
4543
|
logFailOpenFailure(args.log, "GitHub merge conflict item close failed", error, {
|
|
4279
4544
|
number,
|
|
@@ -4284,6 +4549,12 @@ async function closeGitHubConflictItems(args) {
|
|
|
4284
4549
|
await Promise.all([...openers].flatMap(([number, { conversationId }]) => conversationId ? [limit(() => close(number, conversationId))] : []));
|
|
4285
4550
|
}
|
|
4286
4551
|
// src/webhooks/installation-requests.ts
|
|
4552
|
+
/**
|
|
4553
|
+
* GitHub requests that webhook handling makes with installation tokens.
|
|
4554
|
+
*
|
|
4555
|
+
* A webhook delivery has no Turn and no egress context, so these requests
|
|
4556
|
+
* call GitHub directly. Other plugin code must use host egress.
|
|
4557
|
+
*/
|
|
4287
4558
|
function splitRepository(fullName, label) {
|
|
4288
4559
|
const [owner, name, ...extra] = fullName.split("/");
|
|
4289
4560
|
if (!owner || !name || extra.length > 0) throw new Error(`GitHub ${label} received an invalid repository name`);
|
|
@@ -4300,7 +4571,10 @@ async function loadPullRequestCommitPages(env, pullRequest) {
|
|
|
4300
4571
|
permissions: { pull_requests: "read" },
|
|
4301
4572
|
repositories: [name]
|
|
4302
4573
|
});
|
|
4303
|
-
return async (page, perPage) => await githubRequest("https://api.github.com", `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${pullRequest.number}/commits?per_page=${perPage}&page=${page}`, {
|
|
4574
|
+
return async (page, perPage) => await githubRequest("https://api.github.com", `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${pullRequest.number}/commits?per_page=${perPage}&page=${page}`, {
|
|
4575
|
+
responses: env.responses,
|
|
4576
|
+
token: token.token
|
|
4577
|
+
});
|
|
4304
4578
|
}
|
|
4305
4579
|
/** Read one pull request, with a read-only token. */
|
|
4306
4580
|
async function loadPullRequest(env, pullRequest) {
|
|
@@ -4310,7 +4584,10 @@ async function loadPullRequest(env, pullRequest) {
|
|
|
4310
4584
|
permissions: { pull_requests: "read" },
|
|
4311
4585
|
repositories: [name]
|
|
4312
4586
|
});
|
|
4313
|
-
return await githubRequest("https://api.github.com", `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${pullRequest.number}`, {
|
|
4587
|
+
return await githubRequest("https://api.github.com", `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${pullRequest.number}`, {
|
|
4588
|
+
responses: env.responses,
|
|
4589
|
+
token: token.token
|
|
4590
|
+
});
|
|
4314
4591
|
}
|
|
4315
4592
|
/** GitHub cannot reach a repository: it is gone, or the installation lost it. */
|
|
4316
4593
|
var GitHubRepositoryUnreachableError = class extends Error {
|
|
@@ -4467,7 +4744,10 @@ async function loadRepositoryRole(env, cache, target) {
|
|
|
4467
4744
|
permissions: { metadata: "read" },
|
|
4468
4745
|
repositories: [name]
|
|
4469
4746
|
});
|
|
4470
|
-
const response = repositoryPermissionSchema.parse(await githubRequest("https://api.github.com", `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/collaborators/${encodeURIComponent(target.login)}/permission`, {
|
|
4747
|
+
const response = repositoryPermissionSchema.parse(await githubRequest("https://api.github.com", `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/collaborators/${encodeURIComponent(target.login)}/permission`, {
|
|
4748
|
+
responses: env.responses,
|
|
4749
|
+
token: token.token
|
|
4750
|
+
}));
|
|
4471
4751
|
return {
|
|
4472
4752
|
value: response.role_name?.trim() || response.permission,
|
|
4473
4753
|
ttlMs: REPOSITORY_ROLE_TTL_MS
|
|
@@ -4602,6 +4882,7 @@ async function loadPullRequestMergeState(env, pullRequest, requesterLogin) {
|
|
|
4602
4882
|
headSha: pull.headRefOid,
|
|
4603
4883
|
...mergeableState ? { mergeableState } : void 0,
|
|
4604
4884
|
requestedReviewers: pull.reviewRequests.nodes.flatMap((request) => request.requestedReviewer?.__typename === "User" && request.requestedReviewer.login ? [request.requestedReviewer.login] : []),
|
|
4885
|
+
reviewedBy: [],
|
|
4605
4886
|
state: pull.state === "MERGED" ? "merged" : pull.state === "OPEN" ? "open" : "closed",
|
|
4606
4887
|
title: pull.title,
|
|
4607
4888
|
url: pull.url
|
|
@@ -4609,6 +4890,9 @@ async function loadPullRequestMergeState(env, pullRequest, requesterLogin) {
|
|
|
4609
4890
|
if (!open) return state;
|
|
4610
4891
|
const latest = /* @__PURE__ */ new Map();
|
|
4611
4892
|
for (const review of reviews) if (review.author && review.state !== "COMMENTED" && review.state !== "PENDING") latest.set(review.author.login.toLowerCase(), review);
|
|
4893
|
+
const latestSubmitted = /* @__PURE__ */ new Map();
|
|
4894
|
+
for (const review of reviews) if (review.author && review.submittedAt && review.state !== "PENDING") latestSubmitted.set(review.author.login.toLowerCase(), review.state);
|
|
4895
|
+
state.reviewedBy = [...latestSubmitted].flatMap(([login, reviewState]) => reviewState === "DISMISSED" ? [] : [login]);
|
|
4612
4896
|
const reviewStates = [...latest.values()].map((review) => review.state);
|
|
4613
4897
|
if (!state.autoMerge && state.mergeableState === "clean") state.approved = reviewStates.includes("APPROVED") && !reviewStates.includes("CHANGES_REQUESTED");
|
|
4614
4898
|
const login = requesterLogin?.toLowerCase();
|
|
@@ -4807,6 +5091,7 @@ async function showAction(items, args) {
|
|
|
4807
5091
|
subject: {
|
|
4808
5092
|
id: state.url,
|
|
4809
5093
|
title: `${state.title} (#${number})`,
|
|
5094
|
+
...args.titleParts ? { titleParts: args.titleParts } : void 0,
|
|
4810
5095
|
url: state.url
|
|
4811
5096
|
},
|
|
4812
5097
|
title: action === "merge" ? `Ready to merge · #${number}` : `Review requested · #${number}`,
|
|
@@ -4832,7 +5117,7 @@ async function closeEndedGitHubPullRequestItems(args) {
|
|
|
4832
5117
|
repositoryFullName: target.repositoryFullName
|
|
4833
5118
|
})).get(target.number);
|
|
4834
5119
|
if (!opener?.conversationId) return;
|
|
4835
|
-
const items = args.
|
|
5120
|
+
const items = args.inboxItems.forConversation(opener.conversationId);
|
|
4836
5121
|
const reason = ENDED_REASONS[args.state];
|
|
4837
5122
|
await Promise.all([items.close({
|
|
4838
5123
|
dedupeKey: actionDedupeKey(target),
|
|
@@ -4871,7 +5156,7 @@ async function syncOne(args, target) {
|
|
|
4871
5156
|
repositoryFullName: target.repositoryFullName
|
|
4872
5157
|
})).get(target.number);
|
|
4873
5158
|
if (!opener?.conversationId) return;
|
|
4874
|
-
const items = args.
|
|
5159
|
+
const items = args.inboxItems.forConversation(opener.conversationId);
|
|
4875
5160
|
const name = itemName(target);
|
|
4876
5161
|
const dedupeKey = actionDedupeKey(target);
|
|
4877
5162
|
const requesterLogin = await args.loadGitHubLogin?.(opener.identityId);
|
|
@@ -4905,7 +5190,11 @@ async function syncOne(args, target) {
|
|
|
4905
5190
|
number: target.number,
|
|
4906
5191
|
previous,
|
|
4907
5192
|
reason: next.reason,
|
|
4908
|
-
state
|
|
5193
|
+
state,
|
|
5194
|
+
titleParts: next.action ? await loadGitHubTitleParts(args.env, {
|
|
5195
|
+
repositoryFullName: target.repositoryFullName,
|
|
5196
|
+
title: state.title
|
|
5197
|
+
}, args.log) : void 0
|
|
4909
5198
|
});
|
|
4910
5199
|
if (next.reason && requesterLogin && !isRequested(state, requesterLogin)) await requestReviewAgain(args, target, requesterLogin);
|
|
4911
5200
|
}
|
|
@@ -4980,7 +5269,7 @@ function githubCodeChange(outcome, conversationIds) {
|
|
|
4980
5269
|
/**
|
|
4981
5270
|
* Record one pull request outcome. When the stored row changes, update the
|
|
4982
5271
|
* code index, and mark the chip of each linked conversation merged or closed.
|
|
4983
|
-
* A merged or closed pull request closes its
|
|
5272
|
+
* A merged or closed pull request closes its Inbox items first, so no
|
|
4984
5273
|
* reader sees a merged chip next to an open item. A failed chip or item is
|
|
4985
5274
|
* logged, so it does not stop the work after it.
|
|
4986
5275
|
*/
|
|
@@ -4994,7 +5283,7 @@ async function applyGitHubPullRequestOutcome(args) {
|
|
|
4994
5283
|
await closeEndedGitHubPullRequestItems({
|
|
4995
5284
|
db: args.db,
|
|
4996
5285
|
log: args.log,
|
|
4997
|
-
|
|
5286
|
+
inboxItems: args.inboxItems,
|
|
4998
5287
|
state,
|
|
4999
5288
|
target: outcome
|
|
5000
5289
|
});
|
|
@@ -5535,10 +5824,11 @@ async function loadGitHubMergeConflictEvents(args) {
|
|
|
5535
5824
|
conflict
|
|
5536
5825
|
}),
|
|
5537
5826
|
loadHistory: loadConflictHistory,
|
|
5827
|
+
loadTitleParts: args.loadTitleParts,
|
|
5538
5828
|
log: args.log,
|
|
5539
5829
|
now: /* @__PURE__ */ new Date(),
|
|
5540
5830
|
ref,
|
|
5541
|
-
|
|
5831
|
+
inboxItems: args.inboxItems,
|
|
5542
5832
|
...loaded.title ? { title: loaded.title } : void 0
|
|
5543
5833
|
});
|
|
5544
5834
|
} catch (error) {
|
|
@@ -5675,7 +5965,10 @@ async function requestGitHubReviewersWhenReady(args) {
|
|
|
5675
5965
|
if (!opener?.conversationId) return;
|
|
5676
5966
|
const named = await readGitHubDraftReviewers(args.state, target);
|
|
5677
5967
|
const requester = named ? void 0 : await args.loadGitHubLogin?.(opener.identityId);
|
|
5678
|
-
const
|
|
5968
|
+
const candidates = named ?? (requester ? [requester] : []);
|
|
5969
|
+
if (candidates.length === 0) return;
|
|
5970
|
+
const { reviewedBy } = await loadPullRequestMergeState(args.env, target, void 0);
|
|
5971
|
+
const reviewers = candidates.filter((login) => !reviewedBy.includes(login.toLowerCase()));
|
|
5679
5972
|
if (reviewers.length === 0) return;
|
|
5680
5973
|
await requestPullRequestReviewers(args.env, {
|
|
5681
5974
|
...target,
|
|
@@ -6108,7 +6401,7 @@ function createGitHubWebhookRoute(args) {
|
|
|
6108
6401
|
db: args.db,
|
|
6109
6402
|
log: args.log,
|
|
6110
6403
|
outcome: pullRequestOutcome,
|
|
6111
|
-
|
|
6404
|
+
inboxItems: args.inboxItems
|
|
6112
6405
|
});
|
|
6113
6406
|
if (recordedOutcome.applied && !recordedOutcome.commitComposition && pullRequestOutcome.state === "merged" && args.classifyPullRequestCommits) {
|
|
6114
6407
|
let commitComposition;
|
|
@@ -6178,7 +6471,9 @@ function createGitHubWebhookRoute(args) {
|
|
|
6178
6471
|
...args.loadGitHubIncidents ? { loadGitHubIncidents: args.loadGitHubIncidents } : void 0,
|
|
6179
6472
|
loadPullRequestFacts: needsCheckSuitePullRequestFacts(checkSuiteMatchKeys),
|
|
6180
6473
|
log: args.log,
|
|
6181
|
-
privateKeyEnv: args.privateKeyEnv
|
|
6474
|
+
privateKeyEnv: args.privateKeyEnv,
|
|
6475
|
+
responses: args.state,
|
|
6476
|
+
tokens: args.tokens
|
|
6182
6477
|
}) : void 0;
|
|
6183
6478
|
const hasMatch = args.events.hasMatch;
|
|
6184
6479
|
const commitPages = args.loadPullRequestCommitPages ? shareCommitPages(args.loadPullRequestCommitPages) : void 0;
|
|
@@ -6230,38 +6525,38 @@ function createGitHubWebhookRoute(args) {
|
|
|
6230
6525
|
events,
|
|
6231
6526
|
hasMatch,
|
|
6232
6527
|
loadConflictHistory: args.loadPullRequestConflictHistory,
|
|
6528
|
+
loadTitleParts: args.loadTitleParts,
|
|
6233
6529
|
loadPullRequest: args.loadPullRequest,
|
|
6234
6530
|
log: args.log,
|
|
6235
6531
|
pullRequestPayload: eventName === "pull_request" ? body : void 0,
|
|
6236
|
-
|
|
6532
|
+
inboxItems: args.inboxItems
|
|
6237
6533
|
}));
|
|
6238
6534
|
for (const event of events) await args.events.publish({
|
|
6239
6535
|
...event,
|
|
6240
6536
|
objectType: event.eventType.startsWith("pull_request.") ? "code_change" : event.eventType.startsWith("issue.") ? "task" : event.eventType.startsWith("deployment.") ? "deployment" : "item"
|
|
6241
6537
|
});
|
|
6538
|
+
const env = {
|
|
6539
|
+
appIdEnv: args.appIdEnv,
|
|
6540
|
+
installationIdEnv: args.installationIdEnv,
|
|
6541
|
+
privateKeyEnv: args.privateKeyEnv,
|
|
6542
|
+
responses: args.state,
|
|
6543
|
+
tokens: args.tokens
|
|
6544
|
+
};
|
|
6242
6545
|
await syncGitHubPullRequestActions({
|
|
6243
6546
|
botEmail,
|
|
6244
6547
|
db: args.db,
|
|
6245
6548
|
deliveryId,
|
|
6246
|
-
env
|
|
6247
|
-
appIdEnv: args.appIdEnv,
|
|
6248
|
-
installationIdEnv: args.installationIdEnv,
|
|
6249
|
-
privateKeyEnv: args.privateKeyEnv
|
|
6250
|
-
},
|
|
6549
|
+
env,
|
|
6251
6550
|
loadGitHubLogin: args.loadGitHubLogin,
|
|
6252
6551
|
log: args.log,
|
|
6253
|
-
|
|
6552
|
+
inboxItems: args.inboxItems,
|
|
6254
6553
|
targets: pullRequestActionTargets(eventName, body)
|
|
6255
6554
|
});
|
|
6256
6555
|
await requestGitHubReviewersWhenReady({
|
|
6257
6556
|
body,
|
|
6258
6557
|
db: args.db,
|
|
6259
6558
|
deliveryId,
|
|
6260
|
-
env
|
|
6261
|
-
appIdEnv: args.appIdEnv,
|
|
6262
|
-
installationIdEnv: args.installationIdEnv,
|
|
6263
|
-
privateKeyEnv: args.privateKeyEnv
|
|
6264
|
-
},
|
|
6559
|
+
env,
|
|
6265
6560
|
eventName,
|
|
6266
6561
|
loadGitHubLogin: args.loadGitHubLogin,
|
|
6267
6562
|
log: args.log,
|
|
@@ -6322,10 +6617,11 @@ async function checkConflict(args, input) {
|
|
|
6322
6617
|
draft: input.draft,
|
|
6323
6618
|
events,
|
|
6324
6619
|
loadHistory: args.loadHistory,
|
|
6620
|
+
loadTitleParts: args.loadTitleParts,
|
|
6325
6621
|
log: args.log,
|
|
6326
6622
|
now: args.now,
|
|
6327
6623
|
ref: input.ref,
|
|
6328
|
-
|
|
6624
|
+
inboxItems: args.inboxItems,
|
|
6329
6625
|
title: input.title
|
|
6330
6626
|
})) await args.events.publish(event);
|
|
6331
6627
|
}
|
|
@@ -6364,7 +6660,7 @@ async function checkRepository(args, repositoryFullName) {
|
|
|
6364
6660
|
numbers: mergeable,
|
|
6365
6661
|
reason: GITHUB_CONFLICT_GONE_REASON,
|
|
6366
6662
|
repositoryFullName,
|
|
6367
|
-
|
|
6663
|
+
inboxItems: args.inboxItems,
|
|
6368
6664
|
status: "done"
|
|
6369
6665
|
});
|
|
6370
6666
|
if (!search.pageInfo.hasNextPage || !search.pageInfo.endCursor) break;
|
|
@@ -6505,11 +6801,11 @@ const lifecyclesResponseSchema = z.object({ data: z.object({ repository: z.objec
|
|
|
6505
6801
|
databaseId: z.number().int().positive(),
|
|
6506
6802
|
nameWithOwner: z.string().min(1)
|
|
6507
6803
|
}).catchall(lifecycleSchema.nullable()) }) });
|
|
6508
|
-
/** Write a GraphQL lifecycle as the body of a webhook
|
|
6509
|
-
function
|
|
6804
|
+
/** Write a GraphQL lifecycle as the body of a `closed` webhook. */
|
|
6805
|
+
function closedWebhookBody(repository, pullRequest) {
|
|
6510
6806
|
const login = pullRequest.author?.login ?? "ghost";
|
|
6511
6807
|
return {
|
|
6512
|
-
action,
|
|
6808
|
+
action: "closed",
|
|
6513
6809
|
pull_request: {
|
|
6514
6810
|
assignees: pullRequest.assignees.nodes.flatMap((assignee) => assignee ? [{ login: assignee.login }] : []),
|
|
6515
6811
|
closed_at: pullRequest.closedAt,
|
|
@@ -6530,24 +6826,7 @@ function webhookBody(action, repository, pullRequest) {
|
|
|
6530
6826
|
}
|
|
6531
6827
|
};
|
|
6532
6828
|
}
|
|
6533
|
-
|
|
6534
|
-
async function reconcileDraft(args, repository, pullRequest) {
|
|
6535
|
-
const outcome = normalizeGitHubPullRequestOutcome({
|
|
6536
|
-
body: webhookBody(pullRequest.isDraft ? "converted_to_draft" : "ready_for_review", repository, pullRequest),
|
|
6537
|
-
botEmail: args.botEmail
|
|
6538
|
-
});
|
|
6539
|
-
if (!outcome) return;
|
|
6540
|
-
await applyGitHubPullRequestOutcome({
|
|
6541
|
-
annotations: args.annotations,
|
|
6542
|
-
codeChanges: args.codeChanges,
|
|
6543
|
-
db: args.db,
|
|
6544
|
-
log: args.log,
|
|
6545
|
-
outcome,
|
|
6546
|
-
reviewItems: args.reviewItems
|
|
6547
|
-
});
|
|
6548
|
-
}
|
|
6549
|
-
async function reconcileRepository(args, repositoryId, drafts) {
|
|
6550
|
-
const numbers = [...drafts.keys()];
|
|
6829
|
+
async function reconcileRepository(args, repositoryId, numbers) {
|
|
6551
6830
|
for (let start = 0; start < numbers.length; start += PULL_REQUESTS_PER_QUERY) {
|
|
6552
6831
|
const { databaseId, nameWithOwner, ...pullRequests } = lifecyclesResponseSchema.parse(await args.loadLifecycles({
|
|
6553
6832
|
numbers: numbers.slice(start, start + PULL_REQUESTS_PER_QUERY),
|
|
@@ -6558,20 +6837,13 @@ async function reconcileRepository(args, repositoryId, drafts) {
|
|
|
6558
6837
|
await reconcilePullRequest(args, {
|
|
6559
6838
|
databaseId,
|
|
6560
6839
|
nameWithOwner
|
|
6561
|
-
}, pullRequest
|
|
6840
|
+
}, pullRequest);
|
|
6562
6841
|
}
|
|
6563
6842
|
}
|
|
6564
6843
|
}
|
|
6565
6844
|
/** Write the GitHub state of one stored pull request. */
|
|
6566
|
-
async function reconcilePullRequest(args, { databaseId, nameWithOwner }, pullRequest
|
|
6845
|
+
async function reconcilePullRequest(args, { databaseId, nameWithOwner }, pullRequest) {
|
|
6567
6846
|
if (pullRequest.state === "OPEN") {
|
|
6568
|
-
if (pullRequest.isDraft !== drafts.get(pullRequest.number)) {
|
|
6569
|
-
await reconcileDraft(args, {
|
|
6570
|
-
databaseId,
|
|
6571
|
-
nameWithOwner
|
|
6572
|
-
}, pullRequest);
|
|
6573
|
-
return;
|
|
6574
|
-
}
|
|
6575
6847
|
await args.codeChanges.record(githubCodeChange({
|
|
6576
6848
|
candidateOwned: false,
|
|
6577
6849
|
draft: pullRequest.isDraft,
|
|
@@ -6586,7 +6858,7 @@ async function reconcilePullRequest(args, { databaseId, nameWithOwner }, pullReq
|
|
|
6586
6858
|
}, []));
|
|
6587
6859
|
return;
|
|
6588
6860
|
}
|
|
6589
|
-
const body =
|
|
6861
|
+
const body = closedWebhookBody({
|
|
6590
6862
|
databaseId,
|
|
6591
6863
|
nameWithOwner
|
|
6592
6864
|
}, pullRequest);
|
|
@@ -6616,7 +6888,7 @@ async function reconcilePullRequest(args, { databaseId, nameWithOwner }, pullReq
|
|
|
6616
6888
|
number: pullRequest.number,
|
|
6617
6889
|
repositoryFullName: nameWithOwner
|
|
6618
6890
|
},
|
|
6619
|
-
|
|
6891
|
+
inboxItems: args.inboxItems,
|
|
6620
6892
|
...pullRequest.merged ? {
|
|
6621
6893
|
reason: "The pull request merged.",
|
|
6622
6894
|
status: "done"
|
|
@@ -6631,7 +6903,7 @@ async function reconcilePullRequest(args, { databaseId, nameWithOwner }, pullReq
|
|
|
6631
6903
|
db: args.db,
|
|
6632
6904
|
log: args.log,
|
|
6633
6905
|
outcome,
|
|
6634
|
-
|
|
6906
|
+
inboxItems: args.inboxItems
|
|
6635
6907
|
});
|
|
6636
6908
|
}
|
|
6637
6909
|
/**
|
|
@@ -6642,19 +6914,19 @@ async function reconcileGitHubPullRequests(args) {
|
|
|
6642
6914
|
const repositories = /* @__PURE__ */ new Map();
|
|
6643
6915
|
for (const row of await listGitHubStaleOpenPullRequests(args.db, /* @__PURE__ */ new Date(args.nowMs - RECONCILE_MS))) {
|
|
6644
6916
|
const repository = repositories.get(row.repositoryId) ?? {
|
|
6645
|
-
|
|
6646
|
-
|
|
6917
|
+
name: row.repositoryFullName,
|
|
6918
|
+
numbers: []
|
|
6647
6919
|
};
|
|
6648
|
-
repository.
|
|
6920
|
+
repository.numbers.push(row.number);
|
|
6649
6921
|
repositories.set(row.repositoryId, repository);
|
|
6650
6922
|
}
|
|
6651
6923
|
let reconciled = 0;
|
|
6652
|
-
for (const [repositoryId, {
|
|
6924
|
+
for (const [repositoryId, { name: repositoryFullName, numbers }] of repositories) {
|
|
6653
6925
|
if (reconciled >= REPOSITORY_LIMIT) break;
|
|
6654
6926
|
if (!await args.state.setIfNotExists(`pull-request-reconcile:${repositoryId}`, args.nowMs, RECONCILE_MS)) continue;
|
|
6655
6927
|
reconciled += 1;
|
|
6656
6928
|
try {
|
|
6657
|
-
await reconcileRepository(args, Number(repositoryId),
|
|
6929
|
+
await reconcileRepository(args, Number(repositoryId), numbers);
|
|
6658
6930
|
} catch (error) {
|
|
6659
6931
|
if (error instanceof GitHubRepositoryUnreachableError) args.log.warn("GitHub pull request reconcile skipped a repository", {
|
|
6660
6932
|
repository: repositoryFullName,
|
|
@@ -8442,7 +8714,7 @@ function githubPlugin(options = {}) {
|
|
|
8442
8714
|
systemPrompt() {
|
|
8443
8715
|
return [{ text: "Write each GitHub issue, pull request, or commit reference with its repository, such as owner/repo#123 or owner/repo@abc1234, and not in code formatting. A bare #123, GH-123, or SHA is ambiguous when a conversation spans several repositories." }];
|
|
8444
8716
|
},
|
|
8445
|
-
async
|
|
8717
|
+
async inboxItemAnswered(ctx) {
|
|
8446
8718
|
const ref = parseGitHubConflictItemKey(ctx.dedupeKey);
|
|
8447
8719
|
if (!ref || ctx.choice !== "Resume") return;
|
|
8448
8720
|
const installationEnv = {
|
|
@@ -8472,9 +8744,13 @@ function githubPlugin(options = {}) {
|
|
|
8472
8744
|
db,
|
|
8473
8745
|
events: ctx.events,
|
|
8474
8746
|
loadHistory: async (ref) => await loadPullRequestConflictHistory(installationEnv, ref),
|
|
8747
|
+
loadTitleParts: async (input) => await loadGitHubTitleParts({
|
|
8748
|
+
...installationEnv,
|
|
8749
|
+
responses: ctx.state
|
|
8750
|
+
}, input, ctx.log),
|
|
8475
8751
|
log: ctx.log,
|
|
8476
8752
|
now: new Date(ctx.nowMs),
|
|
8477
|
-
|
|
8753
|
+
inboxItems: ctx.inboxItems,
|
|
8478
8754
|
search: async (input) => {
|
|
8479
8755
|
const login = botLoginFromEmail(requireEnv(botEmailEnv));
|
|
8480
8756
|
if (!login) throw new Error(`${botEmailEnv} is not a GitHub bot address`);
|
|
@@ -8495,7 +8771,7 @@ function githubPlugin(options = {}) {
|
|
|
8495
8771
|
loadLifecycles: async (input) => await loadPullRequestLifecycles(installationEnv, input),
|
|
8496
8772
|
log: ctx.log,
|
|
8497
8773
|
nowMs: ctx.nowMs,
|
|
8498
|
-
|
|
8774
|
+
inboxItems: ctx.inboxItems,
|
|
8499
8775
|
state: ctx.state
|
|
8500
8776
|
});
|
|
8501
8777
|
},
|
|
@@ -8516,7 +8792,9 @@ function githubPlugin(options = {}) {
|
|
|
8516
8792
|
const installationEnv = {
|
|
8517
8793
|
appIdEnv,
|
|
8518
8794
|
installationIdEnv,
|
|
8519
|
-
privateKeyEnv
|
|
8795
|
+
privateKeyEnv,
|
|
8796
|
+
responses: ctx.state,
|
|
8797
|
+
tokens: /* @__PURE__ */ new Map()
|
|
8520
8798
|
};
|
|
8521
8799
|
return [createGitHubWebhookRoute({
|
|
8522
8800
|
annotations: ctx.annotations,
|
|
@@ -8537,12 +8815,14 @@ function githubPlugin(options = {}) {
|
|
|
8537
8815
|
loadPullRequest: async (pullRequest) => await loadPullRequest(installationEnv, pullRequest),
|
|
8538
8816
|
loadPullRequestConflictHistory: async (pullRequest) => await loadPullRequestConflictHistory(installationEnv, pullRequest),
|
|
8539
8817
|
loadPullRequestCommitPages: async (pullRequest) => await loadPullRequestCommitPages(installationEnv, pullRequest),
|
|
8818
|
+
loadTitleParts: async (input) => await loadGitHubTitleParts(installationEnv, input, ctx.log),
|
|
8540
8819
|
log: ctx.log,
|
|
8541
8820
|
markFeedbackReviewing: async (target) => await markPullRequestFeedbackReviewing(installationEnv, target),
|
|
8542
8821
|
privateKeyEnv,
|
|
8543
8822
|
events: ctx.events,
|
|
8544
|
-
|
|
8823
|
+
inboxItems: ctx.inboxItems,
|
|
8545
8824
|
state: ctx.state,
|
|
8825
|
+
tokens: installationEnv.tokens,
|
|
8546
8826
|
webhookSecret: () => readEnv("GITHUB_WEBHOOK_SECRET")
|
|
8547
8827
|
})];
|
|
8548
8828
|
},
|