@sentry/junior-github 0.317.0 → 0.319.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-BoMOs5Rd.js → events-DDjNmMZq.js} +11 -86
- package/dist/index.js +992 -466
- package/dist/testing.js +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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-DDjNmMZq.js";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
-
import pLimit from "p-limit";
|
|
4
|
-
import { EgressAuthRequired, EgressPolicyDenied, OBJECT_FACTS_MAX_BYTES, PluginToolInputError, decodeObjectImageRef, defineJuniorPlugin, definePluginTool, enforceEgressPolicy, mergeEventMatchFields, objectFactsBytes, objectFactsMatchType, objectFactsSchema, parseShellCommands, pluginToolOutputSchema, subscribableResourceSchema, watchResultSchema } from "@sentry/junior-plugin-api";
|
|
5
3
|
import { RE2JS } from "re2js";
|
|
6
4
|
import { parse } from "yaml";
|
|
5
|
+
import { EgressAuthRequired, EgressPolicyDenied, OBJECT_FACTS_MAX_BYTES, PluginInboxItemOwnerError, PluginToolInputError, decodeObjectImageRef, defineJuniorPlugin, definePluginTool, enforceEgressPolicy, mergeEventMatchFields, objectFactsBytes, parseShellCommands, pluginToolOutputSchema, subscribableResourceSchema, watchResultSchema } from "@sentry/junior-plugin-api";
|
|
7
6
|
import { lexer, walkTokens } from "marked";
|
|
8
7
|
import { parseFragment } from "parse5";
|
|
8
|
+
import pLimit from "p-limit";
|
|
9
9
|
import { Kind, parse as parse$1, print, visit } from "@0no-co/graphql.web";
|
|
10
10
|
import { and, asc, eq, gt, inArray, isNull, lt, lte, or, sql } from "drizzle-orm";
|
|
11
11
|
import { integer, jsonb, pgTable, primaryKey, text, timestamp as timestamp$1, uniqueIndex } from "drizzle-orm/pg-core";
|
|
@@ -88,6 +88,7 @@ const githubAccountLinks = {
|
|
|
88
88
|
// src/inbox-subjects.ts
|
|
89
89
|
/** The subject kinds of GitHub Inbox items. */
|
|
90
90
|
const GITHUB_INBOX_SUBJECTS = {
|
|
91
|
+
issue: "issue",
|
|
91
92
|
mergeConflict: "merge_conflict",
|
|
92
93
|
pullRequest: "pull_request"
|
|
93
94
|
};
|
|
@@ -102,24 +103,60 @@ function pullRequestAsk(object) {
|
|
|
102
103
|
if (facts?.type !== "code_change") return void 0;
|
|
103
104
|
return facts.review === "approved" && facts.mergeable === true && object.status !== "draft" ? "Ready to merge" : "Review requested";
|
|
104
105
|
}
|
|
106
|
+
const CARD_REVIEWER_LIMIT = 5;
|
|
107
|
+
/**
|
|
108
|
+
* Say what a dismiss of a pull request's item also changes on GitHub for
|
|
109
|
+
* the viewer: a requested reviewer leaves the reviewers. The requester is
|
|
110
|
+
* on the item too, with no review request. The card's list decides, and a
|
|
111
|
+
* full list may leave out a reviewer past its five, so a full list warns
|
|
112
|
+
* everyone on an item that asks for a review.
|
|
113
|
+
*/
|
|
114
|
+
function pullRequestDismissNote(object, viewer) {
|
|
115
|
+
const handle = viewer.handle?.toLowerCase();
|
|
116
|
+
if (!object || !handle) return void 0;
|
|
117
|
+
const reviewers = object.facts?.type === "code_change" ? object.facts.reviewers ?? [] : [];
|
|
118
|
+
return reviewers.some((login) => login.toLowerCase() === handle) || reviewers.length >= CARD_REVIEWER_LIMIT && pullRequestAsk(object) === "Review requested" ? "Also removes you from the reviewers on GitHub." : void 0;
|
|
119
|
+
}
|
|
120
|
+
function issueDismissNote() {
|
|
121
|
+
return "Also unassigns you on GitHub.";
|
|
122
|
+
}
|
|
105
123
|
const pullRequestOwner = {
|
|
106
124
|
conversationId: "conversation_id",
|
|
107
125
|
subjectId: "pull_request_id",
|
|
108
126
|
table: "junior_github_pull_request_requesters"
|
|
109
127
|
};
|
|
110
128
|
/** The registered kinds and labels, for the plugin registration. */
|
|
111
|
-
const githubInboxSubjectKinds = [
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
const githubInboxSubjectKinds = [
|
|
130
|
+
{
|
|
131
|
+
ask: pullRequestAsk,
|
|
132
|
+
codeChange: true,
|
|
133
|
+
assigneeRoles: true,
|
|
134
|
+
dismissNote: pullRequestDismissNote,
|
|
135
|
+
kind: GITHUB_INBOX_SUBJECTS.pullRequest,
|
|
136
|
+
label: "Pull request",
|
|
137
|
+
owner: pullRequestOwner
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
codeChange: true,
|
|
141
|
+
kind: GITHUB_INBOX_SUBJECTS.mergeConflict,
|
|
142
|
+
label: "Merge conflict",
|
|
143
|
+
owner: pullRequestOwner
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
assigneeRoles: true,
|
|
147
|
+
dismissNote: issueDismissNote,
|
|
148
|
+
kind: GITHUB_INBOX_SUBJECTS.issue,
|
|
149
|
+
label: "Issue",
|
|
150
|
+
owner: "annotation"
|
|
151
|
+
}
|
|
152
|
+
];
|
|
153
|
+
/** The subject of the Inbox item of one issue that Junior created. */
|
|
154
|
+
function issueSubject(issueId) {
|
|
155
|
+
return {
|
|
156
|
+
id: issueId,
|
|
157
|
+
kind: GITHUB_INBOX_SUBJECTS.issue
|
|
158
|
+
};
|
|
159
|
+
}
|
|
123
160
|
/** The subject of an Inbox item about one pull request. */
|
|
124
161
|
function pullRequestSubject(kind, pullRequestId) {
|
|
125
162
|
return {
|
|
@@ -147,11 +184,11 @@ function githubSidebarAnnotations(annotations) {
|
|
|
147
184
|
if (!label) return [];
|
|
148
185
|
const sidebar = {
|
|
149
186
|
objectType: githubObjectType(annotation),
|
|
150
|
-
status: annotation.status,
|
|
151
187
|
key: annotation.key,
|
|
152
188
|
label
|
|
153
189
|
};
|
|
154
190
|
if (annotation.kind === "object") {
|
|
191
|
+
if (annotation.status) sidebar.status = annotation.status;
|
|
155
192
|
sidebar.title = annotation.title;
|
|
156
193
|
if (annotation.facts?.type === "code_change") {
|
|
157
194
|
const image = annotation.facts.previewImageUrls?.[0];
|
|
@@ -165,15 +202,73 @@ function githubSidebarAnnotations(annotations) {
|
|
|
165
202
|
}];
|
|
166
203
|
}).sort((left, right) => right.updatedAt.localeCompare(left.updatedAt)).map(({ annotation }) => annotation);
|
|
167
204
|
}
|
|
205
|
+
function repositoryPrefix(repo) {
|
|
206
|
+
return {
|
|
207
|
+
key: `${repo.toLowerCase()}#`,
|
|
208
|
+
url: `https://github.com/${repo}/`
|
|
209
|
+
};
|
|
210
|
+
}
|
|
168
211
|
/** Return the Annotation key of a GitHub issue or pull request. */
|
|
169
212
|
function githubObjectKey(repo, number) {
|
|
170
|
-
return `${repo.
|
|
213
|
+
return `${repositoryPrefix(repo).key}${number}`;
|
|
171
214
|
}
|
|
172
|
-
/**
|
|
173
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Return the move of the Annotations of each issue and pull request of a
|
|
217
|
+
* repository that GitHub renamed or transferred, by its full names.
|
|
218
|
+
*/
|
|
219
|
+
function githubRepositoryMove(from, to) {
|
|
220
|
+
return {
|
|
221
|
+
from: repositoryPrefix(from),
|
|
222
|
+
to: repositoryPrefix(to)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Order repository renames so that each runs before the rename into its old
|
|
227
|
+
* name: `a→b` after `b→c`, or the keys of `a` would end on `c`. Renames in
|
|
228
|
+
* a cycle, such as two repositories that swapped names, have no safe order
|
|
229
|
+
* and are returned apart.
|
|
230
|
+
*/
|
|
231
|
+
function orderRepositoryRenames(renames) {
|
|
232
|
+
const pending = [...renames];
|
|
233
|
+
const ordered = [];
|
|
234
|
+
for (;;) {
|
|
235
|
+
const sources = new Set(pending.map(([from]) => from.toLowerCase()));
|
|
236
|
+
const next = pending.findIndex(([, to]) => !sources.has(to.toLowerCase()));
|
|
237
|
+
if (next < 0) return {
|
|
238
|
+
cyclic: pending,
|
|
239
|
+
ordered
|
|
240
|
+
};
|
|
241
|
+
ordered.push(...pending.splice(next, 1));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function currentRepository(url, repo) {
|
|
245
|
+
const parsed = URL.parse(url);
|
|
246
|
+
const [owner, name] = parsed?.hostname === "github.com" ? parsed.pathname.split("/").filter(Boolean) : [];
|
|
247
|
+
return owner && name ? `${owner}/${name}` : repo;
|
|
248
|
+
}
|
|
249
|
+
/** Build the Annotation that GitHub create and update tools return. */
|
|
250
|
+
function githubAnnotatedObject(input) {
|
|
251
|
+
return {
|
|
252
|
+
kind: "object",
|
|
253
|
+
key: githubObjectKey(currentRepository(input.url, input.repo), input.number),
|
|
254
|
+
...input.id ? { subject: {
|
|
255
|
+
id: input.id,
|
|
256
|
+
kind: input.objectType === "code_change" ? GITHUB_INBOX_SUBJECTS.pullRequest : GITHUB_INBOX_SUBJECTS.issue
|
|
257
|
+
} } : void 0,
|
|
258
|
+
title: input.title.slice(0, 512),
|
|
259
|
+
url: input.url,
|
|
260
|
+
objectType: input.objectType
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/** Build the live card of a GitHub issue or pull request. */
|
|
264
|
+
function githubObjectCard(input) {
|
|
174
265
|
return {
|
|
175
266
|
kind: "object",
|
|
176
267
|
key: githubObjectKey(input.repo, input.number),
|
|
268
|
+
...input.id ? { subject: {
|
|
269
|
+
id: String(input.id),
|
|
270
|
+
kind: input.objectType === "code_change" ? GITHUB_INBOX_SUBJECTS.pullRequest : GITHUB_INBOX_SUBJECTS.issue
|
|
271
|
+
} } : void 0,
|
|
177
272
|
label: `${input.repo}#${input.number}`,
|
|
178
273
|
title: input.title.slice(0, 512),
|
|
179
274
|
url: input.url,
|
|
@@ -185,70 +280,6 @@ function githubObjectAnnotation(input) {
|
|
|
185
280
|
sourceUpdatedAt: input.sourceUpdatedAt
|
|
186
281
|
};
|
|
187
282
|
}
|
|
188
|
-
/**
|
|
189
|
-
* Return the annotation that shows a new status of one object, from the
|
|
190
|
-
* stored annotations of a conversation. It keeps a saved object card and
|
|
191
|
-
* does not select a card for delivery.
|
|
192
|
-
*/
|
|
193
|
-
function githubStatusAnnotation(annotations, input) {
|
|
194
|
-
const key = githubObjectKey(input.repo, input.number);
|
|
195
|
-
const current = annotations.find((annotation) => annotation.key === key);
|
|
196
|
-
if (current?.kind === "object") {
|
|
197
|
-
const { plugin: _plugin, createdAt: _createdAt, updatedAt: _updatedAt, facts, ...annotation } = current;
|
|
198
|
-
return {
|
|
199
|
-
...annotation,
|
|
200
|
-
...facts && objectFactsMatchType(facts, input.objectType) ? { facts } : void 0,
|
|
201
|
-
objectType: input.objectType,
|
|
202
|
-
status: input.status
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
return {
|
|
206
|
-
kind: "resource_link",
|
|
207
|
-
objectType: input.objectType,
|
|
208
|
-
key,
|
|
209
|
-
label: `${input.repo}#${input.number}`,
|
|
210
|
-
url: `https://github.com/${input.repo}/${input.objectType === "code_change" ? "pull" : "issues"}/${input.number}`,
|
|
211
|
-
status: input.status
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Refresh an existing object's status without selecting a card for delivery.
|
|
216
|
-
* With `existingOnly`, a conversation with no annotation for the object gets
|
|
217
|
-
* none.
|
|
218
|
-
*/
|
|
219
|
-
async function updateGitHubAnnotation(store, input, existingOnly) {
|
|
220
|
-
const annotations = await store.list();
|
|
221
|
-
const key = githubObjectKey(input.repo, input.number);
|
|
222
|
-
if (existingOnly && !annotations.some((item) => item.key === key)) return;
|
|
223
|
-
await store.upsert(githubStatusAnnotation(annotations, input));
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Refresh the status of one object in each linked conversation. One failed
|
|
227
|
-
* conversation does not stop the others. Each failure is logged.
|
|
228
|
-
*/
|
|
229
|
-
async function updateGitHubAnnotations(args) {
|
|
230
|
-
const limit = pLimit(8);
|
|
231
|
-
const results = await Promise.allSettled(args.conversationIds.map((conversationId) => limit(() => updateGitHubAnnotation(args.annotations.forConversation(conversationId), args.update, args.existingOnly ?? false))));
|
|
232
|
-
for (const result of results) {
|
|
233
|
-
if (result.status === "fulfilled") continue;
|
|
234
|
-
args.log?.error("GitHub conversation annotation update failed", {
|
|
235
|
-
errorType: result.reason instanceof Error ? result.reason.name : "UnknownError",
|
|
236
|
-
number: args.update.number,
|
|
237
|
-
objectType: args.update.objectType,
|
|
238
|
-
repository: args.update.repo
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Return the status change of one object for one conversation, to save in
|
|
244
|
-
* one batch with other changes.
|
|
245
|
-
*/
|
|
246
|
-
async function githubAnnotationChange(args) {
|
|
247
|
-
return {
|
|
248
|
-
conversationId: args.conversationId,
|
|
249
|
-
upsert: githubStatusAnnotation(await args.annotations.forConversation(args.conversationId).list(), args.update)
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
283
|
// src/code-change-titles/parse.ts
|
|
253
284
|
function nativePattern(source) {
|
|
254
285
|
const regex = new RegExp(source, "i");
|
|
@@ -436,6 +467,7 @@ const label = z.union([z.string(), z.object({ name: z.string() })]);
|
|
|
436
467
|
const objectFields = {
|
|
437
468
|
body: z.string().nullable().optional(),
|
|
438
469
|
html_url: z.string(),
|
|
470
|
+
id: z.number().int().positive().optional(),
|
|
439
471
|
number: z.number().int().positive(),
|
|
440
472
|
state: z.string(),
|
|
441
473
|
title: z.string(),
|
|
@@ -940,9 +972,9 @@ const OPEN_PULL_REQUEST_MERGEABILITY = githubGraphql(`
|
|
|
940
972
|
`);
|
|
941
973
|
/**
|
|
942
974
|
* Read what decides a merge conflict fix on one pull request: the review
|
|
943
|
-
* decision, when it opened,
|
|
944
|
-
*
|
|
945
|
-
*
|
|
975
|
+
* decision, when it opened, its latest pushes, reviews, and comments, and
|
|
976
|
+
* its base branch changes. Pushes and base changes have their own windows,
|
|
977
|
+
* so comments, which anyone can add, cannot push them out.
|
|
946
978
|
*/
|
|
947
979
|
const PULL_REQUEST_CONFLICT_HISTORY = githubGraphql(`
|
|
948
980
|
query PullRequestConflictHistory($owner: String!, $name: String!, $number: Int!) {
|
|
@@ -964,6 +996,13 @@ const PULL_REQUEST_CONFLICT_HISTORY = githubGraphql(`
|
|
|
964
996
|
... on IssueComment { createdAt author { __typename } }
|
|
965
997
|
}
|
|
966
998
|
}
|
|
999
|
+
baseChanges: timelineItems(last: 10, itemTypes: [AUTOMATIC_BASE_CHANGE_SUCCEEDED_EVENT, BASE_REF_CHANGED_EVENT]) {
|
|
1000
|
+
nodes {
|
|
1001
|
+
__typename
|
|
1002
|
+
... on AutomaticBaseChangeSucceededEvent { createdAt actor { __typename } }
|
|
1003
|
+
... on BaseRefChangedEvent { createdAt actor { __typename } }
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
967
1006
|
}
|
|
968
1007
|
}
|
|
969
1008
|
}
|
|
@@ -972,15 +1011,20 @@ const PULL_REQUEST_CONFLICT_HISTORY = githubGraphql(`
|
|
|
972
1011
|
* Read what decides the requester's next action on one pull request: its
|
|
973
1012
|
* state, merge state, review requests, latest reviews, and latest comments
|
|
974
1013
|
* and review requests. A review comment reply is a review, so `reviews`
|
|
975
|
-
* holds it too.
|
|
1014
|
+
* holds it too. The open pull requests whose head is the base branch show
|
|
1015
|
+
* that the base has not merged yet.
|
|
976
1016
|
*/
|
|
977
1017
|
const PULL_REQUEST_NEXT_ACTION = githubGraphql(`
|
|
978
1018
|
query PullRequestNextAction($owner: String!, $name: String!, $number: Int!) {
|
|
979
1019
|
repository(owner: $owner, name: $name) {
|
|
1020
|
+
defaultBranchRef { name }
|
|
980
1021
|
pullRequest(number: $number) {
|
|
981
1022
|
autoMergeRequest { enabledAt }
|
|
1023
|
+
baseRefName
|
|
1024
|
+
baseRef { associatedPullRequests(states: [OPEN]) { totalCount } }
|
|
982
1025
|
commits(last: 1) { nodes { commit { committedDate } } }
|
|
983
1026
|
isDraft
|
|
1027
|
+
isInMergeQueue
|
|
984
1028
|
mergeStateStatus
|
|
985
1029
|
state
|
|
986
1030
|
title
|
|
@@ -1257,6 +1301,7 @@ const PULL_REQUEST_HEAD_FACT = githubGraphql(`
|
|
|
1257
1301
|
}
|
|
1258
1302
|
|
|
1259
1303
|
fragment HeadFacts on PullRequest {
|
|
1304
|
+
databaseId
|
|
1260
1305
|
updatedAt
|
|
1261
1306
|
headRefOid
|
|
1262
1307
|
mergeable
|
|
@@ -1631,6 +1676,10 @@ async function prefetchGitHubPullRequests(ctx, refs) {
|
|
|
1631
1676
|
return outOfTime;
|
|
1632
1677
|
}
|
|
1633
1678
|
// src/issue-links.ts
|
|
1679
|
+
const OBJECT_CACHE_READS = {
|
|
1680
|
+
staleIfError: false,
|
|
1681
|
+
ttlMs: 0
|
|
1682
|
+
};
|
|
1634
1683
|
const RELEASE_CONFIG_TTL_MS = 36e5;
|
|
1635
1684
|
const contentsSchema = z.object({
|
|
1636
1685
|
content: z.string(),
|
|
@@ -1660,10 +1709,11 @@ function repoRef(htmlUrl, link) {
|
|
|
1660
1709
|
return `${owner}/${name}`;
|
|
1661
1710
|
}
|
|
1662
1711
|
function issueCard(link, issue) {
|
|
1663
|
-
return
|
|
1712
|
+
return githubObjectCard({
|
|
1664
1713
|
...githubObjectFacts("task", issue),
|
|
1665
1714
|
repo: repoRef(issue.html_url, link),
|
|
1666
1715
|
number: issue.number,
|
|
1716
|
+
id: issue.id,
|
|
1667
1717
|
title: issue.title,
|
|
1668
1718
|
url: issue.html_url,
|
|
1669
1719
|
objectType: "task",
|
|
@@ -1686,11 +1736,12 @@ function pullRequestCard(link, pull, categories) {
|
|
|
1686
1736
|
const card = githubObjectFacts("code_change", pull);
|
|
1687
1737
|
const parsed = categories && parseCodeChangeTitle(pull.title, categories);
|
|
1688
1738
|
const titleParts = parsed && (parsed.scope?.length ?? 0) <= TITLE_PART_MAX_LENGTH && (parsed.type?.length ?? 0) <= TITLE_PART_MAX_LENGTH ? parsed : void 0;
|
|
1689
|
-
return
|
|
1739
|
+
return githubObjectCard({
|
|
1690
1740
|
...card,
|
|
1691
1741
|
...titleParts && card.facts?.type === "code_change" ? { facts: withTitleParts(card.facts, titleParts) } : void 0,
|
|
1692
1742
|
repo: repoRef(pull.html_url, link),
|
|
1693
1743
|
number: pull.number,
|
|
1744
|
+
id: pull.id,
|
|
1694
1745
|
title: pull.title,
|
|
1695
1746
|
url: pull.html_url,
|
|
1696
1747
|
objectType: "code_change",
|
|
@@ -1799,6 +1850,10 @@ async function canViewLink(ctx, url) {
|
|
|
1799
1850
|
const source = card.url ? htmlUrlLink(card.url) : void 0;
|
|
1800
1851
|
return Boolean(source && await viewerCanSeeRepository(ctx, source));
|
|
1801
1852
|
}
|
|
1853
|
+
function linkLabel(url) {
|
|
1854
|
+
const link = parseLink(url);
|
|
1855
|
+
return link ? `${link.owner}/${link.name}#${link.number}` : void 0;
|
|
1856
|
+
}
|
|
1802
1857
|
async function resolveLink(ctx, url) {
|
|
1803
1858
|
const link = parseLink(url);
|
|
1804
1859
|
return (link && await readObject(ctx, link)) ?? void 0;
|
|
@@ -1808,12 +1863,13 @@ async function resolveLink(ctx, url) {
|
|
|
1808
1863
|
* A pull request at its issue URL shows the pull request card.
|
|
1809
1864
|
*/
|
|
1810
1865
|
const githubIssueLinks = {
|
|
1811
|
-
cacheCards: false,
|
|
1812
1866
|
canView: canViewLink,
|
|
1813
1867
|
filters: [{
|
|
1814
1868
|
host: "github.com",
|
|
1815
1869
|
pathPattern: "/*/*/issues/*"
|
|
1816
1870
|
}],
|
|
1871
|
+
httpCache: OBJECT_CACHE_READS,
|
|
1872
|
+
label: linkLabel,
|
|
1817
1873
|
objectTypes: ["task", "code_change"],
|
|
1818
1874
|
readTool: (object) => object.objectType === "code_change" ? "github_getPullRequest" : "github_getIssue",
|
|
1819
1875
|
resolve: resolveLink,
|
|
@@ -1841,12 +1897,13 @@ async function prefetchLinks(ctx, urls) {
|
|
|
1841
1897
|
}
|
|
1842
1898
|
/** GitHub pull request links, such as `https://github.com/owner/repo/pull/12`. */
|
|
1843
1899
|
const githubPullRequestLinks = {
|
|
1844
|
-
cacheCards: false,
|
|
1845
1900
|
canView: canViewLink,
|
|
1846
1901
|
filters: [{
|
|
1847
1902
|
host: "github.com",
|
|
1848
1903
|
pathPattern: "/*/*/pull/*"
|
|
1849
1904
|
}],
|
|
1905
|
+
httpCache: OBJECT_CACHE_READS,
|
|
1906
|
+
label: linkLabel,
|
|
1850
1907
|
objectTypes: ["code_change"],
|
|
1851
1908
|
prefetch: prefetchLinks,
|
|
1852
1909
|
readTool: () => "github_getPullRequest",
|
|
@@ -2795,6 +2852,7 @@ const createIssueToolInputSchema = z.object({
|
|
|
2795
2852
|
}).strict();
|
|
2796
2853
|
const createIssueStateSchema = Type.Union([Type.Object({
|
|
2797
2854
|
createdAtMs: Type.Number(),
|
|
2855
|
+
id: Type.Optional(Type.Number()),
|
|
2798
2856
|
input: Type.Optional(createIssueInputSchema),
|
|
2799
2857
|
number: Type.Number(),
|
|
2800
2858
|
facts: Type.Optional(Type.Unknown()),
|
|
@@ -2837,17 +2895,17 @@ async function gitHubIssueToolResult(ctx, input, result) {
|
|
|
2837
2895
|
...watch
|
|
2838
2896
|
};
|
|
2839
2897
|
return {
|
|
2840
|
-
objectAnnotations: [
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
}
|
|
2898
|
+
objectAnnotations: [{
|
|
2899
|
+
action: "created",
|
|
2900
|
+
...githubAnnotatedObject({
|
|
2901
|
+
repo: input.repo,
|
|
2902
|
+
number: result.number,
|
|
2903
|
+
id: result.id === void 0 ? void 0 : String(result.id),
|
|
2904
|
+
title: input.title,
|
|
2905
|
+
url: result.url,
|
|
2906
|
+
objectType: "task"
|
|
2907
|
+
})
|
|
2908
|
+
}],
|
|
2851
2909
|
target: "createIssue",
|
|
2852
2910
|
...data
|
|
2853
2911
|
};
|
|
@@ -2913,7 +2971,7 @@ async function createGitHubIssue(ctx, request) {
|
|
|
2913
2971
|
const issue = parsed;
|
|
2914
2972
|
if (typeof issue.number !== "number" || typeof issue.html_url !== "string") throw new Error("GitHub issue creation returned an invalid response.");
|
|
2915
2973
|
return {
|
|
2916
|
-
...
|
|
2974
|
+
...typeof issue.id === "number" ? { id: issue.id } : void 0,
|
|
2917
2975
|
number: issue.number,
|
|
2918
2976
|
url: issue.html_url
|
|
2919
2977
|
};
|
|
@@ -2936,9 +2994,7 @@ const gitHubIssueTool = definePluginTool({
|
|
|
2936
2994
|
const attempt = await ctx.state.withLock(`${key}:lock`, GITHUB_ISSUE_CREATE_LOCK_TTL_MS, async () => {
|
|
2937
2995
|
const state = createIssueState(await ctx.state.get(key));
|
|
2938
2996
|
if (state?.status === "completed") return await gitHubIssueToolResult(ctx, state.input ?? parsedInput, {
|
|
2939
|
-
|
|
2940
|
-
sourceUpdatedAt: state.sourceUpdatedAt,
|
|
2941
|
-
description: state.description,
|
|
2997
|
+
id: state.id,
|
|
2942
2998
|
number: state.number,
|
|
2943
2999
|
url: state.url
|
|
2944
3000
|
});
|
|
@@ -3520,7 +3576,6 @@ async function createGitHubPullRequest(ctx, request) {
|
|
|
3520
3576
|
const stackTarget = stackTargetSchema.safeParse(parsed);
|
|
3521
3577
|
return {
|
|
3522
3578
|
result: {
|
|
3523
|
-
...githubObjectFacts("code_change", parsed),
|
|
3524
3579
|
number: pullRequest.number,
|
|
3525
3580
|
url: pullRequest.html_url
|
|
3526
3581
|
},
|
|
@@ -3677,17 +3732,17 @@ function gitHubPullRequestToolResult(input, result, canSubscribe, omitSuggestedE
|
|
|
3677
3732
|
}
|
|
3678
3733
|
async function gitHubPullRequestStructuredResult(ctx, input, result, subscriptionConfig, stack) {
|
|
3679
3734
|
const base = gitHubPullRequestToolResult(input, result, ctx.events.canSubscribe);
|
|
3680
|
-
const objectAnnotations = [
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
}
|
|
3735
|
+
const objectAnnotations = [{
|
|
3736
|
+
action: "created",
|
|
3737
|
+
...githubAnnotatedObject({
|
|
3738
|
+
id: result.id,
|
|
3739
|
+
repo: input.repo,
|
|
3740
|
+
number: result.number,
|
|
3741
|
+
title: input.title,
|
|
3742
|
+
url: result.url,
|
|
3743
|
+
objectType: "code_change"
|
|
3744
|
+
})
|
|
3745
|
+
}];
|
|
3691
3746
|
if (!subscriptionConfig || !base.subscribable) return {
|
|
3692
3747
|
objectAnnotations,
|
|
3693
3748
|
target: "createPullRequest",
|
|
@@ -3757,9 +3812,7 @@ function createGitHubPullRequestTool(subscriptionConfig, descriptionChecks = fal
|
|
|
3757
3812
|
});
|
|
3758
3813
|
await saveNamedDraftReviewers(ctx, completedInput, state.number);
|
|
3759
3814
|
return await gitHubPullRequestStructuredResult(ctx, completedInput, {
|
|
3760
|
-
|
|
3761
|
-
sourceUpdatedAt: state.sourceUpdatedAt,
|
|
3762
|
-
description: state.description,
|
|
3815
|
+
id: state.pullRequestId,
|
|
3763
3816
|
number: state.number,
|
|
3764
3817
|
url: state.url
|
|
3765
3818
|
}, subscriptionConfig);
|
|
@@ -3790,10 +3843,7 @@ function createGitHubPullRequestTool(subscriptionConfig, descriptionChecks = fal
|
|
|
3790
3843
|
status: "completed",
|
|
3791
3844
|
number: result.number,
|
|
3792
3845
|
...pullRequestId === void 0 ? void 0 : { pullRequestId },
|
|
3793
|
-
url: result.url
|
|
3794
|
-
facts: result.facts,
|
|
3795
|
-
...result.sourceUpdatedAt === void 0 ? void 0 : { sourceUpdatedAt: result.sourceUpdatedAt },
|
|
3796
|
-
...result.description === void 0 ? void 0 : { description: result.description }
|
|
3846
|
+
url: result.url
|
|
3797
3847
|
};
|
|
3798
3848
|
try {
|
|
3799
3849
|
await ctx.state.set(key, completedState, GITHUB_PULL_REQUEST_CREATE_IDEMPOTENCY_TTL_MS);
|
|
@@ -3807,7 +3857,10 @@ function createGitHubPullRequestTool(subscriptionConfig, descriptionChecks = fal
|
|
|
3807
3857
|
await assignPullRequest(ctx, parsedInput, result, requester);
|
|
3808
3858
|
await requestPullRequestReviewers$1(ctx, parsedInput, result, requester);
|
|
3809
3859
|
const stack = stackTarget ? await stackGitHubPullRequest(ctx, stackTarget) : void 0;
|
|
3810
|
-
return await gitHubPullRequestStructuredResult(ctx, parsedInput,
|
|
3860
|
+
return await gitHubPullRequestStructuredResult(ctx, parsedInput, {
|
|
3861
|
+
...result,
|
|
3862
|
+
id: pullRequestId
|
|
3863
|
+
}, subscriptionConfig, stack);
|
|
3811
3864
|
});
|
|
3812
3865
|
if (!attempt.acquired) throw new Error("GitHub pull request creation for this tool call is already running; refusing to create a duplicate pull request.");
|
|
3813
3866
|
return attempt.value;
|
|
@@ -4022,11 +4075,12 @@ function truncate(text, maxLength) {
|
|
|
4022
4075
|
* Other Conversations that touched one pull request: working ones first,
|
|
4023
4076
|
* then newest activity.
|
|
4024
4077
|
*/
|
|
4025
|
-
async function readRelatedConversations(conversations,
|
|
4078
|
+
async function readRelatedConversations(conversations, subject, url) {
|
|
4026
4079
|
if (!conversations) return [];
|
|
4027
4080
|
return (await conversations.search({
|
|
4028
|
-
|
|
4029
|
-
|
|
4081
|
+
limit: RELATED_CONVERSATIONS_MAX,
|
|
4082
|
+
subject,
|
|
4083
|
+
url
|
|
4030
4084
|
})).map((match) => ({
|
|
4031
4085
|
conversation_id: match.conversationId,
|
|
4032
4086
|
...match.rootConversationId ? { root_conversation_id: match.rootConversationId } : void 0,
|
|
@@ -4066,12 +4120,13 @@ const gitHubGetPullRequestTool = definePluginTool({
|
|
|
4066
4120
|
sha: commitShaSchema
|
|
4067
4121
|
}),
|
|
4068
4122
|
html_url: z.string(),
|
|
4123
|
+
id: z.number().int(),
|
|
4069
4124
|
merged: z.boolean().optional().default(false),
|
|
4070
4125
|
number: z.number(),
|
|
4071
4126
|
state: z.string(),
|
|
4072
4127
|
title: z.string()
|
|
4073
4128
|
}).parse(response.body);
|
|
4074
|
-
const [checks, relatedConversations] = await Promise.all([readPullRequestChecks(ctx.egress, repo, providerResult.number), readRelatedConversations(ctx.conversations,
|
|
4129
|
+
const [checks, relatedConversations] = await Promise.all([readPullRequestChecks(ctx.egress, repo, providerResult.number), readRelatedConversations(ctx.conversations, pullRequestSubject(GITHUB_INBOX_SUBJECTS.pullRequest, String(providerResult.id)), providerResult.html_url)]);
|
|
4075
4130
|
const readiness = providerResult.draft && providerResult.state === "open" ? await readDraftReadiness(ctx.egress, repo, {
|
|
4076
4131
|
base: providerResult.base.ref,
|
|
4077
4132
|
number: providerResult.number
|
|
@@ -4357,6 +4412,7 @@ const providerIssueSchema = z.object({
|
|
|
4357
4412
|
assignees: z.array(z.object({ login: z.string() })).nullish().transform((assignees) => assignees?.map(({ login }) => login) ?? []),
|
|
4358
4413
|
body: z.string().nullable().optional().default(null),
|
|
4359
4414
|
html_url: z.string(),
|
|
4415
|
+
id: z.number().optional(),
|
|
4360
4416
|
number: z.number(),
|
|
4361
4417
|
state: z.string(),
|
|
4362
4418
|
title: z.string()
|
|
@@ -4425,15 +4481,17 @@ const gitHubUpdateIssueTool = definePluginTool({
|
|
|
4425
4481
|
repo: repo.ref
|
|
4426
4482
|
});
|
|
4427
4483
|
return {
|
|
4428
|
-
objectAnnotations: [
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4484
|
+
objectAnnotations: [{
|
|
4485
|
+
action: "changed",
|
|
4486
|
+
...githubAnnotatedObject({
|
|
4487
|
+
repo: repo.ref,
|
|
4488
|
+
number: providerResult.number,
|
|
4489
|
+
id: providerResult.id === void 0 ? void 0 : String(providerResult.id),
|
|
4490
|
+
title: providerResult.title,
|
|
4491
|
+
url: providerResult.html_url,
|
|
4492
|
+
objectType: "task"
|
|
4493
|
+
})
|
|
4494
|
+
}],
|
|
4437
4495
|
target: "updateIssue",
|
|
4438
4496
|
assignees: providerResult.assignees,
|
|
4439
4497
|
body: providerResult.body,
|
|
@@ -4669,6 +4727,7 @@ function createGitHubUpdatePullRequestTool(descriptionChecks = false) {
|
|
|
4669
4727
|
body: z.string().nullable().optional().default(null),
|
|
4670
4728
|
draft: z.boolean(),
|
|
4671
4729
|
html_url: z.string(),
|
|
4730
|
+
id: z.number().optional(),
|
|
4672
4731
|
merged: z.boolean(),
|
|
4673
4732
|
node_id: z.string().optional(),
|
|
4674
4733
|
number: z.number(),
|
|
@@ -4716,18 +4775,17 @@ function createGitHubUpdatePullRequestTool(descriptionChecks = false) {
|
|
|
4716
4775
|
url: providerResult.html_url
|
|
4717
4776
|
};
|
|
4718
4777
|
return {
|
|
4719
|
-
objectAnnotations: [
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
})],
|
|
4778
|
+
objectAnnotations: [{
|
|
4779
|
+
action: "changed",
|
|
4780
|
+
...githubAnnotatedObject({
|
|
4781
|
+
repo: repo.ref,
|
|
4782
|
+
number: providerResult.number,
|
|
4783
|
+
id: providerResult.id === void 0 ? void 0 : String(providerResult.id),
|
|
4784
|
+
title: providerResult.title,
|
|
4785
|
+
url: providerResult.html_url,
|
|
4786
|
+
objectType: "code_change"
|
|
4787
|
+
})
|
|
4788
|
+
}],
|
|
4731
4789
|
...reviewRequested !== void 0 ? { review_requested: reviewRequested } : void 0,
|
|
4732
4790
|
target: "updatePullRequest",
|
|
4733
4791
|
...data
|
|
@@ -5347,10 +5405,18 @@ function closeReason(state, previous, mergeAccess) {
|
|
|
5347
5405
|
reason: "Auto-merge is on.",
|
|
5348
5406
|
status: "dismissed"
|
|
5349
5407
|
};
|
|
5408
|
+
if (state.inMergeQueue) return {
|
|
5409
|
+
reason: "It is in the merge queue.",
|
|
5410
|
+
status: "done"
|
|
5411
|
+
};
|
|
5350
5412
|
if (mergeAccess === false) return {
|
|
5351
5413
|
reason: "Only a person with write access can merge it.",
|
|
5352
5414
|
status: "dismissed"
|
|
5353
5415
|
};
|
|
5416
|
+
if (state.baseOpen) return {
|
|
5417
|
+
reason: "It merges after the pull request below it.",
|
|
5418
|
+
status: "dismissed"
|
|
5419
|
+
};
|
|
5354
5420
|
return {
|
|
5355
5421
|
reason: "The pull request is no longer ready to merge.",
|
|
5356
5422
|
status: "dismissed"
|
|
@@ -5472,7 +5538,7 @@ function timeOf(at) {
|
|
|
5472
5538
|
*/
|
|
5473
5539
|
function nextAction(state, requester, saved) {
|
|
5474
5540
|
if (state.state !== "open") return {};
|
|
5475
|
-
const canMerge = requester.mergeAccess && !state.draft && !state.autoMerge && !state.reviewPending && !requester.feedback;
|
|
5541
|
+
const canMerge = requester.mergeAccess && !state.draft && !state.autoMerge && !state.inMergeQueue && !state.baseOpen && !state.reviewPending && !requester.feedback;
|
|
5476
5542
|
if (canMerge && state.mergeableState === "clean" && state.reviewOutcome !== "changesRequested") return { action: "merge" };
|
|
5477
5543
|
if (canMerge && !state.mergeableState && saved === "merge") return void 0;
|
|
5478
5544
|
const review = state.draft ? "review_draft" : "review";
|
|
@@ -5489,16 +5555,16 @@ function isRequested(state, login) {
|
|
|
5489
5555
|
/**
|
|
5490
5556
|
* Whether a pull request whose action is none is in limbo: it waits on
|
|
5491
5557
|
* nobody, so Junior asks for the requester's review on GitHub. It is open,
|
|
5492
|
-
* not a draft, and auto-merge is off. GitHub does
|
|
5493
|
-
* for a review, and the requester's feedback does
|
|
5494
|
-
* requester has not reviewed since the last push,
|
|
5495
|
-
* review. No reviewer approved it, so it does not
|
|
5496
|
-
* no reviewer requests changes, so Junior does not
|
|
5497
|
-
* not ask when the requester removed their own review
|
|
5498
|
-
* asked them since.
|
|
5558
|
+
* not a draft, not in the merge queue, and auto-merge is off. GitHub does
|
|
5559
|
+
* not ask the requester for a review, and the requester's feedback does
|
|
5560
|
+
* not wait for Junior. The requester has not reviewed since the last push,
|
|
5561
|
+
* other than a comment-only review. No reviewer approved it, so it does not
|
|
5562
|
+
* wait only on others, and no reviewer requests changes, so Junior does not
|
|
5563
|
+
* act next. Junior does not ask when the requester removed their own review
|
|
5564
|
+
* request and no one asked them since.
|
|
5499
5565
|
*/
|
|
5500
5566
|
function inLimbo(state, activity, login) {
|
|
5501
|
-
return state.state === "open" && !state.draft && !state.autoMerge && !isRequested(state, login) && !requesterFeedback(state, activity) && timeOf(activity.removedAt) <= timeOf(activity.askedAt) && timeOf(activity.actedAt) <= timeOf(state.headCommittedAt) && state.reviewOutcome === void 0;
|
|
5567
|
+
return state.state === "open" && !state.draft && !state.autoMerge && !state.inMergeQueue && !isRequested(state, login) && !requesterFeedback(state, activity) && timeOf(activity.removedAt) <= timeOf(activity.askedAt) && timeOf(activity.actedAt) <= timeOf(state.headCommittedAt) && state.reviewOutcome === void 0;
|
|
5502
5568
|
}
|
|
5503
5569
|
// src/pull-request-outcomes/store.ts
|
|
5504
5570
|
/** One pull request lifecycle outcome, as the webhook and reconcile read it. */
|
|
@@ -5634,20 +5700,28 @@ const timelineItemSchema = z.union([
|
|
|
5634
5700
|
createdAt: z.string()
|
|
5635
5701
|
}),
|
|
5636
5702
|
z.object({
|
|
5637
|
-
__typename: z.
|
|
5703
|
+
__typename: z.enum([
|
|
5704
|
+
"AutomaticBaseChangeSucceededEvent",
|
|
5705
|
+
"BaseRefChangedEvent",
|
|
5706
|
+
"HeadRefForcePushedEvent"
|
|
5707
|
+
]),
|
|
5638
5708
|
actor: actorSchema$1,
|
|
5639
5709
|
createdAt: z.string()
|
|
5640
5710
|
})
|
|
5641
5711
|
]);
|
|
5642
5712
|
const historyResponseSchema = z.object({ data: z.object({ repository: z.object({ pullRequest: z.object({
|
|
5713
|
+
baseChanges: z.object({ nodes: z.array(timelineItemSchema.nullable()) }),
|
|
5643
5714
|
createdAt: z.string(),
|
|
5644
5715
|
discussion: z.object({ nodes: z.array(timelineItemSchema.nullable()) }),
|
|
5645
5716
|
pushes: z.object({ nodes: z.array(timelineItemSchema.nullable()) }),
|
|
5646
5717
|
reviewDecision: z.string().nullable()
|
|
5647
5718
|
}) }) }) });
|
|
5648
5719
|
/**
|
|
5649
|
-
* Read the history from GitHub's answer. A deleted account
|
|
5650
|
-
*
|
|
5720
|
+
* Read the history from GitHub's answer. A deleted account counts as a
|
|
5721
|
+
* person, and a bot's activity is not activity. The opening counts, since a
|
|
5722
|
+
* person asked for it. So does a person's base change, such as the merge of
|
|
5723
|
+
* the PR below in a stack: its conflicts come from that merge, not from a
|
|
5724
|
+
* loop of fixes.
|
|
5651
5725
|
*/
|
|
5652
5726
|
function parseGitHubConflictHistory(response) {
|
|
5653
5727
|
const pullRequest = historyResponseSchema.parse(response).data.repository.pullRequest;
|
|
@@ -5655,12 +5729,18 @@ function parseGitHubConflictHistory(response) {
|
|
|
5655
5729
|
const record = (bot, at) => {
|
|
5656
5730
|
if (!bot && at) activeAtMs = Math.max(activeAtMs, Date.parse(at));
|
|
5657
5731
|
};
|
|
5658
|
-
for (const item of [
|
|
5732
|
+
for (const item of [
|
|
5733
|
+
...pullRequest.pushes.nodes,
|
|
5734
|
+
...pullRequest.discussion.nodes,
|
|
5735
|
+
...pullRequest.baseChanges.nodes
|
|
5736
|
+
]) {
|
|
5659
5737
|
if (!item) continue;
|
|
5660
5738
|
switch (item.__typename) {
|
|
5661
5739
|
case "PullRequestCommit":
|
|
5662
5740
|
record(item.commit.author?.user?.login?.endsWith("[bot]") === true, item.commit.committedDate);
|
|
5663
5741
|
break;
|
|
5742
|
+
case "AutomaticBaseChangeSucceededEvent":
|
|
5743
|
+
case "BaseRefChangedEvent":
|
|
5664
5744
|
case "HeadRefForcePushedEvent":
|
|
5665
5745
|
record(item.actor?.__typename === "Bot", item.createdAt);
|
|
5666
5746
|
break;
|
|
@@ -5891,6 +5971,7 @@ async function githubGraphqlRequest(params) {
|
|
|
5891
5971
|
* A webhook delivery has no Turn and no egress context, so these requests
|
|
5892
5972
|
* call GitHub directly. Other plugin code must use host egress.
|
|
5893
5973
|
*/
|
|
5974
|
+
/** Split `owner/name`, or throw an error that names the request. */
|
|
5894
5975
|
function splitRepository(fullName, label) {
|
|
5895
5976
|
const [owner, name, ...extra] = fullName.split("/");
|
|
5896
5977
|
if (!owner || !name || extra.length > 0) throw new Error(`GitHub ${label} received an invalid repository name`);
|
|
@@ -5960,6 +6041,60 @@ async function loadRepositoryFullNames(env) {
|
|
|
5960
6041
|
}
|
|
5961
6042
|
};
|
|
5962
6043
|
}
|
|
6044
|
+
const objectNameSchema = z.object({
|
|
6045
|
+
html_url: z.url(),
|
|
6046
|
+
id: z.number().int().positive(),
|
|
6047
|
+
pull_request: z.object({}).optional()
|
|
6048
|
+
});
|
|
6049
|
+
/**
|
|
6050
|
+
* Return reads of current names with one read-only token for every
|
|
6051
|
+
* repository of the installation. GitHub answers an old name of a renamed
|
|
6052
|
+
* repository with a redirect to its new place, which a read follows. A
|
|
6053
|
+
* read returns undefined when GitHub does not find the object, also when
|
|
6054
|
+
* the App cannot read it.
|
|
6055
|
+
*/
|
|
6056
|
+
async function loadGitHubObjectNames(env) {
|
|
6057
|
+
const token = await issueInstallationToken({
|
|
6058
|
+
...env,
|
|
6059
|
+
permissions: {
|
|
6060
|
+
issues: "read",
|
|
6061
|
+
metadata: "read",
|
|
6062
|
+
pull_requests: "read"
|
|
6063
|
+
}
|
|
6064
|
+
});
|
|
6065
|
+
const read = async (path, schema) => {
|
|
6066
|
+
try {
|
|
6067
|
+
return schema.parse(await githubRequest("https://api.github.com", path, { token: token.token }));
|
|
6068
|
+
} catch (error) {
|
|
6069
|
+
if (error instanceof GitHubRequestError && (error.status === 404 || error.status === 410)) return;
|
|
6070
|
+
throw error;
|
|
6071
|
+
}
|
|
6072
|
+
};
|
|
6073
|
+
const readOf = async (collection, ref) => await read(`/repos/${encodeURIComponent(ref.owner)}/${encodeURIComponent(ref.name)}/${collection}/${ref.number}`, objectNameSchema);
|
|
6074
|
+
return {
|
|
6075
|
+
async readObject(ref) {
|
|
6076
|
+
if (ref.kind === "issue") {
|
|
6077
|
+
const issue = await readOf("issues", ref);
|
|
6078
|
+
if (!issue) return void 0;
|
|
6079
|
+
if (!issue.pull_request) return {
|
|
6080
|
+
id: String(issue.id),
|
|
6081
|
+
kind: "issue",
|
|
6082
|
+
url: issue.html_url
|
|
6083
|
+
};
|
|
6084
|
+
}
|
|
6085
|
+
const pull = await readOf("pulls", ref);
|
|
6086
|
+
return pull && {
|
|
6087
|
+
id: String(pull.id),
|
|
6088
|
+
kind: "pull_request",
|
|
6089
|
+
url: pull.html_url
|
|
6090
|
+
};
|
|
6091
|
+
},
|
|
6092
|
+
async readRepositoryName(fullName) {
|
|
6093
|
+
const { owner, name } = splitRepository(fullName, "repository name");
|
|
6094
|
+
return (await read(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`, z.object({ full_name: z.string().min(1) })))?.full_name;
|
|
6095
|
+
}
|
|
6096
|
+
};
|
|
6097
|
+
}
|
|
5963
6098
|
/** GitHub cannot reach a repository: it is gone, or the installation lost it. */
|
|
5964
6099
|
var GitHubRepositoryUnreachableError = class extends Error {
|
|
5965
6100
|
constructor(repositoryId) {
|
|
@@ -6204,39 +6339,45 @@ const userLoginSchema = z.object({
|
|
|
6204
6339
|
__typename: z.string(),
|
|
6205
6340
|
login: z.string().min(1).optional()
|
|
6206
6341
|
}).nullable();
|
|
6207
|
-
const nextActionSchema = z.object({ data: z.object({ repository: z.object({
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6342
|
+
const nextActionSchema = z.object({ data: z.object({ repository: z.object({
|
|
6343
|
+
defaultBranchRef: z.object({ name: z.string() }).nullable(),
|
|
6344
|
+
pullRequest: z.object({
|
|
6345
|
+
autoMergeRequest: z.object({}).nullable(),
|
|
6346
|
+
baseRef: z.object({ associatedPullRequests: z.object({ totalCount: z.number() }) }).nullable(),
|
|
6347
|
+
baseRefName: z.string(),
|
|
6348
|
+
commits: z.object({ nodes: nodesSchema(z.object({ commit: z.object({ committedDate: timestampSchema$1 }) })) }),
|
|
6349
|
+
isDraft: z.boolean(),
|
|
6350
|
+
isInMergeQueue: z.boolean(),
|
|
6351
|
+
mergeStateStatus: z.string(),
|
|
6352
|
+
reviewRequests: z.object({ nodes: nodesSchema(z.object({ requestedReviewer: userLoginSchema })) }),
|
|
6353
|
+
reviews: reviewsSchema,
|
|
6354
|
+
state: z.enum([
|
|
6355
|
+
"CLOSED",
|
|
6356
|
+
"MERGED",
|
|
6357
|
+
"OPEN"
|
|
6358
|
+
]),
|
|
6359
|
+
timelineItems: z.object({ nodes: nodesSchema(z.discriminatedUnion("__typename", [
|
|
6360
|
+
z.object({
|
|
6361
|
+
__typename: z.literal("IssueComment"),
|
|
6362
|
+
author: actorSchema,
|
|
6363
|
+
createdAt: timestampSchema$1
|
|
6364
|
+
}),
|
|
6365
|
+
z.object({
|
|
6366
|
+
__typename: z.literal("ReviewRequestedEvent"),
|
|
6367
|
+
createdAt: timestampSchema$1,
|
|
6368
|
+
requestedReviewer: userLoginSchema
|
|
6369
|
+
}),
|
|
6370
|
+
z.object({
|
|
6371
|
+
__typename: z.literal("ReviewRequestRemovedEvent"),
|
|
6372
|
+
actor: actorSchema,
|
|
6373
|
+
createdAt: timestampSchema$1,
|
|
6374
|
+
requestedReviewer: userLoginSchema
|
|
6375
|
+
})
|
|
6376
|
+
])) }),
|
|
6377
|
+
title: z.string(),
|
|
6378
|
+
url: z.string().url()
|
|
6379
|
+
})
|
|
6380
|
+
}) }) });
|
|
6240
6381
|
const reviewsPageSchema = z.object({ data: z.object({ repository: z.object({ pullRequest: z.object({ reviews: reviewsSchema }) }) }) });
|
|
6241
6382
|
function restLogin(actor) {
|
|
6242
6383
|
return actor.__typename === "Bot" ? `${actor.login}[bot]` : actor.login;
|
|
@@ -6272,11 +6413,12 @@ async function loadPullRequestMergeState(env, pullRequest, requesterLogin) {
|
|
|
6272
6413
|
},
|
|
6273
6414
|
token: token.token
|
|
6274
6415
|
});
|
|
6275
|
-
const
|
|
6276
|
-
|
|
6416
|
+
const readRepository = async () => nextActionSchema.parse(await query(PULL_REQUEST_NEXT_ACTION)).data.repository;
|
|
6417
|
+
const repository = await readRepository();
|
|
6418
|
+
let pull = repository.pullRequest;
|
|
6277
6419
|
const open = pull.state === "OPEN" && !pull.isDraft;
|
|
6278
6420
|
const unknown = (status) => status === "UNKNOWN";
|
|
6279
|
-
if (open && !pull.autoMergeRequest && unknown(pull.mergeStateStatus)) pull = await
|
|
6421
|
+
if (open && !pull.autoMergeRequest && unknown(pull.mergeStateStatus)) pull = (await readRepository()).pullRequest;
|
|
6280
6422
|
const reviews = [...pull.reviews.nodes];
|
|
6281
6423
|
let page = pull.reviews.pageInfo;
|
|
6282
6424
|
while (open && page.hasPreviousPage && page.startCursor) {
|
|
@@ -6311,8 +6453,10 @@ async function loadPullRequestMergeState(env, pullRequest, requesterLogin) {
|
|
|
6311
6453
|
const state = {
|
|
6312
6454
|
activity,
|
|
6313
6455
|
autoMerge: Boolean(pull.autoMergeRequest),
|
|
6456
|
+
baseOpen: pull.baseRefName !== repository.defaultBranchRef?.name && (pull.baseRef?.associatedPullRequests.totalCount ?? 0) > 0,
|
|
6314
6457
|
draft: pull.isDraft,
|
|
6315
6458
|
...headCommittedAt ? { headCommittedAt: new Date(headCommittedAt) } : void 0,
|
|
6459
|
+
inMergeQueue: pull.isInMergeQueue,
|
|
6316
6460
|
...mergeableState ? { mergeableState } : void 0,
|
|
6317
6461
|
requesterApproved: false,
|
|
6318
6462
|
requestedReviewers: pull.reviewRequests.nodes.flatMap((request) => request.requestedReviewer?.__typename === "User" && request.requestedReviewer.login ? [request.requestedReviewer.login] : []),
|
|
@@ -6349,6 +6493,9 @@ const ACTION_EVENTS = {
|
|
|
6349
6493
|
"auto_merge_enabled",
|
|
6350
6494
|
"closed",
|
|
6351
6495
|
"converted_to_draft",
|
|
6496
|
+
"dequeued",
|
|
6497
|
+
"edited",
|
|
6498
|
+
"enqueued",
|
|
6352
6499
|
"ready_for_review",
|
|
6353
6500
|
"reopened",
|
|
6354
6501
|
"review_request_removed",
|
|
@@ -6360,6 +6507,7 @@ const ACTION_EVENTS = {
|
|
|
6360
6507
|
const repositorySchema$3 = z.object({ full_name: z.string().min(1) });
|
|
6361
6508
|
const pullRequestWebhookSchema = z.object({
|
|
6362
6509
|
action: z.string(),
|
|
6510
|
+
changes: z.object({ base: z.unknown().optional() }).optional(),
|
|
6363
6511
|
pull_request: z.object({ number: z.number().int().positive() }),
|
|
6364
6512
|
repository: repositorySchema$3,
|
|
6365
6513
|
requested_reviewer: z.object({ login: z.string().min(1) }).nullish()
|
|
@@ -6374,7 +6522,7 @@ const commentWebhookSchema = z.object({
|
|
|
6374
6522
|
pull_request: z.object({ number: z.number().int().positive() }).optional(),
|
|
6375
6523
|
repository: repositorySchema$3
|
|
6376
6524
|
});
|
|
6377
|
-
/** Return the pull requests whose next action one webhook
|
|
6525
|
+
/** Return the pull requests whose next action one webhook can change. */
|
|
6378
6526
|
function pullRequestActionTargets(eventName, body) {
|
|
6379
6527
|
if (eventName === "check_suite") return checkSuitePullRequests(body);
|
|
6380
6528
|
if (eventName === "issue_comment" || eventName === "pull_request_review_comment") {
|
|
@@ -6391,7 +6539,7 @@ function pullRequestActionTargets(eventName, body) {
|
|
|
6391
6539
|
}
|
|
6392
6540
|
const actions = ACTION_EVENTS[eventName];
|
|
6393
6541
|
const parsed = pullRequestWebhookSchema.safeParse(body);
|
|
6394
|
-
if (!actions || !parsed.success || !actions.has(parsed.data.action)) return [];
|
|
6542
|
+
if (!actions || !parsed.success || !actions.has(parsed.data.action) || parsed.data.action === "edited" && !parsed.data.changes?.base) return [];
|
|
6395
6543
|
const reviewer = parsed.data.action === "review_requested" ? parsed.data.requested_reviewer?.login : void 0;
|
|
6396
6544
|
return [{
|
|
6397
6545
|
number: parsed.data.pull_request.number,
|
|
@@ -6446,12 +6594,10 @@ async function requestReviewAgain(args, target, login) {
|
|
|
6446
6594
|
}
|
|
6447
6595
|
}
|
|
6448
6596
|
/**
|
|
6449
|
-
* Ask the reviewer of a held review ask again once the required checks
|
|
6450
|
-
*
|
|
6451
|
-
*
|
|
6452
|
-
*
|
|
6453
|
-
* reviewer commented or reviewed since, or when their change request is no
|
|
6454
|
-
* longer ready.
|
|
6597
|
+
* Ask the reviewer of a held review ask again once the required checks pass,
|
|
6598
|
+
* and return their login and the reason. Keep the hold until the checks pass
|
|
6599
|
+
* and GitHub takes the request. Drop it when the PR ended, the reviewer acted
|
|
6600
|
+
* since, or their change request is no longer ready.
|
|
6455
6601
|
*/
|
|
6456
6602
|
async function askHeldReview(args, target, state, requesterLogin) {
|
|
6457
6603
|
const held = await readHeldGitHubReviewAsk(args.state, target);
|
|
@@ -6643,12 +6789,11 @@ async function retryAfterFailure(env, target, error) {
|
|
|
6643
6789
|
return error instanceof GitHubRequestError && error.status >= 500 ? {} : void 0;
|
|
6644
6790
|
}
|
|
6645
6791
|
/**
|
|
6646
|
-
* Add, change, or close the item of each Junior pull request that
|
|
6647
|
-
*
|
|
6648
|
-
*
|
|
6649
|
-
*
|
|
6650
|
-
*
|
|
6651
|
-
* That webhook checks them again, but without `askAfterRequesterActed`.
|
|
6792
|
+
* Add, change, or close the item of each Junior pull request that a webhook
|
|
6793
|
+
* delivery can change. The item is optional, so failures are logged, and one
|
|
6794
|
+
* that GitHub causes for a while starts a sync task when `tasks` is given.
|
|
6795
|
+
* Return the pull requests that another webhook was checking, which it checks
|
|
6796
|
+
* again without `askAfterRequesterActed`.
|
|
6652
6797
|
*/
|
|
6653
6798
|
async function syncGitHubPullRequestActions(args) {
|
|
6654
6799
|
const busy = [];
|
|
@@ -6697,7 +6842,6 @@ function startedTaskSyncContext(ctx, options) {
|
|
|
6697
6842
|
db: gitHubDbSchema.parse(ctx.db),
|
|
6698
6843
|
env: {
|
|
6699
6844
|
...options.env,
|
|
6700
|
-
responses: ctx.state,
|
|
6701
6845
|
tokens: /* @__PURE__ */ new Map()
|
|
6702
6846
|
},
|
|
6703
6847
|
findLinkedIdentityIds: async (logins) => await ctx.users.findLinkedIdentityIds(logins),
|
|
@@ -6761,12 +6905,10 @@ function githubCodeChange(outcome) {
|
|
|
6761
6905
|
}
|
|
6762
6906
|
/**
|
|
6763
6907
|
* Record one pull request outcome. When the stored row changes, update the
|
|
6764
|
-
* code index. A merged or closed pull request then
|
|
6765
|
-
* conversation that asked for it
|
|
6766
|
-
*
|
|
6767
|
-
*
|
|
6768
|
-
* conversation id breaks only its own chip. The chips and items are optional UI, so a
|
|
6769
|
-
* failed write is logged and does not stop the work after it.
|
|
6908
|
+
* code index. A merged or closed pull request then closes the Inbox items
|
|
6909
|
+
* of the conversation that asked for it in one batch. The items are
|
|
6910
|
+
* optional UI, so a failed write is logged and does not stop the work after
|
|
6911
|
+
* it.
|
|
6770
6912
|
*/
|
|
6771
6913
|
async function applyGitHubPullRequestOutcome(args) {
|
|
6772
6914
|
const { outcome } = args;
|
|
@@ -6785,34 +6927,12 @@ async function applyGitHubPullRequestOutcome(args) {
|
|
|
6785
6927
|
numbers: [outcome.number],
|
|
6786
6928
|
repositoryFullName: outcome.repositoryFullName
|
|
6787
6929
|
});
|
|
6788
|
-
if (
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6930
|
+
if (ended) try {
|
|
6931
|
+
await args.conversationChanges.apply({ inboxItems: ended.inboxItems });
|
|
6932
|
+
} catch (error) {
|
|
6933
|
+
logFailOpenFailure(args.log, "GitHub ended pull request change failed", error, {
|
|
6792
6934
|
number: outcome.number,
|
|
6793
|
-
|
|
6794
|
-
status: state
|
|
6795
|
-
};
|
|
6796
|
-
if (ended) try {
|
|
6797
|
-
await args.conversationChanges.apply({
|
|
6798
|
-
annotations: conversationIds.includes(ended.conversationId) ? [await githubAnnotationChange({
|
|
6799
|
-
annotations: args.annotations,
|
|
6800
|
-
conversationId: ended.conversationId,
|
|
6801
|
-
update
|
|
6802
|
-
})] : [],
|
|
6803
|
-
inboxItems: ended.inboxItems
|
|
6804
|
-
});
|
|
6805
|
-
} catch (error) {
|
|
6806
|
-
logFailOpenFailure(args.log, "GitHub ended pull request change failed", error, {
|
|
6807
|
-
number: outcome.number,
|
|
6808
|
-
repository: outcome.repositoryFullName
|
|
6809
|
-
});
|
|
6810
|
-
}
|
|
6811
|
-
await updateGitHubAnnotations({
|
|
6812
|
-
annotations: args.annotations,
|
|
6813
|
-
conversationIds: conversationIds.filter((id) => id !== ended?.conversationId),
|
|
6814
|
-
log: args.log,
|
|
6815
|
-
update
|
|
6935
|
+
repository: outcome.repositoryFullName
|
|
6816
6936
|
});
|
|
6817
6937
|
}
|
|
6818
6938
|
return recorded;
|
|
@@ -6866,7 +6986,7 @@ async function publishGitHubConflictResolved(args) {
|
|
|
6866
6986
|
// src/pull-request-patches.ts
|
|
6867
6987
|
const GITHUB_PULL_REQUEST_PATCH_TASK = "patchPullRequest";
|
|
6868
6988
|
const PATCH_DELAY_SECONDS = 5;
|
|
6869
|
-
const payloadSchema$
|
|
6989
|
+
const payloadSchema$4 = z.object({
|
|
6870
6990
|
/** Cache entry `pulls:owner/repo#N`. */
|
|
6871
6991
|
key: z.string().min(1),
|
|
6872
6992
|
/** Head commit of the event. */
|
|
@@ -6900,10 +7020,12 @@ async function startGitHubPullRequestPatch(args) {
|
|
|
6900
7020
|
}
|
|
6901
7021
|
});
|
|
6902
7022
|
}
|
|
7023
|
+
const headFactsNodeSchema = pullRequestHeadFactsNodeSchema.extend({ databaseId: z.number().int().positive().nullish() });
|
|
6903
7024
|
async function writeHeadFacts(cache, key, node, last) {
|
|
6904
7025
|
const mergeable = githubMergeable(node.mergeable);
|
|
6905
7026
|
let outcome = "done";
|
|
6906
7027
|
let written = false;
|
|
7028
|
+
let changed = false;
|
|
6907
7029
|
await cache.update(key, (current) => {
|
|
6908
7030
|
if (!current) return void 0;
|
|
6909
7031
|
if (current.head?.sha !== node.headRefOid) {
|
|
@@ -6917,16 +7039,19 @@ async function writeHeadFacts(cache, key, node, last) {
|
|
|
6917
7039
|
const computing = mergeable === null && current.mergeable === "pending";
|
|
6918
7040
|
if (computing && !last) outcome = "again";
|
|
6919
7041
|
written = true;
|
|
7042
|
+
const value = {
|
|
7043
|
+
...current,
|
|
7044
|
+
checks: githubCheckCounts(node.commits),
|
|
7045
|
+
mergeable: mergeable ?? current.mergeable
|
|
7046
|
+
};
|
|
7047
|
+
changed = JSON.stringify([current.checks, current.mergeable]) !== JSON.stringify([value.checks, value.mergeable]);
|
|
6920
7048
|
return {
|
|
6921
7049
|
...computing && last ? GITHUB_PULL_REQUEST_PENDING_CACHE : GITHUB_PULL_REQUEST_CACHE,
|
|
6922
|
-
value
|
|
6923
|
-
...current,
|
|
6924
|
-
checks: githubCheckCounts(node.commits),
|
|
6925
|
-
mergeable: mergeable ?? current.mergeable
|
|
6926
|
-
}
|
|
7050
|
+
value
|
|
6927
7051
|
};
|
|
6928
7052
|
});
|
|
6929
7053
|
return {
|
|
7054
|
+
changed,
|
|
6930
7055
|
outcome,
|
|
6931
7056
|
written
|
|
6932
7057
|
};
|
|
@@ -6965,11 +7090,11 @@ async function expirePending(cache, key) {
|
|
|
6965
7090
|
* that GitHub still computes stays pending only briefly, so the next read
|
|
6966
7091
|
* asks GitHub. A pull request missing from the answer, of another head
|
|
6967
7092
|
* commit, or whose query fails on the last delivery, leaves its pending
|
|
6968
|
-
* fields fresh only briefly too.
|
|
7093
|
+
* fields fresh only briefly too. A change calls `objectChanged`.
|
|
6969
7094
|
*/
|
|
6970
7095
|
function githubPullRequestPatchTask(loadHeadFacts) {
|
|
6971
7096
|
return {
|
|
6972
|
-
payload: payloadSchema$
|
|
7097
|
+
payload: payloadSchema$4,
|
|
6973
7098
|
async run(ctx) {
|
|
6974
7099
|
const { key, sha } = ctx.payload;
|
|
6975
7100
|
const ref = pullRequestRefFromCacheKey(key);
|
|
@@ -6978,13 +7103,17 @@ function githubPullRequestPatchTask(loadHeadFacts) {
|
|
|
6978
7103
|
if (cached && cached.head?.sha !== sha) return;
|
|
6979
7104
|
let node;
|
|
6980
7105
|
try {
|
|
6981
|
-
[node] = aliasedPullRequests(await loadHeadFacts([ref]), 1,
|
|
7106
|
+
[node] = aliasedPullRequests(await loadHeadFacts([ref]), 1, headFactsNodeSchema);
|
|
6982
7107
|
} catch (error) {
|
|
6983
7108
|
if (ctx.lastDelivery) await expirePending(ctx.cache, key);
|
|
6984
7109
|
throw error;
|
|
6985
7110
|
}
|
|
6986
7111
|
const write = node ? await writeHeadFacts(ctx.cache, key, node, ctx.lastDelivery) : void 0;
|
|
6987
7112
|
if (node && write?.written) await observeMergeState(ctx, ref, node);
|
|
7113
|
+
if (node?.databaseId && write?.changed) await ctx.annotations.objectChanged({
|
|
7114
|
+
id: String(node.databaseId),
|
|
7115
|
+
kind: GITHUB_INBOX_SUBJECTS.pullRequest
|
|
7116
|
+
});
|
|
6988
7117
|
const outcome = write?.outcome ?? "expire";
|
|
6989
7118
|
if (outcome === "again" && !ctx.lastDelivery) throw new GitHubPullRequestPatchPendingError(key, sha);
|
|
6990
7119
|
if (outcome !== "done") await expirePending(ctx.cache, key);
|
|
@@ -6993,7 +7122,7 @@ function githubPullRequestPatchTask(loadHeadFacts) {
|
|
|
6993
7122
|
}
|
|
6994
7123
|
// src/webhooks/object-cache.ts
|
|
6995
7124
|
const repositorySchema$2 = z.object({ full_name: z.string().min(1) });
|
|
6996
|
-
const issueEventSchema = z.object({
|
|
7125
|
+
const issueEventSchema$1 = z.object({
|
|
6997
7126
|
action: z.string().optional(),
|
|
6998
7127
|
issue: githubIssueFieldsSchema,
|
|
6999
7128
|
repository: repositorySchema$2
|
|
@@ -7012,7 +7141,10 @@ const REVIEW_ACTIONS = {
|
|
|
7012
7141
|
pull_request: /* @__PURE__ */ new Set(["review_requested", "review_request_removed"]),
|
|
7013
7142
|
pull_request_review: /* @__PURE__ */ new Set(["dismissed", "submitted"])
|
|
7014
7143
|
};
|
|
7015
|
-
const checkPullRequestsSchema = z.array(z.object({
|
|
7144
|
+
const checkPullRequestsSchema = z.array(z.object({
|
|
7145
|
+
id: z.number().int().positive().optional(),
|
|
7146
|
+
number: z.number().int().positive()
|
|
7147
|
+
}));
|
|
7016
7148
|
const checkSuiteEventSchema = z.object({
|
|
7017
7149
|
check_suite: z.object({
|
|
7018
7150
|
head_sha: z.string().min(1),
|
|
@@ -7031,26 +7163,42 @@ const GONE_TTL_MS = 2592e5;
|
|
|
7031
7163
|
function goneKey(key) {
|
|
7032
7164
|
return `gone:${key}`;
|
|
7033
7165
|
}
|
|
7166
|
+
const objectIdSchema = z.object({ id: z.number().int().positive() });
|
|
7167
|
+
function webhookSubject(body, field) {
|
|
7168
|
+
const parsed = z.object({ [field]: objectIdSchema }).safeParse(body);
|
|
7169
|
+
if (!parsed.success) return void 0;
|
|
7170
|
+
return {
|
|
7171
|
+
id: String(parsed.data[field].id),
|
|
7172
|
+
kind: field === "issue" ? GITHUB_INBOX_SUBJECTS.issue : GITHUB_INBOX_SUBJECTS.pullRequest
|
|
7173
|
+
};
|
|
7174
|
+
}
|
|
7175
|
+
function sameValue(current, next) {
|
|
7176
|
+
return JSON.stringify(current ?? null) === JSON.stringify(next ?? null);
|
|
7177
|
+
}
|
|
7034
7178
|
async function refreshPullRequest(args, event) {
|
|
7035
7179
|
const { action = "", pull_request: payload, repository } = event;
|
|
7036
7180
|
const reviewChanged = REVIEW_ACTIONS.pull_request.has(action);
|
|
7037
7181
|
const key = githubObjectCacheKey("pulls", repository.full_name, payload.number);
|
|
7038
7182
|
let patch = false;
|
|
7039
7183
|
let conflicted = false;
|
|
7184
|
+
let changed = false;
|
|
7040
7185
|
if (reviewChanged) await markGitHubReviewCleared(args.cache, key);
|
|
7041
7186
|
await args.cache.update(key, (current) => {
|
|
7042
7187
|
const merged = mergeGitHubPullRequest(current, payload);
|
|
7043
7188
|
patch = merged?.patch ?? false;
|
|
7044
7189
|
conflicted = merged?.fields.state === "open" && (payload.mergeable === false || patch && current?.mergeable === false);
|
|
7045
|
-
|
|
7190
|
+
const value = merged ? {
|
|
7046
7191
|
...GITHUB_PULL_REQUEST_CACHE,
|
|
7047
7192
|
value: reviewChanged ? withoutGitHubReview(merged.fields) : merged.fields
|
|
7048
|
-
}
|
|
7049
|
-
return reviewChanged && current?.review !== void 0 ? {
|
|
7193
|
+
} : reviewChanged && current?.review !== void 0 ? {
|
|
7050
7194
|
...GITHUB_PULL_REQUEST_CACHE,
|
|
7051
7195
|
value: withoutGitHubReview(current)
|
|
7052
7196
|
} : void 0;
|
|
7197
|
+
changed = Boolean(value) && !sameValue(current, value?.value);
|
|
7198
|
+
return value;
|
|
7053
7199
|
});
|
|
7200
|
+
const subject = webhookSubject(args.body, "pull_request");
|
|
7201
|
+
if (changed && subject) await args.objectChanged(subject);
|
|
7054
7202
|
if (conflicted) await markGitHubConflict(args.state, {
|
|
7055
7203
|
number: payload.number,
|
|
7056
7204
|
repositoryFullName: repository.full_name
|
|
@@ -7063,12 +7211,14 @@ async function refreshPullRequest(args, event) {
|
|
|
7063
7211
|
tasks: args.tasks
|
|
7064
7212
|
});
|
|
7065
7213
|
}
|
|
7066
|
-
async function refreshChecks(args,
|
|
7067
|
-
for (const key of
|
|
7214
|
+
async function refreshChecks(args, pulls, sha) {
|
|
7215
|
+
for (const { key, subject } of pulls) {
|
|
7068
7216
|
let patch = false;
|
|
7217
|
+
let changed = false;
|
|
7069
7218
|
await args.cache.update(key, (current) => {
|
|
7070
7219
|
if (current?.state !== "open" || current.head?.sha !== sha) return void 0;
|
|
7071
7220
|
patch = true;
|
|
7221
|
+
changed = current.checks !== "pending";
|
|
7072
7222
|
return {
|
|
7073
7223
|
...GITHUB_PULL_REQUEST_CACHE,
|
|
7074
7224
|
value: {
|
|
@@ -7077,6 +7227,7 @@ async function refreshChecks(args, keys, sha) {
|
|
|
7077
7227
|
}
|
|
7078
7228
|
};
|
|
7079
7229
|
});
|
|
7230
|
+
if (changed && subject) await args.objectChanged(subject);
|
|
7080
7231
|
if (patch) await startGitHubPullRequestPatch({
|
|
7081
7232
|
key,
|
|
7082
7233
|
nowMs: args.nowMs,
|
|
@@ -7091,17 +7242,23 @@ function checkEventTarget(body, eventName) {
|
|
|
7091
7242
|
const { repository } = event.data;
|
|
7092
7243
|
const check = "check_suite" in event.data ? event.data.check_suite : event.data.check_run;
|
|
7093
7244
|
return {
|
|
7094
|
-
|
|
7245
|
+
pulls: check.pull_requests.map((pull) => ({
|
|
7246
|
+
key: githubObjectCacheKey("pulls", repository.full_name, pull.number),
|
|
7247
|
+
...pull.id && { subject: {
|
|
7248
|
+
id: String(pull.id),
|
|
7249
|
+
kind: GITHUB_INBOX_SUBJECTS.pullRequest
|
|
7250
|
+
} }
|
|
7251
|
+
})),
|
|
7095
7252
|
sha: check.head_sha
|
|
7096
7253
|
};
|
|
7097
7254
|
}
|
|
7098
7255
|
/**
|
|
7099
7256
|
* Write the issue or pull request of an `issues` or `pull_request` webhook
|
|
7100
|
-
* into its cache entry, so the next card read
|
|
7101
|
-
*
|
|
7102
|
-
*
|
|
7103
|
-
*
|
|
7104
|
-
*
|
|
7257
|
+
* into its cache entry, so the next card read needs no GitHub call. A
|
|
7258
|
+
* webhook that can change the review decision clears it. A check webhook
|
|
7259
|
+
* marks its pull requests' checks pending, which gets a patch
|
|
7260
|
+
* (`pull-request-patches.ts`). A write that changes an entry calls
|
|
7261
|
+
* `objectChanged`.
|
|
7105
7262
|
*/
|
|
7106
7263
|
async function refreshGitHubObjectCache(args) {
|
|
7107
7264
|
if (args.eventName === "pull_request") {
|
|
@@ -7115,19 +7272,28 @@ async function refreshGitHubObjectCache(args) {
|
|
|
7115
7272
|
if (!REVIEW_ACTIONS.pull_request_review.has(event.data.action ?? "")) return;
|
|
7116
7273
|
const key = githubObjectCacheKey("pulls", event.data.repository.full_name, event.data.pull_request.number);
|
|
7117
7274
|
await markGitHubReviewCleared(args.cache, key);
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7275
|
+
let changed = false;
|
|
7276
|
+
await args.cache.update(key, (current) => {
|
|
7277
|
+
if (current?.review === void 0) return void 0;
|
|
7278
|
+
changed = true;
|
|
7279
|
+
return {
|
|
7280
|
+
...GITHUB_PULL_REQUEST_CACHE,
|
|
7281
|
+
value: withoutGitHubReview(current)
|
|
7282
|
+
};
|
|
7121
7283
|
});
|
|
7284
|
+
const subject = webhookSubject(args.body, "pull_request");
|
|
7285
|
+
if (changed && subject) await args.objectChanged(subject);
|
|
7122
7286
|
return;
|
|
7123
7287
|
}
|
|
7124
7288
|
if (args.eventName === "issues") {
|
|
7125
|
-
const event = issueEventSchema.safeParse(args.body);
|
|
7289
|
+
const event = issueEventSchema$1.safeParse(args.body);
|
|
7126
7290
|
if (!event.success) return;
|
|
7127
7291
|
const { action, issue, repository } = event.data;
|
|
7128
7292
|
const key = githubObjectCacheKey("issues", repository.full_name, issue.number);
|
|
7293
|
+
const subject = webhookSubject(args.body, "issue");
|
|
7129
7294
|
if (action === "transferred") {
|
|
7130
7295
|
await args.cache.delete(key);
|
|
7296
|
+
if (subject) await args.objectChanged(subject);
|
|
7131
7297
|
return;
|
|
7132
7298
|
}
|
|
7133
7299
|
if (action === "deleted") {
|
|
@@ -7136,20 +7302,24 @@ async function refreshGitHubObjectCache(args) {
|
|
|
7136
7302
|
ttlMs: GONE_TTL_MS,
|
|
7137
7303
|
value: null
|
|
7138
7304
|
}));
|
|
7305
|
+
if (subject) await args.objectChanged(subject);
|
|
7139
7306
|
return;
|
|
7140
7307
|
}
|
|
7141
7308
|
if (await args.state.get(goneKey(key))) return;
|
|
7309
|
+
let changed = false;
|
|
7142
7310
|
await args.cache.update(key, (current) => {
|
|
7143
7311
|
const value = mergeGitHubObject(current, issue);
|
|
7312
|
+
changed = Boolean(value) && !sameValue(current, value);
|
|
7144
7313
|
return value && {
|
|
7145
7314
|
...GITHUB_ISSUE_CACHE,
|
|
7146
7315
|
value
|
|
7147
7316
|
};
|
|
7148
7317
|
});
|
|
7318
|
+
if (changed && subject) await args.objectChanged(subject);
|
|
7149
7319
|
return;
|
|
7150
7320
|
}
|
|
7151
7321
|
const target = checkEventTarget(args.body, args.eventName);
|
|
7152
|
-
if (target) await refreshChecks(args, target.
|
|
7322
|
+
if (target) await refreshChecks(args, target.pulls, target.sha);
|
|
7153
7323
|
}
|
|
7154
7324
|
// src/pull-request-outcomes/apply-task.ts
|
|
7155
7325
|
const GITHUB_PULL_REQUEST_OUTCOME_TASK = "applyPullRequestOutcome";
|
|
@@ -7164,12 +7334,11 @@ const pullRequestOutcomePayloadSchema = githubPullRequestOutcomeInputSchema.exte
|
|
|
7164
7334
|
function githubPullRequestOutcomeTaskKey(outcome) {
|
|
7165
7335
|
return `pull-request-outcome:${outcome.pullRequestId}:${outcome.state}:${outcome.updatedAt.toISOString()}`;
|
|
7166
7336
|
}
|
|
7167
|
-
/** Apply the outcome in the task payload. The outcome row, code index,
|
|
7337
|
+
/** Apply the outcome in the task payload. The outcome row, code index, and Inbox closes all repeat safely. */
|
|
7168
7338
|
const githubPullRequestOutcomeTask = {
|
|
7169
7339
|
payload: pullRequestOutcomePayloadSchema,
|
|
7170
7340
|
async run(ctx) {
|
|
7171
7341
|
await applyGitHubPullRequestOutcome({
|
|
7172
|
-
annotations: ctx.annotations,
|
|
7173
7342
|
codeChanges: ctx.codeChanges,
|
|
7174
7343
|
conversationChanges: ctx.conversationChanges,
|
|
7175
7344
|
db: gitHubDbSchema.parse(ctx.db),
|
|
@@ -7178,49 +7347,120 @@ const githubPullRequestOutcomeTask = {
|
|
|
7178
7347
|
});
|
|
7179
7348
|
}
|
|
7180
7349
|
};
|
|
7181
|
-
// src/webhooks/issue-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7350
|
+
// src/webhooks/issue-item.ts
|
|
7351
|
+
/**
|
|
7352
|
+
* The Inbox item of an issue that Junior created, for its linked assignees.
|
|
7353
|
+
* `design/github.md` says when it opens and closes. Only Conversations that
|
|
7354
|
+
* the issue footer names are read as its owner, and core checks the owner
|
|
7355
|
+
* from every stored card, so an edited footer cannot move the item.
|
|
7356
|
+
*/
|
|
7357
|
+
const FOOTER_READ_CONCURRENCY = 4;
|
|
7358
|
+
const ITEM_ACTIONS = /* @__PURE__ */ new Set([
|
|
7359
|
+
"assigned",
|
|
7360
|
+
"closed",
|
|
7361
|
+
"deleted",
|
|
7362
|
+
"reopened",
|
|
7363
|
+
"transferred",
|
|
7364
|
+
"unassigned"
|
|
7365
|
+
]);
|
|
7366
|
+
const GONE_ACTIONS = /* @__PURE__ */ new Set(["deleted", "transferred"]);
|
|
7367
|
+
const login$1 = z.object({ login: z.string().min(1) });
|
|
7368
|
+
const issueEventSchema = z.object({
|
|
7192
7369
|
action: z.string(),
|
|
7370
|
+
assignee: login$1.nullish(),
|
|
7193
7371
|
issue: z.object({
|
|
7194
|
-
|
|
7372
|
+
assignees: z.array(login$1).nullish(),
|
|
7373
|
+
body: z.string().nullish(),
|
|
7374
|
+
html_url: z.string(),
|
|
7375
|
+
id: z.number().int().positive(),
|
|
7195
7376
|
number: z.number().int().positive(),
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
})
|
|
7200
|
-
|
|
7201
|
-
issue: {
|
|
7202
|
-
body: provider.issue.body,
|
|
7203
|
-
number: provider.issue.number,
|
|
7204
|
-
user: { login: provider.issue.user.login }
|
|
7205
|
-
},
|
|
7206
|
-
repository: { full_name: provider.repository.full_name }
|
|
7207
|
-
}));
|
|
7377
|
+
pull_request: z.unknown().optional(),
|
|
7378
|
+
state: z.string(),
|
|
7379
|
+
user: login$1
|
|
7380
|
+
})
|
|
7381
|
+
});
|
|
7208
7382
|
/**
|
|
7209
|
-
* Read
|
|
7210
|
-
*
|
|
7211
|
-
* action or issue.
|
|
7383
|
+
* Read an `issues` webhook that changes the item of an issue that Junior
|
|
7384
|
+
* created. Undefined for any other action or issue.
|
|
7212
7385
|
*/
|
|
7213
|
-
function
|
|
7214
|
-
const parsed =
|
|
7215
|
-
if (!parsed.success || parsed.data.action
|
|
7216
|
-
const {
|
|
7386
|
+
function normalizeGitHubIssueItemEvent(args) {
|
|
7387
|
+
const parsed = issueEventSchema.safeParse(args.body);
|
|
7388
|
+
if (!parsed.success || !ITEM_ACTIONS.has(parsed.data.action)) return;
|
|
7389
|
+
const { action, assignee, issue } = parsed.data;
|
|
7390
|
+
if (issue.pull_request !== void 0) return void 0;
|
|
7217
7391
|
if (!isBotLogin(issue.user.login, args.botEmail)) return void 0;
|
|
7218
7392
|
const conversationIds = githubConversationIds(issue.body);
|
|
7219
|
-
|
|
7393
|
+
if (conversationIds.length === 0) return void 0;
|
|
7394
|
+
const assignees = (issue.assignees ?? []).map((person) => person.login);
|
|
7395
|
+
return {
|
|
7396
|
+
asked: action === "reopened" ? assignees : action === "assigned" && assignee ? [assignee.login] : [],
|
|
7397
|
+
assignees,
|
|
7220
7398
|
conversationIds,
|
|
7399
|
+
issueId: String(issue.id),
|
|
7221
7400
|
number: issue.number,
|
|
7222
|
-
|
|
7223
|
-
|
|
7401
|
+
open: !GONE_ACTIONS.has(action) && issue.state === "open",
|
|
7402
|
+
url: issue.html_url
|
|
7403
|
+
};
|
|
7404
|
+
}
|
|
7405
|
+
/**
|
|
7406
|
+
* Return the Conversation that first saved the card of the issue, among
|
|
7407
|
+
* the ones that its footer names. Core reads the owner the same way, from
|
|
7408
|
+
* every stored card.
|
|
7409
|
+
*/
|
|
7410
|
+
async function issueOwner(annotations, event) {
|
|
7411
|
+
const saved = await pLimit(FOOTER_READ_CONCURRENCY).map(event.conversationIds, async (conversationId) => {
|
|
7412
|
+
const card = (await annotations.forConversation(conversationId).list()).find((annotation) => annotation.kind === "object" && annotation.subject?.kind === GITHUB_INBOX_SUBJECTS.issue && annotation.subject.id === event.issueId);
|
|
7413
|
+
return card ? [{
|
|
7414
|
+
conversationId,
|
|
7415
|
+
createdAt: card.createdAt
|
|
7416
|
+
}] : [];
|
|
7417
|
+
});
|
|
7418
|
+
let first;
|
|
7419
|
+
for (const card of saved.flat()) if (!first || card.createdAt < first.createdAt || card.createdAt === first.createdAt && card.conversationId < first.conversationId) first = card;
|
|
7420
|
+
return first?.conversationId;
|
|
7421
|
+
}
|
|
7422
|
+
/** Show the item of an issue that Junior created, after an `issues` webhook. */
|
|
7423
|
+
async function syncGitHubIssueItem(args) {
|
|
7424
|
+
try {
|
|
7425
|
+
await showIssueItem(args);
|
|
7426
|
+
} catch (error) {
|
|
7427
|
+
if (!(error instanceof PluginInboxItemOwnerError) && !(error instanceof Error && error.name === "PluginInboxItemOwnerError")) throw error;
|
|
7428
|
+
args.log?.warn("GitHub issue footer does not name its item's owner", { "app.github.issue_id": args.event.issueId });
|
|
7429
|
+
}
|
|
7430
|
+
}
|
|
7431
|
+
async function showIssueItem(args) {
|
|
7432
|
+
const { event } = args;
|
|
7433
|
+
const owner = await issueOwner(args.annotations, event);
|
|
7434
|
+
if (!owner) return;
|
|
7435
|
+
const items = args.inboxItems.forConversation(owner);
|
|
7436
|
+
const subject = issueSubject(event.issueId);
|
|
7437
|
+
if (!event.open) {
|
|
7438
|
+
await items.close({
|
|
7439
|
+
reason: "The issue is closed.",
|
|
7440
|
+
status: "done",
|
|
7441
|
+
subject
|
|
7442
|
+
});
|
|
7443
|
+
return;
|
|
7444
|
+
}
|
|
7445
|
+
const linked = await args.findLinkedIdentityIds(event.assignees);
|
|
7446
|
+
const identityOf = (person) => linked.get(person.toLowerCase());
|
|
7447
|
+
const assigneeIdentityIds = event.assignees.flatMap((person) => identityOf(person) ?? []);
|
|
7448
|
+
if (assigneeIdentityIds.length === 0) {
|
|
7449
|
+
await items.close({
|
|
7450
|
+
reason: "Nobody on the issue has a linked account now.",
|
|
7451
|
+
status: "done",
|
|
7452
|
+
subject
|
|
7453
|
+
});
|
|
7454
|
+
return;
|
|
7455
|
+
}
|
|
7456
|
+
await items.upsert({
|
|
7457
|
+
assigneeIdentityIds,
|
|
7458
|
+
askedIdentityIds: event.asked.flatMap((person) => identityOf(person) ?? []),
|
|
7459
|
+
body: `You are assigned to #${event.number}.\n\n${event.url}`,
|
|
7460
|
+
subject,
|
|
7461
|
+
title: `Assigned · #${event.number}`,
|
|
7462
|
+
waitsOnAssignees: true
|
|
7463
|
+
});
|
|
7224
7464
|
}
|
|
7225
7465
|
// src/webhooks/pull-request-outcome.ts
|
|
7226
7466
|
const pullRequestLifecycleActionsSchema = z.enum([
|
|
@@ -7426,62 +7666,6 @@ function normalizeGitHubPullRequestActivity(input) {
|
|
|
7426
7666
|
const { senderType, ...activity } = parsed.data;
|
|
7427
7667
|
return senderType === "Bot" ? void 0 : activity;
|
|
7428
7668
|
}
|
|
7429
|
-
// src/webhooks/pull-request-preview.ts
|
|
7430
|
-
const previewWebhookSchema = z.object({
|
|
7431
|
-
action: z.enum([
|
|
7432
|
-
"opened",
|
|
7433
|
-
"edited",
|
|
7434
|
-
"synchronize",
|
|
7435
|
-
"ready_for_review"
|
|
7436
|
-
]),
|
|
7437
|
-
pull_request: z.object({
|
|
7438
|
-
body: z.string().nullable().optional(),
|
|
7439
|
-
number: z.number().int().positive(),
|
|
7440
|
-
updated_at: z.iso.datetime({ offset: true })
|
|
7441
|
-
}),
|
|
7442
|
-
repository: z.object({ full_name: z.string().min(1) })
|
|
7443
|
-
});
|
|
7444
|
-
/**
|
|
7445
|
-
* Set or clear the preview image fact on each chip of a Junior pull request
|
|
7446
|
-
* from the webhook body. One failed conversation does not stop the others.
|
|
7447
|
-
*/
|
|
7448
|
-
async function refreshGitHubPullRequestPreview(args) {
|
|
7449
|
-
const parsed = previewWebhookSchema.safeParse(args.body);
|
|
7450
|
-
if (!parsed.success) return;
|
|
7451
|
-
const { pull_request: pullRequest, repository } = parsed.data;
|
|
7452
|
-
const conversationIds = (await findGitHubPullRequest(args.codeChanges, {
|
|
7453
|
-
number: pullRequest.number,
|
|
7454
|
-
repositoryFullName: repository.full_name
|
|
7455
|
-
}))?.conversationIds ?? [];
|
|
7456
|
-
if (conversationIds.length === 0) return;
|
|
7457
|
-
const key = `${repository.full_name.toLowerCase()}#${pullRequest.number}`;
|
|
7458
|
-
const previewImageUrls = githubPreviewImageUrls(pullRequest.body);
|
|
7459
|
-
const updatedAt = Date.parse(pullRequest.updated_at);
|
|
7460
|
-
const limit = pLimit(8);
|
|
7461
|
-
const results = await Promise.allSettled(conversationIds.map((conversationId) => limit(async () => {
|
|
7462
|
-
const store = args.annotations.forConversation(conversationId);
|
|
7463
|
-
const current = (await store.list()).find((annotation) => annotation.key === key);
|
|
7464
|
-
if (current?.kind !== "object" || current.facts?.type !== "code_change") return;
|
|
7465
|
-
const storedAt = current.sourceUpdatedAt ? Date.parse(current.sourceUpdatedAt) : void 0;
|
|
7466
|
-
if (storedAt !== void 0 && storedAt > updatedAt) return;
|
|
7467
|
-
const { plugin: _plugin, createdAt: _createdAt, updatedAt: _updatedAt, facts: { previewImageUrls: previous, additions: _additions, changedFiles: _changedFiles, deletions: _deletions, mergeable: _mergeable, reviewers: _reviewers, ...facts }, ...annotation } = current;
|
|
7468
|
-
const next = withGitHubPreviewImages(facts, previewImageUrls);
|
|
7469
|
-
if (previous?.join("\n") === next.previewImageUrls?.join("\n") && storedAt === updatedAt) return;
|
|
7470
|
-
await store.upsert({
|
|
7471
|
-
...annotation,
|
|
7472
|
-
facts: next,
|
|
7473
|
-
sourceUpdatedAt: pullRequest.updated_at
|
|
7474
|
-
});
|
|
7475
|
-
})));
|
|
7476
|
-
for (const result of results) {
|
|
7477
|
-
if (result.status === "fulfilled") continue;
|
|
7478
|
-
args.log?.error("GitHub pull request preview update failed", {
|
|
7479
|
-
errorType: result.reason instanceof Error ? result.reason.name : "UnknownError",
|
|
7480
|
-
number: pullRequest.number,
|
|
7481
|
-
repository: repository.full_name
|
|
7482
|
-
});
|
|
7483
|
-
}
|
|
7484
|
-
}
|
|
7485
7669
|
// src/webhooks/merge-conflict.ts
|
|
7486
7670
|
const PULL_REQUEST_CHECK_CONCURRENCY = 5;
|
|
7487
7671
|
const EVENT_TYPE = "pull_request.merge_conflict";
|
|
@@ -7720,6 +7904,44 @@ async function scheduleGitHubPushConflictCheck(args) {
|
|
|
7720
7904
|
state: args.state
|
|
7721
7905
|
});
|
|
7722
7906
|
}
|
|
7907
|
+
// src/webhooks/repository-move.ts
|
|
7908
|
+
const login = z.object({ login: z.string().min(1) });
|
|
7909
|
+
const repositoryMoveSchema = z.object({
|
|
7910
|
+
action: z.enum(["renamed", "transferred"]),
|
|
7911
|
+
changes: z.object({
|
|
7912
|
+
owner: z.object({ from: z.object({
|
|
7913
|
+
organization: login.nullish(),
|
|
7914
|
+
user: login.nullish()
|
|
7915
|
+
}) }).optional(),
|
|
7916
|
+
repository: z.object({ name: z.object({ from: z.string().min(1) }) }).optional()
|
|
7917
|
+
}),
|
|
7918
|
+
repository: z.object({
|
|
7919
|
+
full_name: z.string().min(1),
|
|
7920
|
+
name: z.string().min(1),
|
|
7921
|
+
owner: login
|
|
7922
|
+
})
|
|
7923
|
+
});
|
|
7924
|
+
/** Return the old and the new full name of a moved repository, if any. */
|
|
7925
|
+
function movedRepository(body) {
|
|
7926
|
+
const parsed = repositoryMoveSchema.safeParse(body);
|
|
7927
|
+
if (!parsed.success) return void 0;
|
|
7928
|
+
const { changes, repository } = parsed.data;
|
|
7929
|
+
const from = `${changes.owner?.from.organization?.login ?? changes.owner?.from.user?.login ?? repository.owner.login}/${changes.repository?.name.from ?? repository.name}`;
|
|
7930
|
+
return from.toLowerCase() === repository.full_name.toLowerCase() ? void 0 : {
|
|
7931
|
+
from,
|
|
7932
|
+
to: repository.full_name
|
|
7933
|
+
};
|
|
7934
|
+
}
|
|
7935
|
+
/**
|
|
7936
|
+
* Move the Annotations of a renamed or transferred repository to its new
|
|
7937
|
+
* name. Return whether the webhook moved one.
|
|
7938
|
+
*/
|
|
7939
|
+
async function moveGitHubRepositoryAnnotations(annotations, body) {
|
|
7940
|
+
const moved = movedRepository(body);
|
|
7941
|
+
if (!moved) return false;
|
|
7942
|
+
await annotations.objectsMoved(githubRepositoryMove(moved.from, moved.to));
|
|
7943
|
+
return true;
|
|
7944
|
+
}
|
|
7723
7945
|
// src/webhooks/pull-request-ready-reviewers.ts
|
|
7724
7946
|
const readyForReviewSchema = z.object({
|
|
7725
7947
|
action: z.literal("ready_for_review"),
|
|
@@ -8155,11 +8377,16 @@ function createGitHubWebhookRoute(args) {
|
|
|
8155
8377
|
});
|
|
8156
8378
|
return new Response(scheduled ? "Accepted" : "Ignored", { status: 202 });
|
|
8157
8379
|
}
|
|
8380
|
+
if (eventName === "repository") {
|
|
8381
|
+
const moved = await moveGitHubRepositoryAnnotations(args.annotations, body);
|
|
8382
|
+
return new Response(moved ? "Accepted" : "Ignored", { status: 202 });
|
|
8383
|
+
}
|
|
8158
8384
|
await refreshGitHubObjectCache({
|
|
8159
8385
|
body,
|
|
8160
8386
|
cache: args.cache,
|
|
8161
8387
|
eventName,
|
|
8162
8388
|
nowMs: Date.now(),
|
|
8389
|
+
objectChanged: async (subject) => await args.annotations.objectChanged(subject),
|
|
8163
8390
|
state: args.state,
|
|
8164
8391
|
tasks: args.tasks
|
|
8165
8392
|
});
|
|
@@ -8168,7 +8395,7 @@ function createGitHubWebhookRoute(args) {
|
|
|
8168
8395
|
body,
|
|
8169
8396
|
botEmail
|
|
8170
8397
|
}) : void 0;
|
|
8171
|
-
const
|
|
8398
|
+
const issueItemEvent = eventName === "issues" ? normalizeGitHubIssueItemEvent({
|
|
8172
8399
|
body,
|
|
8173
8400
|
botEmail
|
|
8174
8401
|
}) : void 0;
|
|
@@ -8180,7 +8407,6 @@ function createGitHubWebhookRoute(args) {
|
|
|
8180
8407
|
let recordedOutcome;
|
|
8181
8408
|
try {
|
|
8182
8409
|
recordedOutcome = await applyGitHubPullRequestOutcome({
|
|
8183
|
-
annotations: args.annotations,
|
|
8184
8410
|
codeChanges: args.codeChanges,
|
|
8185
8411
|
conversationChanges: args.conversationChanges,
|
|
8186
8412
|
db: args.db,
|
|
@@ -8221,28 +8447,17 @@ function createGitHubWebhookRoute(args) {
|
|
|
8221
8447
|
});
|
|
8222
8448
|
}
|
|
8223
8449
|
}
|
|
8224
|
-
if (
|
|
8450
|
+
if (issueItemEvent) await syncGitHubIssueItem({
|
|
8225
8451
|
annotations: args.annotations,
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
repo: closedIssue.repositoryFullName,
|
|
8231
|
-
number: closedIssue.number,
|
|
8232
|
-
objectType: "task",
|
|
8233
|
-
status: "closed"
|
|
8234
|
-
}
|
|
8452
|
+
event: issueItemEvent,
|
|
8453
|
+
findLinkedIdentityIds: args.findLinkedIdentityIds,
|
|
8454
|
+
inboxItems: args.inboxItems,
|
|
8455
|
+
log: args.log
|
|
8235
8456
|
});
|
|
8236
8457
|
if (pullRequestConversations) await args.codeChanges.associateConversations({
|
|
8237
8458
|
conversationIds: pullRequestConversations.conversationIds,
|
|
8238
8459
|
providerId: pullRequestConversations.pullRequestId
|
|
8239
8460
|
});
|
|
8240
|
-
if (eventName === "pull_request") await refreshGitHubPullRequestPreview({
|
|
8241
|
-
annotations: args.annotations,
|
|
8242
|
-
body,
|
|
8243
|
-
codeChanges: args.codeChanges,
|
|
8244
|
-
log: args.log
|
|
8245
|
-
});
|
|
8246
8461
|
const pullRequestActivity = normalizeGitHubPullRequestActivity({
|
|
8247
8462
|
body,
|
|
8248
8463
|
eventName
|
|
@@ -8264,7 +8479,7 @@ function createGitHubWebhookRoute(args) {
|
|
|
8264
8479
|
loadPullRequestFacts: needsCheckSuitePullRequestFacts(checkSuiteMatchKeys),
|
|
8265
8480
|
log: args.log,
|
|
8266
8481
|
privateKeyEnv: args.privateKeyEnv,
|
|
8267
|
-
responses: args.
|
|
8482
|
+
responses: args.responses,
|
|
8268
8483
|
tokens: args.tokens
|
|
8269
8484
|
}) : void 0;
|
|
8270
8485
|
const hasMatch = args.events.hasMatch;
|
|
@@ -8334,7 +8549,7 @@ function createGitHubWebhookRoute(args) {
|
|
|
8334
8549
|
appIdEnv: args.appIdEnv,
|
|
8335
8550
|
installationIdEnv: args.installationIdEnv,
|
|
8336
8551
|
privateKeyEnv: args.privateKeyEnv,
|
|
8337
|
-
responses: args.
|
|
8552
|
+
responses: args.responses,
|
|
8338
8553
|
tokens: args.tokens
|
|
8339
8554
|
};
|
|
8340
8555
|
await requestGitHubReviewersWhenReady({
|
|
@@ -8362,7 +8577,7 @@ function createGitHubWebhookRoute(args) {
|
|
|
8362
8577
|
targets: pullRequestActionTargets(eventName, body),
|
|
8363
8578
|
tasks: args.tasks
|
|
8364
8579
|
});
|
|
8365
|
-
if (!pullRequestOutcome && !
|
|
8580
|
+
if (!pullRequestOutcome && !issueItemEvent && !pullRequestConversations && events.length === 0) return new Response("Ignored", { status: 202 });
|
|
8366
8581
|
return new Response("Accepted", { status: 202 });
|
|
8367
8582
|
}
|
|
8368
8583
|
};
|
|
@@ -8714,8 +8929,8 @@ async function reconcilePullRequest(args, { databaseId, nameWithOwner }, pullReq
|
|
|
8714
8929
|
status: "dismissed"
|
|
8715
8930
|
}
|
|
8716
8931
|
});
|
|
8932
|
+
await closeCachedPullRequest(args, nameWithOwner, pullRequest);
|
|
8717
8933
|
await applyGitHubPullRequestOutcome({
|
|
8718
|
-
annotations: args.annotations,
|
|
8719
8934
|
codeChanges: args.codeChanges,
|
|
8720
8935
|
conversationChanges: args.conversationChanges,
|
|
8721
8936
|
db: args.db,
|
|
@@ -8724,6 +8939,25 @@ async function reconcilePullRequest(args, { databaseId, nameWithOwner }, pullReq
|
|
|
8724
8939
|
});
|
|
8725
8940
|
}
|
|
8726
8941
|
/**
|
|
8942
|
+
* No webhook refreshed the card's cache entry either. Mark a cached entry
|
|
8943
|
+
* closed, as the webhook does, and have open pages read the card again.
|
|
8944
|
+
*/
|
|
8945
|
+
async function closeCachedPullRequest(args, nameWithOwner, pullRequest) {
|
|
8946
|
+
await args.cache.update(githubObjectCacheKey("pulls", nameWithOwner, pullRequest.number), (current) => current ? {
|
|
8947
|
+
...GITHUB_PULL_REQUEST_CACHE,
|
|
8948
|
+
value: {
|
|
8949
|
+
...current,
|
|
8950
|
+
merged: pullRequest.merged,
|
|
8951
|
+
state: "closed",
|
|
8952
|
+
updated_at: pullRequest.updatedAt
|
|
8953
|
+
}
|
|
8954
|
+
} : void 0);
|
|
8955
|
+
await args.objectChanged({
|
|
8956
|
+
id: String(pullRequest.databaseId),
|
|
8957
|
+
kind: GITHUB_INBOX_SUBJECTS.pullRequest
|
|
8958
|
+
});
|
|
8959
|
+
}
|
|
8960
|
+
/**
|
|
8727
8961
|
* Reconcile the next repository that has open Junior pull requests and was
|
|
8728
8962
|
* not reconciled in the last day.
|
|
8729
8963
|
*/
|
|
@@ -8895,20 +9129,16 @@ async function classifyGitHubPullRequestCommitComposition(args) {
|
|
|
8895
9129
|
}
|
|
8896
9130
|
// src/repository-name-repair.ts
|
|
8897
9131
|
/**
|
|
8898
|
-
* A one-off repair of
|
|
8899
|
-
*
|
|
8900
|
-
*
|
|
8901
|
-
*
|
|
8902
|
-
* its old name. Reads that find a pull request by repository name miss it
|
|
8903
|
-
* until a lifecycle webhook records the new name. This task reads the
|
|
8904
|
-
* current name of each stored repository from GitHub by its id, once, and
|
|
8905
|
-
* records the names that changed.
|
|
9132
|
+
* A one-off repair of repository names in the code index. Migration 0020
|
|
9133
|
+
* kept the stored name of a repository renamed before it, so reads by name
|
|
9134
|
+
* miss its pull requests. This task reads each stored repository's name from
|
|
9135
|
+
* GitHub by its id, once, and moves its rows and Annotations to the new name.
|
|
8906
9136
|
*/
|
|
8907
9137
|
const GITHUB_REPOSITORY_NAME_REPAIR_TASK = "repairRepositoryNames";
|
|
8908
9138
|
const DONE_KEY$2 = "repository-name-repair:done";
|
|
8909
9139
|
/** GitHub reads at once. */
|
|
8910
|
-
const READ_CONCURRENCY = 4;
|
|
8911
|
-
const payloadSchema$
|
|
9140
|
+
const READ_CONCURRENCY$1 = 4;
|
|
9141
|
+
const payloadSchema$3 = z.object({}).strict();
|
|
8912
9142
|
/** Start the repair until one run finishes. */
|
|
8913
9143
|
async function startGitHubRepositoryNameRepair(args) {
|
|
8914
9144
|
if (await args.state.get(DONE_KEY$2)) return;
|
|
@@ -8925,7 +9155,7 @@ async function startGitHubRepositoryNameRepair(args) {
|
|
|
8925
9155
|
*/
|
|
8926
9156
|
function githubRepositoryNameRepairTask(loadFullNames) {
|
|
8927
9157
|
return {
|
|
8928
|
-
payload: payloadSchema$
|
|
9158
|
+
payload: payloadSchema$3,
|
|
8929
9159
|
async run(ctx) {
|
|
8930
9160
|
if (await ctx.state.get(DONE_KEY$2)) return;
|
|
8931
9161
|
const stored = /* @__PURE__ */ new Map();
|
|
@@ -8933,7 +9163,8 @@ function githubRepositoryNameRepairTask(loadFullNames) {
|
|
|
8933
9163
|
if (stored.size > 0) {
|
|
8934
9164
|
const readFullName = await loadFullNames();
|
|
8935
9165
|
const updatedAt = /* @__PURE__ */ new Date();
|
|
8936
|
-
|
|
9166
|
+
const renames = [];
|
|
9167
|
+
await pLimit(READ_CONCURRENCY$1).map([...stored], async ([providerId, name]) => {
|
|
8937
9168
|
try {
|
|
8938
9169
|
const fullName = await readFullName(providerId);
|
|
8939
9170
|
if (!fullName || fullName === name) return;
|
|
@@ -8942,10 +9173,24 @@ function githubRepositoryNameRepairTask(loadFullNames) {
|
|
|
8942
9173
|
providerId,
|
|
8943
9174
|
updatedAt
|
|
8944
9175
|
});
|
|
9176
|
+
renames.push([name, fullName]);
|
|
8945
9177
|
} catch (error) {
|
|
8946
9178
|
ctx.log.error("GitHub repository name repair failed", { repositoryId: providerId }, error);
|
|
8947
9179
|
}
|
|
8948
9180
|
});
|
|
9181
|
+
const { cyclic, ordered } = orderRepositoryRenames(renames);
|
|
9182
|
+
for (const [from, to] of ordered) try {
|
|
9183
|
+
await ctx.annotations.objectsMoved(githubRepositoryMove(from, to));
|
|
9184
|
+
} catch (error) {
|
|
9185
|
+
ctx.log.error("GitHub repository Annotation move failed", {
|
|
9186
|
+
from,
|
|
9187
|
+
to
|
|
9188
|
+
}, error);
|
|
9189
|
+
}
|
|
9190
|
+
for (const [from, to] of cyclic) ctx.log.error("GitHub repository renames form a cycle", {
|
|
9191
|
+
from,
|
|
9192
|
+
to
|
|
9193
|
+
});
|
|
8949
9194
|
}
|
|
8950
9195
|
await ctx.state.set(DONE_KEY$2, true);
|
|
8951
9196
|
}
|
|
@@ -8957,7 +9202,7 @@ const CURSOR_KEY$1 = "pull-request-requester-backfill:cursor";
|
|
|
8957
9202
|
const DONE_KEY$1 = "pull-request-requester-backfill:done";
|
|
8958
9203
|
/** Pull requests per task run. Each needs a few small database writes. */
|
|
8959
9204
|
const PAGE_SIZE$1 = 200;
|
|
8960
|
-
const payloadSchema$
|
|
9205
|
+
const payloadSchema$2 = z.object({}).strict();
|
|
8961
9206
|
/** Start the next page of the backfill until the last page is done. */
|
|
8962
9207
|
async function startGitHubPullRequestRequesterBackfill(args) {
|
|
8963
9208
|
if (await args.state.get(DONE_KEY$1)) return;
|
|
@@ -8973,7 +9218,7 @@ async function startGitHubPullRequestRequesterBackfill(args) {
|
|
|
8973
9218
|
* code changes, in the order of repository name and number.
|
|
8974
9219
|
*/
|
|
8975
9220
|
const githubPullRequestRequesterBackfillTask = {
|
|
8976
|
-
payload: payloadSchema$
|
|
9221
|
+
payload: payloadSchema$2,
|
|
8977
9222
|
async run(ctx) {
|
|
8978
9223
|
if (await ctx.state.get(DONE_KEY$1)) return;
|
|
8979
9224
|
const db = gitHubDbSchema.parse(ctx.db);
|
|
@@ -9007,7 +9252,7 @@ const RERUNS_KEY = `pull-request-action-backfill:${VERSION}:reruns`;
|
|
|
9007
9252
|
* one run stays well inside the function time and the hourly rate limit.
|
|
9008
9253
|
*/
|
|
9009
9254
|
const PAGE_SIZE = 50;
|
|
9010
|
-
const payloadSchema = z.object({}).strict();
|
|
9255
|
+
const payloadSchema$1 = z.object({}).strict();
|
|
9011
9256
|
/** Start the next page of the backfill until the last page is done. */
|
|
9012
9257
|
async function startGitHubPullRequestActionBackfill(args) {
|
|
9013
9258
|
if (await args.state.get(DONE_KEY)) return;
|
|
@@ -9026,7 +9271,7 @@ async function startGitHubPullRequestActionBackfill(args) {
|
|
|
9026
9271
|
*/
|
|
9027
9272
|
function githubPullRequestActionBackfillTask(args) {
|
|
9028
9273
|
return {
|
|
9029
|
-
payload: payloadSchema,
|
|
9274
|
+
payload: payloadSchema$1,
|
|
9030
9275
|
async run(ctx) {
|
|
9031
9276
|
if (await ctx.state.get(DONE_KEY)) return;
|
|
9032
9277
|
const after = await ctx.state.get(CURSOR_KEY) ?? 0;
|
|
@@ -9053,6 +9298,292 @@ function githubPullRequestActionBackfillTask(args) {
|
|
|
9053
9298
|
}
|
|
9054
9299
|
};
|
|
9055
9300
|
}
|
|
9301
|
+
// src/annotation-names.ts
|
|
9302
|
+
/**
|
|
9303
|
+
* Give old GitHub Annotations their object's id and current repository name,
|
|
9304
|
+
* so search finds them after a rename. A heartbeat runs one bounded slice
|
|
9305
|
+
* after the cursor in plugin state: first objects with an id, then objects
|
|
9306
|
+
* without one. A new repository name moves the whole repository's rows.
|
|
9307
|
+
*/
|
|
9308
|
+
const GITHUB_ANNOTATION_NAMES_TASK = "nameAnnotationObjects";
|
|
9309
|
+
/** Objects that one slice reads. */
|
|
9310
|
+
const BATCH = 50;
|
|
9311
|
+
/**
|
|
9312
|
+
* The job's progress in plugin state: the pass, the key after which the
|
|
9313
|
+
* next slice reads in it, and the number of slices that ran, which names
|
|
9314
|
+
* the next slice. The `named` pass reads the objects that have their id,
|
|
9315
|
+
* then the `unnamed` pass reads the others.
|
|
9316
|
+
*/
|
|
9317
|
+
const PROGRESS_KEY = "annotation-names:progress";
|
|
9318
|
+
const progressSchema = z.object({
|
|
9319
|
+
after: z.string().optional(),
|
|
9320
|
+
done: z.boolean().optional(),
|
|
9321
|
+
pass: z.enum(["named", "unnamed"]).default("named"),
|
|
9322
|
+
slices: z.number().int().nonnegative()
|
|
9323
|
+
});
|
|
9324
|
+
async function readProgress(state) {
|
|
9325
|
+
return progressSchema.parse(await state.get(PROGRESS_KEY) ?? { slices: 0 });
|
|
9326
|
+
}
|
|
9327
|
+
/** GitHub reads at once. */
|
|
9328
|
+
const READ_CONCURRENCY = 4;
|
|
9329
|
+
const payloadSchema = z.object({}).strict();
|
|
9330
|
+
const OBJECT_KEY$1 = /^([^/#\s]+)\/([^/#\s]+)#(\d+)$/;
|
|
9331
|
+
function linkRef(url) {
|
|
9332
|
+
const parsed = URL.parse(url);
|
|
9333
|
+
if (parsed?.protocol !== "https:" || parsed.hostname !== "github.com") return;
|
|
9334
|
+
const [owner, name, collection, number] = parsed.pathname.split("/").filter(Boolean);
|
|
9335
|
+
if (!owner || !name || collection !== "issues" && collection !== "pull" || !number || !/^\d+$/.test(number)) return;
|
|
9336
|
+
return {
|
|
9337
|
+
kind: collection === "pull" ? "pull_request" : "issue",
|
|
9338
|
+
name,
|
|
9339
|
+
number: Number(number),
|
|
9340
|
+
owner
|
|
9341
|
+
};
|
|
9342
|
+
}
|
|
9343
|
+
function objectRef(annotation) {
|
|
9344
|
+
const link = annotation.url ? linkRef(annotation.url) : void 0;
|
|
9345
|
+
if (link) return link;
|
|
9346
|
+
const key = OBJECT_KEY$1.exec(annotation.key);
|
|
9347
|
+
if (!key?.[1] || !key[2] || !key[3]) return void 0;
|
|
9348
|
+
return {
|
|
9349
|
+
kind: "issue",
|
|
9350
|
+
name: key[2],
|
|
9351
|
+
number: Number(key[3]),
|
|
9352
|
+
owner: key[1]
|
|
9353
|
+
};
|
|
9354
|
+
}
|
|
9355
|
+
function repositoryOf(url) {
|
|
9356
|
+
const link = linkRef(url);
|
|
9357
|
+
return link && `${link.owner}/${link.name}`;
|
|
9358
|
+
}
|
|
9359
|
+
/**
|
|
9360
|
+
* Start the next slice until one slice finds no more objects. The key
|
|
9361
|
+
* names the slice, so each slice starts once.
|
|
9362
|
+
*/
|
|
9363
|
+
async function startGitHubAnnotationNames(args) {
|
|
9364
|
+
const progress = await readProgress(args.state);
|
|
9365
|
+
if (progress.done) return;
|
|
9366
|
+
await args.tasks.start({
|
|
9367
|
+
key: `annotation-names:${progress.slices}`,
|
|
9368
|
+
name: GITHUB_ANNOTATION_NAMES_TASK,
|
|
9369
|
+
payload: {}
|
|
9370
|
+
});
|
|
9371
|
+
}
|
|
9372
|
+
/**
|
|
9373
|
+
* Read at most one batch of objects, in the current pass and then in the
|
|
9374
|
+
* next one. GitHub does not find an object that is gone or that the App
|
|
9375
|
+
* cannot read, so its Annotations stay as they are, and the cursor moves
|
|
9376
|
+
* past them. A failed read fails the slice, so a later delivery reads it
|
|
9377
|
+
* again. The last delivery leaves that object as it is.
|
|
9378
|
+
*/
|
|
9379
|
+
function githubAnnotationNamesTask(loadNames) {
|
|
9380
|
+
return {
|
|
9381
|
+
payload: payloadSchema,
|
|
9382
|
+
async run(ctx) {
|
|
9383
|
+
const start = await readProgress(ctx.state);
|
|
9384
|
+
if (start.done) return;
|
|
9385
|
+
let progress = start;
|
|
9386
|
+
let budget = BATCH;
|
|
9387
|
+
let reader;
|
|
9388
|
+
const renames = /* @__PURE__ */ new Map();
|
|
9389
|
+
const renamedTo = async (names, stored, current) => {
|
|
9390
|
+
if (stored.toLowerCase() === current.toLowerCase()) return void 0;
|
|
9391
|
+
const key = stored.toLowerCase();
|
|
9392
|
+
let read = renames.get(key);
|
|
9393
|
+
if (!read) {
|
|
9394
|
+
read = names.readRepositoryName(stored);
|
|
9395
|
+
renames.set(key, read);
|
|
9396
|
+
}
|
|
9397
|
+
return (await read)?.toLowerCase() === current.toLowerCase() ? current : void 0;
|
|
9398
|
+
};
|
|
9399
|
+
let failure;
|
|
9400
|
+
while (!progress.done && budget > 0 && failure === void 0) {
|
|
9401
|
+
const named = progress.pass === "named";
|
|
9402
|
+
const limit = budget;
|
|
9403
|
+
const batch = await ctx.annotations.listObjects({
|
|
9404
|
+
after: progress.after,
|
|
9405
|
+
limit,
|
|
9406
|
+
named
|
|
9407
|
+
});
|
|
9408
|
+
budget -= batch.length;
|
|
9409
|
+
const moves = /* @__PURE__ */ new Map();
|
|
9410
|
+
const objects = batch.flatMap((annotation) => {
|
|
9411
|
+
const ref = objectRef(annotation);
|
|
9412
|
+
return ref ? [{
|
|
9413
|
+
key: annotation.key,
|
|
9414
|
+
ref
|
|
9415
|
+
}] : [];
|
|
9416
|
+
});
|
|
9417
|
+
if (objects.length > 0) {
|
|
9418
|
+
const names = reader ??= await loadNames();
|
|
9419
|
+
await pLimit(READ_CONCURRENCY).map(objects, async ({ key, ref }) => {
|
|
9420
|
+
let name;
|
|
9421
|
+
let renamed;
|
|
9422
|
+
const stored = `${ref.owner}/${ref.name}`;
|
|
9423
|
+
try {
|
|
9424
|
+
name = await names.readObject(ref);
|
|
9425
|
+
const current = name && repositoryOf(name.url);
|
|
9426
|
+
renamed = current && await renamedTo(names, stored, current);
|
|
9427
|
+
} catch (error) {
|
|
9428
|
+
if (!ctx.lastDelivery) {
|
|
9429
|
+
failure ??= error;
|
|
9430
|
+
return;
|
|
9431
|
+
}
|
|
9432
|
+
ctx.log.error("GitHub Annotation object read failed", {}, error);
|
|
9433
|
+
return;
|
|
9434
|
+
}
|
|
9435
|
+
if (!name) return;
|
|
9436
|
+
if (renamed) moves.set(stored.toLowerCase(), [stored, renamed]);
|
|
9437
|
+
if (named) return;
|
|
9438
|
+
try {
|
|
9439
|
+
await ctx.annotations.nameObject(key, {
|
|
9440
|
+
subject: {
|
|
9441
|
+
id: name.id,
|
|
9442
|
+
kind: name.kind === "pull_request" ? GITHUB_INBOX_SUBJECTS.pullRequest : GITHUB_INBOX_SUBJECTS.issue
|
|
9443
|
+
},
|
|
9444
|
+
url: name.url
|
|
9445
|
+
});
|
|
9446
|
+
} catch (error) {
|
|
9447
|
+
failure ??= error;
|
|
9448
|
+
}
|
|
9449
|
+
});
|
|
9450
|
+
}
|
|
9451
|
+
const renames = orderRepositoryRenames(moves.values());
|
|
9452
|
+
for (const [from, to] of renames.ordered) await ctx.annotations.objectsMoved(githubRepositoryMove(from, to));
|
|
9453
|
+
for (const [from, to] of renames.cyclic) ctx.log.error("GitHub repository renames form a cycle", {
|
|
9454
|
+
from,
|
|
9455
|
+
to
|
|
9456
|
+
});
|
|
9457
|
+
const last = batch.at(-1);
|
|
9458
|
+
if (!named && renames.ordered.length > 0) progress = {
|
|
9459
|
+
pass: "unnamed",
|
|
9460
|
+
slices: progress.slices
|
|
9461
|
+
};
|
|
9462
|
+
else if (failure !== void 0) break;
|
|
9463
|
+
else if (last && batch.length === limit) progress = {
|
|
9464
|
+
...progress,
|
|
9465
|
+
after: last.key
|
|
9466
|
+
};
|
|
9467
|
+
else if (named) progress = {
|
|
9468
|
+
pass: "unnamed",
|
|
9469
|
+
slices: progress.slices
|
|
9470
|
+
};
|
|
9471
|
+
else progress = {
|
|
9472
|
+
done: true,
|
|
9473
|
+
pass: "unnamed",
|
|
9474
|
+
slices: progress.slices
|
|
9475
|
+
};
|
|
9476
|
+
}
|
|
9477
|
+
if (failure !== void 0) {
|
|
9478
|
+
if (progress !== start) await ctx.state.set(PROGRESS_KEY, progress);
|
|
9479
|
+
throw failure;
|
|
9480
|
+
}
|
|
9481
|
+
await ctx.state.set(PROGRESS_KEY, {
|
|
9482
|
+
...progress,
|
|
9483
|
+
slices: start.slices + 1
|
|
9484
|
+
});
|
|
9485
|
+
}
|
|
9486
|
+
};
|
|
9487
|
+
}
|
|
9488
|
+
// src/webhooks/dismiss-requests.ts
|
|
9489
|
+
/**
|
|
9490
|
+
* GitHub writes that a dismiss of a GitHub Inbox item makes with
|
|
9491
|
+
* installation tokens, to take the person off the object on GitHub.
|
|
9492
|
+
*/
|
|
9493
|
+
/**
|
|
9494
|
+
* Unassign people from one issue, with an issues write token. A gone issue
|
|
9495
|
+
* has nobody left to unassign.
|
|
9496
|
+
*/
|
|
9497
|
+
async function removeIssueAssignees(env, input) {
|
|
9498
|
+
const { owner, name } = splitRepository(input.repositoryFullName, "issue unassign");
|
|
9499
|
+
const token = await issueInstallationToken({
|
|
9500
|
+
...env,
|
|
9501
|
+
permissions: { issues: "write" },
|
|
9502
|
+
repositories: [name]
|
|
9503
|
+
});
|
|
9504
|
+
try {
|
|
9505
|
+
await githubRequest("https://api.github.com", `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/issues/${input.number}/assignees`, {
|
|
9506
|
+
body: { assignees: input.assignees },
|
|
9507
|
+
method: "DELETE",
|
|
9508
|
+
token: token.token
|
|
9509
|
+
});
|
|
9510
|
+
} catch (error) {
|
|
9511
|
+
if (error instanceof GitHubRequestError && (error.status === 404 || error.status === 410)) return;
|
|
9512
|
+
throw error;
|
|
9513
|
+
}
|
|
9514
|
+
}
|
|
9515
|
+
const requestedReviewersSchema = z.object({ requested_reviewers: z.array(z.object({ login: z.string().min(1) })) });
|
|
9516
|
+
/**
|
|
9517
|
+
* Remove one person from the requested reviewers of a pull request, with a
|
|
9518
|
+
* pull requests write token. Does nothing when GitHub does not list them
|
|
9519
|
+
* or the pull request is gone.
|
|
9520
|
+
*/
|
|
9521
|
+
async function removeRequestedReviewer(env, input) {
|
|
9522
|
+
const { owner, name } = splitRepository(input.repositoryFullName, "review request removal");
|
|
9523
|
+
const token = await issueInstallationToken({
|
|
9524
|
+
...env,
|
|
9525
|
+
permissions: { pull_requests: "write" },
|
|
9526
|
+
repositories: [name]
|
|
9527
|
+
});
|
|
9528
|
+
const path = `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${input.number}`;
|
|
9529
|
+
try {
|
|
9530
|
+
const pullRequest = requestedReviewersSchema.parse(await githubRequest("https://api.github.com", path, { token: token.token }));
|
|
9531
|
+
const login = input.login.toLowerCase();
|
|
9532
|
+
if (!pullRequest.requested_reviewers.some((reviewer) => reviewer.login.toLowerCase() === login)) return;
|
|
9533
|
+
await githubRequest("https://api.github.com", `${path}/requested_reviewers`, {
|
|
9534
|
+
body: { reviewers: [input.login] },
|
|
9535
|
+
method: "DELETE",
|
|
9536
|
+
token: token.token
|
|
9537
|
+
});
|
|
9538
|
+
} catch (error) {
|
|
9539
|
+
if (error instanceof GitHubRequestError && (error.status === 404 || error.status === 410)) return;
|
|
9540
|
+
throw error;
|
|
9541
|
+
}
|
|
9542
|
+
}
|
|
9543
|
+
// src/inbox-dismiss.ts
|
|
9544
|
+
/** Split an Annotation key, such as `getsentry/junior#12`. */
|
|
9545
|
+
function parseObjectKey(key) {
|
|
9546
|
+
const match = /^([^/#\s]+\/[^/#\s]+)#(\d+)$/.exec(key);
|
|
9547
|
+
return match ? {
|
|
9548
|
+
number: Number(match[2]),
|
|
9549
|
+
repositoryFullName: match[1]
|
|
9550
|
+
} : void 0;
|
|
9551
|
+
}
|
|
9552
|
+
/** Unassign the person who dismissed an issue item from the issue. */
|
|
9553
|
+
async function unassignFromIssue(ctx, env, login) {
|
|
9554
|
+
const card = (await ctx.annotations.list()).find((annotation) => annotation.kind === "object" && annotation.subject?.kind === ctx.subject.kind && annotation.subject.id === ctx.subject.id);
|
|
9555
|
+
const ref = card ? parseObjectKey(card.key) : void 0;
|
|
9556
|
+
if (!ref) throw new Error(`GitHub issue ${ctx.subject.id} has no card in Conversation ${ctx.conversationId}`);
|
|
9557
|
+
await removeIssueAssignees(env, {
|
|
9558
|
+
...ref,
|
|
9559
|
+
assignees: [login]
|
|
9560
|
+
});
|
|
9561
|
+
}
|
|
9562
|
+
/**
|
|
9563
|
+
* Remove the person who dismissed a pull request item from its requested
|
|
9564
|
+
* reviewers. A requester, such as on Ready to merge, holds no reviewer role,
|
|
9565
|
+
* so their dismiss changes nothing on GitHub.
|
|
9566
|
+
*/
|
|
9567
|
+
async function removeFromReviewers(ctx, env) {
|
|
9568
|
+
if (!ctx.handle) return;
|
|
9569
|
+
const [change] = await ctx.codeChanges.list({ providerIds: [ctx.subject.id] });
|
|
9570
|
+
if (!change) throw new Error(`GitHub pull request ${ctx.subject.id} has no code change`);
|
|
9571
|
+
await removeRequestedReviewer(env, {
|
|
9572
|
+
login: ctx.handle,
|
|
9573
|
+
number: change.number,
|
|
9574
|
+
repositoryFullName: change.repository.name
|
|
9575
|
+
});
|
|
9576
|
+
}
|
|
9577
|
+
/** Remove the person who dismissed a GitHub item from the object on GitHub. */
|
|
9578
|
+
async function dismissGitHubItem(ctx, env) {
|
|
9579
|
+
if (ctx.subject.kind === GITHUB_INBOX_SUBJECTS.pullRequest) {
|
|
9580
|
+
await removeFromReviewers(ctx, env);
|
|
9581
|
+
return;
|
|
9582
|
+
}
|
|
9583
|
+
if (ctx.subject.kind !== GITHUB_INBOX_SUBJECTS.issue) return;
|
|
9584
|
+
if (!ctx.handle) throw new Error("The person who dismissed has no linked GitHub account");
|
|
9585
|
+
await unassignFromIssue(ctx, env, ctx.handle);
|
|
9586
|
+
}
|
|
9056
9587
|
// src/images.ts
|
|
9057
9588
|
/**
|
|
9058
9589
|
* Description images of GitHub objects, served through the Junior image
|
|
@@ -9153,26 +9684,19 @@ function githubNoreplyEmail(user) {
|
|
|
9153
9684
|
}
|
|
9154
9685
|
}
|
|
9155
9686
|
/**
|
|
9156
|
-
*
|
|
9157
|
-
* `instructionActors`
|
|
9158
|
-
*
|
|
9159
|
-
* display profile.
|
|
9687
|
+
* Identity key for an actor: identity ids only, never display fields, as
|
|
9688
|
+
* `instructionActors` builds `run.actors`, so one person under two display
|
|
9689
|
+
* profiles matches.
|
|
9160
9690
|
*/
|
|
9161
9691
|
function actorIdentityKey(actor) {
|
|
9162
9692
|
if (actor.platform === "system") return `system ${actor.name}`;
|
|
9163
9693
|
return actor.platform === "slack" ? `slack ${actor.teamId} ${actor.userId}` : `${actor.platform} ${actor.userId}`;
|
|
9164
9694
|
}
|
|
9165
9695
|
/**
|
|
9166
|
-
* Build `Co-Authored-By` trailers
|
|
9167
|
-
*
|
|
9168
|
-
*
|
|
9169
|
-
*
|
|
9170
|
-
* denying the commit. Dedupes by identity and resolved email so the same human
|
|
9171
|
-
* under two display profiles, or an actor matching the bot identity, only ever
|
|
9172
|
-
* produces one line.
|
|
9173
|
-
*
|
|
9174
|
-
* When the current actor has a linked GitHub identity, prefer that noreply
|
|
9175
|
-
* address so external automation can resolve a login for assignment.
|
|
9696
|
+
* Build `Co-Authored-By` trailers that credit the human run actors. Run actors
|
|
9697
|
+
* are attribution only, so an actor without a resolvable name and email is
|
|
9698
|
+
* left out rather than denying the commit. Lines dedupe by identity and email,
|
|
9699
|
+
* and an actor that matches the bot identity gets no line.
|
|
9176
9700
|
*/
|
|
9177
9701
|
function additionalActorCoauthorTrailers(args) {
|
|
9178
9702
|
if (!args.actors || args.actors.length === 0) return [];
|
|
@@ -9197,12 +9721,9 @@ function additionalActorCoauthorTrailers(args) {
|
|
|
9197
9721
|
}
|
|
9198
9722
|
/**
|
|
9199
9723
|
* Client hooks that Junior's hooks directory passes to the repository.
|
|
9200
|
-
*
|
|
9201
|
-
*
|
|
9202
|
-
*
|
|
9203
|
-
* Git LFS). Git would skip those hooks without these pass-through hooks.
|
|
9204
|
-
* `prepare-commit-msg` is not in the list because Junior's own hook runs the
|
|
9205
|
-
* repository hook first.
|
|
9724
|
+
* Junior's `core.hooksPath` replaces the repository's own (husky) or
|
|
9725
|
+
* `.git/hooks`, so Git would skip them without these. `prepare-commit-msg`
|
|
9726
|
+
* is absent because Junior's own hook runs the repository hook first.
|
|
9206
9727
|
*/
|
|
9207
9728
|
const REPOSITORY_HOOK_NAMES = [
|
|
9208
9729
|
"applypatch-msg",
|
|
@@ -9270,24 +9791,11 @@ fi
|
|
|
9270
9791
|
`;
|
|
9271
9792
|
}
|
|
9272
9793
|
/**
|
|
9273
|
-
* Awk
|
|
9274
|
-
*
|
|
9275
|
-
*
|
|
9276
|
-
*
|
|
9277
|
-
*
|
|
9278
|
-
* and without the bot, to the final trailer paragraph. Like Git, it never
|
|
9279
|
-
* treats the subject paragraph as trailers. A trailer key starts with a
|
|
9280
|
-
* capital letter, so a conventional commit subject such as `feat: x` in a
|
|
9281
|
-
* squash message stays body text. It keeps the comment block that Git adds
|
|
9282
|
-
* for an editor at the end. A message with no content stays empty, so Git
|
|
9283
|
-
* still aborts the commit.
|
|
9284
|
-
*
|
|
9285
|
-
* With `JUNIOR_COAUTHOR_LIST` set, it prints only the `Co-authored-by` lines
|
|
9286
|
-
* that it would remove. The hook uses this to read the co-authors of a
|
|
9287
|
-
* rewritten commit with the same rules, so a squash-style message keeps the
|
|
9288
|
-
* co-authors in its earlier trailer paragraphs too.
|
|
9289
|
-
*
|
|
9290
|
-
* The hook puts this program in single quotes, so it must not contain one.
|
|
9794
|
+
* Awk that sets a commit message's co-author trailers: drops every
|
|
9795
|
+
* `Co-authored-by` in trailer-only paragraphs, so model co-authors never land,
|
|
9796
|
+
* and appends `JUNIOR_COAUTHOR_TRAILERS` to the last one. Like Git, it skips
|
|
9797
|
+
* the subject and needs a capital key, keeps Git's comment block, and leaves
|
|
9798
|
+
* an empty message empty. The hook single-quotes it, so it has no `'`.
|
|
9291
9799
|
*/
|
|
9292
9800
|
const SET_COAUTHOR_TRAILERS_AWK = String.raw`
|
|
9293
9801
|
function blank(line) { return line ~ /^[[:space:]]*$/ }
|
|
@@ -10118,27 +10626,11 @@ function overridesHooksPath([program, ...args]) {
|
|
|
10118
10626
|
}
|
|
10119
10627
|
// src/graphql-budget.ts
|
|
10120
10628
|
/**
|
|
10121
|
-
* Hourly GitHub GraphQL budgets for Sandbox requests
|
|
10122
|
-
*
|
|
10123
|
-
*
|
|
10124
|
-
*
|
|
10125
|
-
*
|
|
10126
|
-
* host calls such as the PR next-action syncs keep working.
|
|
10127
|
-
*
|
|
10128
|
-
* Spend comes from GitHub's own rate limit headers on each response, not
|
|
10129
|
-
* from a prediction. A response's cost is the rise in `x-ratelimit-used`
|
|
10130
|
-
* since the last response that Junior saw. Spend that Junior does not see,
|
|
10131
|
-
* such as a webhook call that does not go through egress, counts toward the
|
|
10132
|
-
* next Sandbox response, so a Conversation can be charged more than its own
|
|
10133
|
-
* queries cost, never less.
|
|
10134
|
-
*
|
|
10135
|
-
* Spend is known only when a response comes back, so each Conversation may
|
|
10136
|
-
* have only a few Sandbox GraphQL requests in flight. Without that limit,
|
|
10137
|
-
* parallel copies of a costly query all pass the check before any of them
|
|
10138
|
-
* is charged.
|
|
10139
|
-
*
|
|
10140
|
-
* Counts live in the plugin cache, which every instance shares. A lost
|
|
10141
|
-
* entry only resets a count, which lets more requests through, never fewer.
|
|
10629
|
+
* Hourly GitHub GraphQL budgets for Sandbox requests: each Conversation gets a
|
|
10630
|
+
* share of the installation's points, and a reserve stays for host calls.
|
|
10631
|
+
* Spend is the rise in `x-ratelimit-used`, so unseen spend overcharges, never
|
|
10632
|
+
* undercharges. Few requests fly at once, since spend is known only on
|
|
10633
|
+
* response. Counts live in the shared cache; a lost entry only resets one.
|
|
10142
10634
|
*/
|
|
10143
10635
|
/** Points that one Conversation's Sandbox may spend in one clock hour. */
|
|
10144
10636
|
const GITHUB_SANDBOX_GRAPHQL_CONVERSATION_BUDGET = 2e3;
|
|
@@ -10705,6 +11197,22 @@ async function selectGitHubGrant(ctx, env, upstreamUrl) {
|
|
|
10705
11197
|
if (access === "write") throw new EgressPolicyDenied("This GitHub write request is not supported. Use the matching GitHub tool or a supported REST endpoint.");
|
|
10706
11198
|
return grantForAccess(access, "github.api-read", "installation-read");
|
|
10707
11199
|
}
|
|
11200
|
+
// src/installation-http-cache.ts
|
|
11201
|
+
/**
|
|
11202
|
+
* Read GitHub with installation tokens through Junior's HTTP cache. Each
|
|
11203
|
+
* read asks GitHub with the saved ETag. GitHub answers `304 Not Modified`
|
|
11204
|
+
* only to a request that it authorized, and does not count it against the
|
|
11205
|
+
* rate limit, so a repeat read of an unchanged resource, such as a pull
|
|
11206
|
+
* request that every check suite webhook reads, is free.
|
|
11207
|
+
*/
|
|
11208
|
+
function installationResponses(cache, installationId) {
|
|
11209
|
+
return async (url, send) => await cache.fetch({
|
|
11210
|
+
scope: `installation:${installationId() ?? ""}`,
|
|
11211
|
+
ttlMs: 0,
|
|
11212
|
+
url,
|
|
11213
|
+
send
|
|
11214
|
+
});
|
|
11215
|
+
}
|
|
10708
11216
|
// src/plugin.ts
|
|
10709
11217
|
/**
|
|
10710
11218
|
* GitHub plugin runtime boundary.
|
|
@@ -10740,6 +11248,11 @@ function githubPlugin(options = {}) {
|
|
|
10740
11248
|
githubPullRequestLinks
|
|
10741
11249
|
],
|
|
10742
11250
|
tasks: {
|
|
11251
|
+
[GITHUB_ANNOTATION_NAMES_TASK]: githubAnnotationNamesTask(async () => await loadGitHubObjectNames({
|
|
11252
|
+
appIdEnv,
|
|
11253
|
+
installationIdEnv,
|
|
11254
|
+
privateKeyEnv
|
|
11255
|
+
})),
|
|
10743
11256
|
[GITHUB_PULL_REQUEST_ACTION_BACKFILL_TASK]: githubPullRequestActionBackfillTask({
|
|
10744
11257
|
botEmail: () => readEnv(botEmailEnv),
|
|
10745
11258
|
env: {
|
|
@@ -10910,6 +11423,13 @@ function githubPlugin(options = {}) {
|
|
|
10910
11423
|
systemPrompt() {
|
|
10911
11424
|
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." }];
|
|
10912
11425
|
},
|
|
11426
|
+
async inboxItemDismissed(ctx) {
|
|
11427
|
+
await dismissGitHubItem(ctx, {
|
|
11428
|
+
appIdEnv,
|
|
11429
|
+
installationIdEnv,
|
|
11430
|
+
privateKeyEnv
|
|
11431
|
+
});
|
|
11432
|
+
},
|
|
10913
11433
|
async inboxItemAnswered(ctx) {
|
|
10914
11434
|
if (ctx.subject.kind !== GITHUB_INBOX_SUBJECTS.mergeConflict || ctx.choice !== "Resume") return;
|
|
10915
11435
|
const db = gitHubDbSchema.parse(ctx.db);
|
|
@@ -10973,8 +11493,8 @@ function githubPlugin(options = {}) {
|
|
|
10973
11493
|
state: ctx.state
|
|
10974
11494
|
});
|
|
10975
11495
|
await reconcileGitHubPullRequests({
|
|
10976
|
-
annotations: ctx.annotations,
|
|
10977
11496
|
botEmail: readEnv(botEmailEnv),
|
|
11497
|
+
cache: ctx.cache,
|
|
10978
11498
|
codeChanges: ctx.codeChanges,
|
|
10979
11499
|
conversationChanges: ctx.conversationChanges,
|
|
10980
11500
|
db,
|
|
@@ -10984,6 +11504,7 @@ function githubPlugin(options = {}) {
|
|
|
10984
11504
|
log: ctx.log,
|
|
10985
11505
|
nowMs: ctx.nowMs,
|
|
10986
11506
|
inboxItems: ctx.inboxItems,
|
|
11507
|
+
objectChanged: async (subject) => await ctx.annotations.objectChanged(subject),
|
|
10987
11508
|
state: ctx.state
|
|
10988
11509
|
});
|
|
10989
11510
|
await startGitHubRepositoryNameRepair({
|
|
@@ -10994,6 +11515,10 @@ function githubPlugin(options = {}) {
|
|
|
10994
11515
|
state: ctx.state,
|
|
10995
11516
|
tasks: ctx.tasks
|
|
10996
11517
|
});
|
|
11518
|
+
await startGitHubAnnotationNames({
|
|
11519
|
+
state: ctx.state,
|
|
11520
|
+
tasks: ctx.tasks
|
|
11521
|
+
});
|
|
10997
11522
|
await startGitHubPullRequestActionBackfill({
|
|
10998
11523
|
state: ctx.state,
|
|
10999
11524
|
tasks: ctx.tasks
|
|
@@ -11007,7 +11532,7 @@ function githubPlugin(options = {}) {
|
|
|
11007
11532
|
appIdEnv,
|
|
11008
11533
|
installationIdEnv,
|
|
11009
11534
|
privateKeyEnv,
|
|
11010
|
-
responses: ctx.
|
|
11535
|
+
responses: installationResponses(ctx.httpCache, () => readEnv(installationIdEnv)),
|
|
11011
11536
|
tokens: /* @__PURE__ */ new Map()
|
|
11012
11537
|
};
|
|
11013
11538
|
return [createGitHubWebhookRoute({
|
|
@@ -11037,6 +11562,7 @@ function githubPlugin(options = {}) {
|
|
|
11037
11562
|
privateKeyEnv,
|
|
11038
11563
|
events: ctx.events,
|
|
11039
11564
|
inboxItems: ctx.inboxItems,
|
|
11565
|
+
responses: installationEnv.responses,
|
|
11040
11566
|
state: ctx.state,
|
|
11041
11567
|
tasks: ctx.tasks,
|
|
11042
11568
|
tokens: installationEnv.tokens,
|