@sentry/junior-github 0.292.0 → 0.293.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-RRID5LSH.js → chunk-J4ZSG7SD.js} +334 -205
- package/dist/events/comment.d.ts +10 -3
- package/dist/events/issue.d.ts +8 -2
- package/dist/index.js +335 -86
- package/dist/merge-conflict-checks/heartbeat.d.ts +27 -0
- package/dist/merge-conflict-checks/store.d.ts +44 -0
- package/dist/merge-conflict-checks/webhooks.d.ts +23 -0
- package/dist/testing.js +1 -1
- package/dist/webhooks/event-targets.d.ts +26 -0
- package/dist/webhooks/handler.d.ts +2 -1
- package/dist/webhooks/installation-requests.d.ts +9 -0
- package/dist/webhooks/issue-update.d.ts +8 -0
- package/dist/webhooks/merge-conflict.d.ts +3 -1
- package/package.json +2 -2
- package/skills/github-code/references/workflow.md +1 -1
package/dist/events/comment.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { type EventMatchFields } from "@sentry/junior-plugin-api";
|
|
2
2
|
/**
|
|
3
|
-
* Filters on who wrote a
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Filters on the GitHub user who sent the webhook: who wrote a comment or
|
|
4
|
+
* review, or who made an issue update. Resource types that merge these maps
|
|
5
|
+
* keep one description, so it names every case.
|
|
6
|
+
*/
|
|
7
|
+
export declare function gitHubSenderMatchFields(events: readonly string[]): EventMatchFields;
|
|
8
|
+
/**
|
|
9
|
+
* Filters on a GitHub comment or review: who wrote it and whether it mentions
|
|
10
|
+
* the App. Issue comments, pull request comments, reviews, and inline review
|
|
11
|
+
* comments set them, so the issue, pull request, and repository resource types
|
|
12
|
+
* share one definition.
|
|
6
13
|
*/
|
|
7
14
|
export declare function gitHubCommentMatchFields(events: readonly string[]): EventMatchFields;
|
package/dist/events/issue.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { type SubscribableResource } from "@sentry/junior-plugin-api";
|
|
2
2
|
export declare const GITHUB_ISSUE_EVENTS: string[];
|
|
3
3
|
export declare const GITHUB_ISSUE_SUGGESTED_EVENTS: string[];
|
|
4
|
+
/**
|
|
5
|
+
* The `issues` webhook actions that `issue.updated` publishes. The webhook
|
|
6
|
+
* schema and the `change` match field both use this list.
|
|
7
|
+
*/
|
|
8
|
+
export declare const GITHUB_ISSUE_UPDATE_CHANGES: readonly ["edited", "labeled", "unlabeled", "assigned", "unassigned", "milestoned", "demilestoned"];
|
|
4
9
|
/**
|
|
5
10
|
* Exact values GitHub sets on issue event data. Every issue event sets the
|
|
6
|
-
* repository and issue number.
|
|
7
|
-
*
|
|
11
|
+
* repository and issue number. Comments and updates set who acted. Only
|
|
12
|
+
* updates set `change` and `label`, so an automation can run on one label
|
|
13
|
+
* that one person adds without the model deciding from untrusted text.
|
|
8
14
|
*/
|
|
9
15
|
export declare const GITHUB_ISSUE_MATCH_FIELDS: Record<string, {
|
|
10
16
|
kind: "boolean" | "number" | "string";
|
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
readGrantPermissions,
|
|
60
60
|
requireEnv,
|
|
61
61
|
resolveUserAccount
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-J4ZSG7SD.js";
|
|
63
63
|
|
|
64
64
|
// src/tool-support/attribution.ts
|
|
65
65
|
import * as z from "zod";
|
|
@@ -854,11 +854,11 @@ function githubLinkedIssues(body, repositoryFullName) {
|
|
|
854
854
|
if (!body) return [];
|
|
855
855
|
const references = /* @__PURE__ */ new Map();
|
|
856
856
|
const add = (linkedRepository, rawNumber) => {
|
|
857
|
-
const
|
|
858
|
-
if (!Number.isInteger(
|
|
857
|
+
const number26 = Number.parseInt(rawNumber, 10);
|
|
858
|
+
if (!Number.isInteger(number26) || number26 <= 0) return;
|
|
859
859
|
const normalizedRepository = linkedRepository.toLowerCase();
|
|
860
|
-
references.set(`${normalizedRepository}#${
|
|
861
|
-
number:
|
|
860
|
+
references.set(`${normalizedRepository}#${number26}`, {
|
|
861
|
+
number: number26,
|
|
862
862
|
repositoryFullName: linkedRepository
|
|
863
863
|
});
|
|
864
864
|
};
|
|
@@ -2977,13 +2977,13 @@ async function assertBotAuthoredPullRequest(egress, input) {
|
|
|
2977
2977
|
pull_request_url: z19.string().optional()
|
|
2978
2978
|
}).safeParse(commentPayload);
|
|
2979
2979
|
const parentUrl = comment.success ? input.commentKind === "conversation" ? comment.data.issue_url : comment.data.pull_request_url : void 0;
|
|
2980
|
-
const
|
|
2981
|
-
if (!
|
|
2980
|
+
const number26 = /\/(?:issues|pulls)\/(\d+)$/.exec(parentUrl ?? "")?.[1];
|
|
2981
|
+
if (!number26) {
|
|
2982
2982
|
throw new Error("GitHub comment did not name its issue or pull request.");
|
|
2983
2983
|
}
|
|
2984
2984
|
const pullResponse = await githubApi(egress, {
|
|
2985
2985
|
operation: "github.pull.get",
|
|
2986
|
-
path: `${repoPath(input)}/pulls/${
|
|
2986
|
+
path: `${repoPath(input)}/pulls/${number26}`
|
|
2987
2987
|
});
|
|
2988
2988
|
const pullPayload = pullResponse.body;
|
|
2989
2989
|
if (!pullResponse.ok && pullResponse.status !== 404) {
|
|
@@ -3394,7 +3394,7 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
|
3394
3394
|
|
|
3395
3395
|
// src/webhooks/handler.ts
|
|
3396
3396
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
3397
|
-
import * as
|
|
3397
|
+
import * as z33 from "zod";
|
|
3398
3398
|
|
|
3399
3399
|
// src/issue-outcomes/store.ts
|
|
3400
3400
|
import { and as and2, eq as eq2, lte, sql as sql2 } from "drizzle-orm";
|
|
@@ -4093,11 +4093,110 @@ async function loadGitHubMergeConflictEvents(args) {
|
|
|
4093
4093
|
return conflicts;
|
|
4094
4094
|
}
|
|
4095
4095
|
|
|
4096
|
-
// src/
|
|
4096
|
+
// src/merge-conflict-checks/webhooks.ts
|
|
4097
4097
|
import * as z28 from "zod";
|
|
4098
4098
|
|
|
4099
|
-
// src/
|
|
4099
|
+
// src/merge-conflict-checks/store.ts
|
|
4100
|
+
import { and as and4, eq as eq4 } from "drizzle-orm";
|
|
4100
4101
|
import * as z27 from "zod";
|
|
4102
|
+
var CHECK_TTL_MS = 30 * 6e4;
|
|
4103
|
+
var repeatSchema = z27.object({
|
|
4104
|
+
/** Checks since the last push that ended with an unknown answer. */
|
|
4105
|
+
attempts: z27.number().int().positive(),
|
|
4106
|
+
dueAtMs: z27.number()
|
|
4107
|
+
});
|
|
4108
|
+
function pushKey(repositoryFullName) {
|
|
4109
|
+
return `merge-conflict-check:push:${repositoryFullName}`;
|
|
4110
|
+
}
|
|
4111
|
+
function repeatKey(repositoryFullName) {
|
|
4112
|
+
return `merge-conflict-check:repeat:${repositoryFullName}`;
|
|
4113
|
+
}
|
|
4114
|
+
async function listGitHubRepositoriesWithOpenPullRequests(db, repositoryFullName) {
|
|
4115
|
+
const t = juniorGitHubPullRequests;
|
|
4116
|
+
const rows = await db.selectDistinct({ repositoryFullName: t.repositoryFullName }).from(t).where(
|
|
4117
|
+
and4(
|
|
4118
|
+
eq4(t.state, "open"),
|
|
4119
|
+
repositoryFullName ? eq4(t.repositoryFullName, repositoryFullName) : void 0
|
|
4120
|
+
)
|
|
4121
|
+
).orderBy(t.repositoryFullName);
|
|
4122
|
+
return rows.map((row) => row.repositoryFullName);
|
|
4123
|
+
}
|
|
4124
|
+
async function scheduleGitHubConflictCheck(args) {
|
|
4125
|
+
const open = await listGitHubRepositoriesWithOpenPullRequests(
|
|
4126
|
+
args.db,
|
|
4127
|
+
args.repositoryFullName
|
|
4128
|
+
);
|
|
4129
|
+
if (open.length === 0) return false;
|
|
4130
|
+
await args.state.setIfNotExists(
|
|
4131
|
+
pushKey(args.repositoryFullName),
|
|
4132
|
+
args.dueAtMs,
|
|
4133
|
+
CHECK_TTL_MS
|
|
4134
|
+
);
|
|
4135
|
+
return true;
|
|
4136
|
+
}
|
|
4137
|
+
async function claimGitHubConflictCheck(args) {
|
|
4138
|
+
const pushDueAtMs = await args.state.get(
|
|
4139
|
+
pushKey(args.repositoryFullName)
|
|
4140
|
+
);
|
|
4141
|
+
const repeat = repeatSchema.safeParse(
|
|
4142
|
+
await args.state.get(repeatKey(args.repositoryFullName))
|
|
4143
|
+
);
|
|
4144
|
+
let attempts;
|
|
4145
|
+
if (typeof pushDueAtMs === "number" && pushDueAtMs <= args.nowMs) {
|
|
4146
|
+
attempts = 1;
|
|
4147
|
+
} else if (repeat.success && repeat.data.dueAtMs <= args.nowMs) {
|
|
4148
|
+
attempts = repeat.data.attempts + 1;
|
|
4149
|
+
} else {
|
|
4150
|
+
return void 0;
|
|
4151
|
+
}
|
|
4152
|
+
await args.state.set(
|
|
4153
|
+
repeatKey(args.repositoryFullName),
|
|
4154
|
+
{ attempts, dueAtMs: args.claimedUntilMs },
|
|
4155
|
+
CHECK_TTL_MS
|
|
4156
|
+
);
|
|
4157
|
+
if (attempts === 1) await args.state.delete(pushKey(args.repositoryFullName));
|
|
4158
|
+
return { attempts, repositoryFullName: args.repositoryFullName };
|
|
4159
|
+
}
|
|
4160
|
+
async function settleGitHubConflictCheck(state, check, retryAtMs) {
|
|
4161
|
+
if (retryAtMs === void 0) {
|
|
4162
|
+
await state.delete(repeatKey(check.repositoryFullName));
|
|
4163
|
+
return;
|
|
4164
|
+
}
|
|
4165
|
+
await state.set(
|
|
4166
|
+
repeatKey(check.repositoryFullName),
|
|
4167
|
+
{ attempts: check.attempts, dueAtMs: retryAtMs },
|
|
4168
|
+
CHECK_TTL_MS
|
|
4169
|
+
);
|
|
4170
|
+
}
|
|
4171
|
+
|
|
4172
|
+
// src/merge-conflict-checks/webhooks.ts
|
|
4173
|
+
var CONFLICT_CHECK_DELAY_MS = 2 * 6e4;
|
|
4174
|
+
var pushSchema = z28.object({
|
|
4175
|
+
deleted: z28.boolean().optional(),
|
|
4176
|
+
ref: z28.string(),
|
|
4177
|
+
repository: z28.object({
|
|
4178
|
+
default_branch: z28.string().min(1),
|
|
4179
|
+
full_name: z28.string().min(1)
|
|
4180
|
+
})
|
|
4181
|
+
});
|
|
4182
|
+
async function scheduleGitHubPushConflictCheck(args) {
|
|
4183
|
+
const parsed = pushSchema.safeParse(args.body);
|
|
4184
|
+
if (!parsed.success || parsed.data.deleted || parsed.data.ref !== `refs/heads/${parsed.data.repository.default_branch}`) {
|
|
4185
|
+
return false;
|
|
4186
|
+
}
|
|
4187
|
+
return await scheduleGitHubConflictCheck({
|
|
4188
|
+
db: args.db,
|
|
4189
|
+
dueAtMs: args.now.getTime() + CONFLICT_CHECK_DELAY_MS,
|
|
4190
|
+
repositoryFullName: parsed.data.repository.full_name,
|
|
4191
|
+
state: args.state
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4194
|
+
|
|
4195
|
+
// src/webhooks/pull-request-ready.ts
|
|
4196
|
+
import * as z30 from "zod";
|
|
4197
|
+
|
|
4198
|
+
// src/webhooks/installation-requests.ts
|
|
4199
|
+
import * as z29 from "zod";
|
|
4101
4200
|
function splitRepository(fullName, label) {
|
|
4102
4201
|
const [owner, name, ...extra] = fullName.split("/");
|
|
4103
4202
|
if (!owner || !name || extra.length > 0) {
|
|
@@ -4137,6 +4236,28 @@ async function loadPullRequest(env, pullRequest) {
|
|
|
4137
4236
|
{ token: token.token }
|
|
4138
4237
|
);
|
|
4139
4238
|
}
|
|
4239
|
+
async function searchOpenPullRequestMergeability(env, input) {
|
|
4240
|
+
const { name } = splitRepository(
|
|
4241
|
+
input.repositoryFullName,
|
|
4242
|
+
"pull request mergeability"
|
|
4243
|
+
);
|
|
4244
|
+
const token = await issueInstallationToken({
|
|
4245
|
+
...env,
|
|
4246
|
+
permissions: { pull_requests: "read" },
|
|
4247
|
+
repositories: [name]
|
|
4248
|
+
});
|
|
4249
|
+
return await githubRequest("https://api.github.com", "/graphql", {
|
|
4250
|
+
body: {
|
|
4251
|
+
query: "query($query: String!, $after: String) { search(query: $query, type: ISSUE, first: 100, after: $after) { pageInfo { hasNextPage endCursor } nodes { ... on PullRequest { number state mergeable headRefOid baseRefName url } } } }",
|
|
4252
|
+
variables: {
|
|
4253
|
+
after: input.after ?? null,
|
|
4254
|
+
query: `repo:${input.repositoryFullName} is:pr is:open author:${input.author}`
|
|
4255
|
+
}
|
|
4256
|
+
},
|
|
4257
|
+
method: "POST",
|
|
4258
|
+
token: token.token
|
|
4259
|
+
});
|
|
4260
|
+
}
|
|
4140
4261
|
async function markPullRequestFeedbackReviewing(env, target) {
|
|
4141
4262
|
const { owner, name } = splitRepository(target.repo, "pull request feedback");
|
|
4142
4263
|
const token = await issueInstallationToken({
|
|
@@ -4158,9 +4279,9 @@ async function markPullRequestFeedbackReviewing(env, target) {
|
|
|
4158
4279
|
}
|
|
4159
4280
|
);
|
|
4160
4281
|
}
|
|
4161
|
-
var repositoryPermissionSchema =
|
|
4162
|
-
permission:
|
|
4163
|
-
role_name:
|
|
4282
|
+
var repositoryPermissionSchema = z29.object({
|
|
4283
|
+
permission: z29.string().min(1),
|
|
4284
|
+
role_name: z29.string().optional()
|
|
4164
4285
|
});
|
|
4165
4286
|
var REPOSITORY_ROLE_TTL_MS = 10 * 60 * 1e3;
|
|
4166
4287
|
async function loadRepositoryRole(env, cache, target) {
|
|
@@ -4190,19 +4311,19 @@ async function loadRepositoryRole(env, cache, target) {
|
|
|
4190
4311
|
}
|
|
4191
4312
|
);
|
|
4192
4313
|
}
|
|
4193
|
-
var pullRequestSchema4 =
|
|
4194
|
-
auto_merge:
|
|
4195
|
-
draft:
|
|
4196
|
-
html_url:
|
|
4197
|
-
mergeable_state:
|
|
4198
|
-
merged:
|
|
4199
|
-
state:
|
|
4200
|
-
title:
|
|
4314
|
+
var pullRequestSchema4 = z29.object({
|
|
4315
|
+
auto_merge: z29.object({}).nullable().optional(),
|
|
4316
|
+
draft: z29.boolean().optional(),
|
|
4317
|
+
html_url: z29.string().url(),
|
|
4318
|
+
mergeable_state: z29.string().nullable().optional(),
|
|
4319
|
+
merged: z29.boolean(),
|
|
4320
|
+
state: z29.enum(["open", "closed"]),
|
|
4321
|
+
title: z29.string()
|
|
4201
4322
|
});
|
|
4202
|
-
var reviewsSchema =
|
|
4203
|
-
|
|
4204
|
-
state:
|
|
4205
|
-
user:
|
|
4323
|
+
var reviewsSchema = z29.array(
|
|
4324
|
+
z29.object({
|
|
4325
|
+
state: z29.string(),
|
|
4326
|
+
user: z29.object({ login: z29.string() }).nullable()
|
|
4206
4327
|
})
|
|
4207
4328
|
);
|
|
4208
4329
|
async function loadPullRequestMergeState(env, pullRequest) {
|
|
@@ -4270,10 +4391,10 @@ var READY_ACTIONS = {
|
|
|
4270
4391
|
]),
|
|
4271
4392
|
pull_request_review: /* @__PURE__ */ new Set(["dismissed", "submitted"])
|
|
4272
4393
|
};
|
|
4273
|
-
var pullRequestWebhookSchema =
|
|
4274
|
-
action:
|
|
4275
|
-
pull_request:
|
|
4276
|
-
repository:
|
|
4394
|
+
var pullRequestWebhookSchema = z30.object({
|
|
4395
|
+
action: z30.string(),
|
|
4396
|
+
pull_request: z30.object({ number: z30.number().int().positive() }),
|
|
4397
|
+
repository: z30.object({ full_name: z30.string().min(1) })
|
|
4277
4398
|
});
|
|
4278
4399
|
function pullRequestReadyTargets(eventName, body) {
|
|
4279
4400
|
if (eventName === "check_suite") return checkSuitePullRequests(body);
|
|
@@ -4371,7 +4492,7 @@ async function syncGitHubPullRequestReadyNotices(args) {
|
|
|
4371
4492
|
}
|
|
4372
4493
|
|
|
4373
4494
|
// src/webhooks/pull-request-match-data.ts
|
|
4374
|
-
import * as
|
|
4495
|
+
import * as z31 from "zod";
|
|
4375
4496
|
var LOOKUPS_BY_MATCH_KEY = {
|
|
4376
4497
|
authors: ["authors"],
|
|
4377
4498
|
openerEmail: ["opener"],
|
|
@@ -4379,22 +4500,22 @@ var LOOKUPS_BY_MATCH_KEY = {
|
|
|
4379
4500
|
openerUsername: ["opener"]
|
|
4380
4501
|
};
|
|
4381
4502
|
var ALL_LOOKUPS = ["authors", "opener", "openerRole"];
|
|
4382
|
-
var lookupDataSchema =
|
|
4383
|
-
authors:
|
|
4384
|
-
openerRole:
|
|
4385
|
-
openerUsername:
|
|
4503
|
+
var lookupDataSchema = z31.object({
|
|
4504
|
+
authors: z31.array(z31.string().min(1)).min(1).optional(),
|
|
4505
|
+
openerRole: z31.string().min(1).optional(),
|
|
4506
|
+
openerUsername: z31.string().min(1).optional()
|
|
4386
4507
|
}).strict();
|
|
4387
4508
|
function lookupData(input) {
|
|
4388
4509
|
return lookupDataSchema.parse(definedValues(input));
|
|
4389
4510
|
}
|
|
4390
|
-
var webhookSchema =
|
|
4391
|
-
repository:
|
|
4511
|
+
var webhookSchema = z31.object({
|
|
4512
|
+
repository: z31.object({ full_name: z31.string().min(1) })
|
|
4392
4513
|
});
|
|
4393
4514
|
function pullRequestNumbers(events) {
|
|
4394
4515
|
const numbers = /* @__PURE__ */ new Map();
|
|
4395
4516
|
for (const event of events) {
|
|
4396
|
-
const
|
|
4397
|
-
if (typeof
|
|
4517
|
+
const number26 = event.data?.pullRequest;
|
|
4518
|
+
if (typeof number26 === "number") numbers.set(event.eventKey, number26);
|
|
4398
4519
|
}
|
|
4399
4520
|
return numbers;
|
|
4400
4521
|
}
|
|
@@ -4408,8 +4529,8 @@ function logFailure(context, lookup, error) {
|
|
|
4408
4529
|
}
|
|
4409
4530
|
async function withJuniorOpeners(context, events) {
|
|
4410
4531
|
const botNumber = (event) => {
|
|
4411
|
-
const
|
|
4412
|
-
return
|
|
4532
|
+
const number26 = context.numbers.get(event.eventKey);
|
|
4533
|
+
return number26 !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number26 : void 0;
|
|
4413
4534
|
};
|
|
4414
4535
|
const numbers = events.flatMap((event) => botNumber(event) ?? []);
|
|
4415
4536
|
if (numbers.length === 0) return events;
|
|
@@ -4428,9 +4549,9 @@ async function withJuniorOpeners(context, events) {
|
|
|
4428
4549
|
}
|
|
4429
4550
|
}
|
|
4430
4551
|
return events.map((event) => {
|
|
4431
|
-
const
|
|
4432
|
-
if (
|
|
4433
|
-
const identityId = openers.get(
|
|
4552
|
+
const number26 = botNumber(event);
|
|
4553
|
+
if (number26 === void 0) return event;
|
|
4554
|
+
const identityId = openers.get(number26)?.identityId;
|
|
4434
4555
|
const login = identityId ? logins.get(identityId) : void 0;
|
|
4435
4556
|
const {
|
|
4436
4557
|
openerEmail: _email,
|
|
@@ -4452,8 +4573,8 @@ async function withRolesAndAuthors(context, events, lookups) {
|
|
|
4452
4573
|
if (!loadRole && !loadAuthors) return events;
|
|
4453
4574
|
return await Promise.all(
|
|
4454
4575
|
events.map(async (event) => {
|
|
4455
|
-
const
|
|
4456
|
-
if (
|
|
4576
|
+
const number26 = context.numbers.get(event.eventKey);
|
|
4577
|
+
if (number26 === void 0) return event;
|
|
4457
4578
|
const login = event.data?.openerUsername;
|
|
4458
4579
|
if (loadRole && typeof login === "string" && !roles.has(login)) {
|
|
4459
4580
|
roles.set(
|
|
@@ -4463,16 +4584,16 @@ async function withRolesAndAuthors(context, events, lookups) {
|
|
|
4463
4584
|
)
|
|
4464
4585
|
);
|
|
4465
4586
|
}
|
|
4466
|
-
if (loadAuthors && !authors.has(
|
|
4587
|
+
if (loadAuthors && !authors.has(number26)) {
|
|
4467
4588
|
authors.set(
|
|
4468
|
-
|
|
4469
|
-
loadAuthors({ number:
|
|
4589
|
+
number26,
|
|
4590
|
+
loadAuthors({ number: number26, repositoryFullName }).catch(
|
|
4470
4591
|
(error) => logFailure(context, "authors", error)
|
|
4471
4592
|
)
|
|
4472
4593
|
);
|
|
4473
4594
|
}
|
|
4474
4595
|
const role = loadRole && typeof login === "string" ? await roles.get(login) : void 0;
|
|
4475
|
-
const logins = loadAuthors ? await authors.get(
|
|
4596
|
+
const logins = loadAuthors ? await authors.get(number26) : void 0;
|
|
4476
4597
|
if (!role && !logins?.length) return event;
|
|
4477
4598
|
return {
|
|
4478
4599
|
...event,
|
|
@@ -4529,7 +4650,7 @@ async function withGitHubPullRequestMatchData(args) {
|
|
|
4529
4650
|
}
|
|
4530
4651
|
|
|
4531
4652
|
// src/webhooks/pull-request-people.ts
|
|
4532
|
-
import * as
|
|
4653
|
+
import * as z32 from "zod";
|
|
4533
4654
|
var PEOPLE_EVENTS = /* @__PURE__ */ new Set([
|
|
4534
4655
|
"pull_request.review.approved",
|
|
4535
4656
|
"pull_request.merged"
|
|
@@ -4539,18 +4660,18 @@ var PAGE_SIZE = 100;
|
|
|
4539
4660
|
var MAX_PAGES = 3;
|
|
4540
4661
|
var CO_AUTHOR_TRAILER = /^co-authored-by:[^<\n]*<([^>\s]+@[^>\s]+)>\s*$/gim;
|
|
4541
4662
|
var GITHUB_NOREPLY_EMAIL = /^(?:\d+\+)?(?<login>[^@+]+)@users\.noreply\.github\.com$/i;
|
|
4542
|
-
var webhookSchema2 =
|
|
4543
|
-
pull_request:
|
|
4544
|
-
assignees:
|
|
4545
|
-
number:
|
|
4546
|
-
user:
|
|
4663
|
+
var webhookSchema2 = z32.object({
|
|
4664
|
+
pull_request: z32.object({
|
|
4665
|
+
assignees: z32.array(z32.object({ login: z32.string().min(1) })).nullish(),
|
|
4666
|
+
number: z32.number(),
|
|
4667
|
+
user: z32.object({ login: z32.string().min(1) }).nullish()
|
|
4547
4668
|
}),
|
|
4548
|
-
repository:
|
|
4669
|
+
repository: z32.object({ full_name: z32.string().min(1) })
|
|
4549
4670
|
});
|
|
4550
|
-
var commitPageSchema =
|
|
4551
|
-
|
|
4552
|
-
author:
|
|
4553
|
-
commit:
|
|
4671
|
+
var commitPageSchema = z32.array(
|
|
4672
|
+
z32.object({
|
|
4673
|
+
author: z32.object({ login: z32.string().min(1) }).nullish(),
|
|
4674
|
+
commit: z32.object({ message: z32.string() })
|
|
4554
4675
|
})
|
|
4555
4676
|
);
|
|
4556
4677
|
function shareCommitPages(load) {
|
|
@@ -4692,10 +4813,10 @@ function webhookInstallationId(body) {
|
|
|
4692
4813
|
}
|
|
4693
4814
|
return parseInstallationId(installation.id);
|
|
4694
4815
|
}
|
|
4695
|
-
var feedbackTargetSchema =
|
|
4696
|
-
commentId:
|
|
4697
|
-
commentKind:
|
|
4698
|
-
repo:
|
|
4816
|
+
var feedbackTargetSchema = z33.object({
|
|
4817
|
+
commentId: z33.number(),
|
|
4818
|
+
commentKind: z33.enum(["conversation", "review"]),
|
|
4819
|
+
repo: z33.string().min(1)
|
|
4699
4820
|
});
|
|
4700
4821
|
function pullRequestFeedbackTarget(events) {
|
|
4701
4822
|
const event = events.find(
|
|
@@ -4748,6 +4869,17 @@ function createGitHubWebhookRoute(args) {
|
|
|
4748
4869
|
if (webhookInstallationId(body) !== installationId) {
|
|
4749
4870
|
return new Response("Ignored", { status: 202 });
|
|
4750
4871
|
}
|
|
4872
|
+
if (eventName === "push") {
|
|
4873
|
+
const scheduled = await scheduleGitHubPushConflictCheck({
|
|
4874
|
+
body,
|
|
4875
|
+
db: args.db,
|
|
4876
|
+
now: /* @__PURE__ */ new Date(),
|
|
4877
|
+
state: args.state
|
|
4878
|
+
});
|
|
4879
|
+
return new Response(scheduled ? "Accepted" : "Ignored", {
|
|
4880
|
+
status: 202
|
|
4881
|
+
});
|
|
4882
|
+
}
|
|
4751
4883
|
const botEmail = args.botEmail();
|
|
4752
4884
|
const pullRequestOutcome = eventName === "pull_request" ? normalizeGitHubPullRequestOutcome({ body, botEmail }) : void 0;
|
|
4753
4885
|
const issueOutcome = eventName === "issues" ? normalizeGitHubIssueOutcome({ body, botEmail }) : void 0;
|
|
@@ -4940,6 +5072,103 @@ function createGitHubWebhookRoute(args) {
|
|
|
4940
5072
|
};
|
|
4941
5073
|
}
|
|
4942
5074
|
|
|
5075
|
+
// src/merge-conflict-checks/heartbeat.ts
|
|
5076
|
+
import * as z34 from "zod";
|
|
5077
|
+
var CHECK_LIMIT = 10;
|
|
5078
|
+
var MAX_PAGES2 = 5;
|
|
5079
|
+
var CLAIM_MS = 5 * 6e4;
|
|
5080
|
+
var UNKNOWN_RETRY_MS = 6e4;
|
|
5081
|
+
var MAX_ATTEMPTS = 5;
|
|
5082
|
+
var searchNodeSchema = z34.union([
|
|
5083
|
+
z34.object({
|
|
5084
|
+
baseRefName: z34.string().min(1),
|
|
5085
|
+
headRefOid: z34.string().min(1),
|
|
5086
|
+
mergeable: z34.enum(["CONFLICTING", "MERGEABLE", "UNKNOWN"]),
|
|
5087
|
+
number: z34.number().int().positive(),
|
|
5088
|
+
state: z34.string(),
|
|
5089
|
+
url: z34.string().min(1)
|
|
5090
|
+
}),
|
|
5091
|
+
z34.object({}).strict()
|
|
5092
|
+
]);
|
|
5093
|
+
var searchResponseSchema = z34.object({
|
|
5094
|
+
data: z34.object({
|
|
5095
|
+
search: z34.object({
|
|
5096
|
+
nodes: z34.array(searchNodeSchema.nullable()),
|
|
5097
|
+
pageInfo: z34.object({
|
|
5098
|
+
endCursor: z34.string().nullable(),
|
|
5099
|
+
hasNextPage: z34.boolean()
|
|
5100
|
+
})
|
|
5101
|
+
})
|
|
5102
|
+
})
|
|
5103
|
+
});
|
|
5104
|
+
async function checkRepository(args, repositoryFullName) {
|
|
5105
|
+
let unknown2 = false;
|
|
5106
|
+
let after;
|
|
5107
|
+
for (let page = 0; page < MAX_PAGES2; page += 1) {
|
|
5108
|
+
const { search } = searchResponseSchema.parse(
|
|
5109
|
+
await args.search({ after, repositoryFullName })
|
|
5110
|
+
).data;
|
|
5111
|
+
for (const node of search.nodes) {
|
|
5112
|
+
if (!node || !("number" in node) || node.state !== "OPEN") continue;
|
|
5113
|
+
if (node.mergeable === "UNKNOWN") unknown2 = true;
|
|
5114
|
+
if (node.mergeable !== "CONFLICTING") continue;
|
|
5115
|
+
const events = gitHubMergeConflictEvents({
|
|
5116
|
+
conflict: {
|
|
5117
|
+
baseBranch: node.baseRefName,
|
|
5118
|
+
headSha: node.headRefOid,
|
|
5119
|
+
url: node.url
|
|
5120
|
+
},
|
|
5121
|
+
number: node.number,
|
|
5122
|
+
repositoryFullName
|
|
5123
|
+
});
|
|
5124
|
+
if (!await args.events.hasMatch?.(events)) continue;
|
|
5125
|
+
for (const event of events) await args.events.publish(event);
|
|
5126
|
+
}
|
|
5127
|
+
if (!search.pageInfo.hasNextPage || !search.pageInfo.endCursor) break;
|
|
5128
|
+
after = search.pageInfo.endCursor;
|
|
5129
|
+
}
|
|
5130
|
+
return unknown2;
|
|
5131
|
+
}
|
|
5132
|
+
async function runCheck(args, check) {
|
|
5133
|
+
let unknown2;
|
|
5134
|
+
try {
|
|
5135
|
+
unknown2 = await checkRepository(args, check.repositoryFullName);
|
|
5136
|
+
} catch (error) {
|
|
5137
|
+
args.log.error("GitHub merge conflict check failed", {
|
|
5138
|
+
attempts: check.attempts,
|
|
5139
|
+
errorType: error instanceof Error ? error.name : "UnknownError",
|
|
5140
|
+
repository: check.repositoryFullName
|
|
5141
|
+
});
|
|
5142
|
+
if (check.attempts >= MAX_ATTEMPTS) {
|
|
5143
|
+
await settleGitHubConflictCheck(args.state, check);
|
|
5144
|
+
}
|
|
5145
|
+
return;
|
|
5146
|
+
}
|
|
5147
|
+
await settleGitHubConflictCheck(
|
|
5148
|
+
args.state,
|
|
5149
|
+
check,
|
|
5150
|
+
unknown2 && check.attempts < MAX_ATTEMPTS ? args.now.getTime() + UNKNOWN_RETRY_MS : void 0
|
|
5151
|
+
);
|
|
5152
|
+
}
|
|
5153
|
+
async function runGitHubConflictChecks(args) {
|
|
5154
|
+
const nowMs = args.now.getTime();
|
|
5155
|
+
let checked = 0;
|
|
5156
|
+
for (const repositoryFullName of await listGitHubRepositoriesWithOpenPullRequests(
|
|
5157
|
+
args.db
|
|
5158
|
+
)) {
|
|
5159
|
+
if (checked >= CHECK_LIMIT) break;
|
|
5160
|
+
const check = await claimGitHubConflictCheck({
|
|
5161
|
+
claimedUntilMs: nowMs + CLAIM_MS,
|
|
5162
|
+
nowMs,
|
|
5163
|
+
repositoryFullName,
|
|
5164
|
+
state: args.state
|
|
5165
|
+
});
|
|
5166
|
+
if (!check) continue;
|
|
5167
|
+
checked += 1;
|
|
5168
|
+
await runCheck(args, check);
|
|
5169
|
+
}
|
|
5170
|
+
}
|
|
5171
|
+
|
|
4943
5172
|
// src/events/declarations.ts
|
|
4944
5173
|
var NEEDS_REPO = { anyOf: ["repo"] };
|
|
4945
5174
|
function gitHubEventDeclarations(pullRequestGuidance) {
|
|
@@ -4964,30 +5193,30 @@ function gitHubResourceUrl(input) {
|
|
|
4964
5193
|
if (input.resourceType === "repository") {
|
|
4965
5194
|
return `https://github.com/${input.identifier}`;
|
|
4966
5195
|
}
|
|
4967
|
-
const [repo,
|
|
4968
|
-
if (!repo || !
|
|
5196
|
+
const [repo, number26] = input.identifier.split("#");
|
|
5197
|
+
if (!repo || !number26) return void 0;
|
|
4969
5198
|
if (input.resourceType === "pull_request") {
|
|
4970
|
-
return `https://github.com/${repo}/pull/${
|
|
5199
|
+
return `https://github.com/${repo}/pull/${number26}`;
|
|
4971
5200
|
}
|
|
4972
5201
|
if (input.resourceType === "issue") {
|
|
4973
|
-
return `https://github.com/${repo}/issues/${
|
|
5202
|
+
return `https://github.com/${repo}/issues/${number26}`;
|
|
4974
5203
|
}
|
|
4975
5204
|
return void 0;
|
|
4976
5205
|
}
|
|
4977
5206
|
|
|
4978
5207
|
// src/pull-request-outcomes/commit-composition.ts
|
|
4979
|
-
import * as
|
|
4980
|
-
var canonicalCommitSchema =
|
|
4981
|
-
authorEmail:
|
|
4982
|
-
authorLogin:
|
|
5208
|
+
import * as z35 from "zod";
|
|
5209
|
+
var canonicalCommitSchema = z35.object({
|
|
5210
|
+
authorEmail: z35.string().nullable(),
|
|
5211
|
+
authorLogin: z35.string().nullable()
|
|
4983
5212
|
}).strict();
|
|
4984
|
-
var providerCommitSchema =
|
|
4985
|
-
author:
|
|
4986
|
-
commit:
|
|
4987
|
-
author:
|
|
5213
|
+
var providerCommitSchema = z35.object({
|
|
5214
|
+
author: z35.object({ login: z35.string() }).passthrough().nullable(),
|
|
5215
|
+
commit: z35.object({
|
|
5216
|
+
author: z35.object({ email: z35.string() }).passthrough().nullable()
|
|
4988
5217
|
}).passthrough()
|
|
4989
5218
|
}).passthrough();
|
|
4990
|
-
var commitPageSchema2 =
|
|
5219
|
+
var commitPageSchema2 = z35.array(providerCommitSchema).transform(
|
|
4991
5220
|
(commits) => commits.map(
|
|
4992
5221
|
(commit) => canonicalCommitSchema.parse({
|
|
4993
5222
|
authorEmail: commit.commit.author?.email ?? null,
|
|
@@ -4996,7 +5225,7 @@ var commitPageSchema2 = z32.array(providerCommitSchema).transform(
|
|
|
4996
5225
|
)
|
|
4997
5226
|
);
|
|
4998
5227
|
var PAGE_SIZE2 = 100;
|
|
4999
|
-
var
|
|
5228
|
+
var MAX_PAGES3 = 3;
|
|
5000
5229
|
var MAX_LISTED_COMMITS = 250;
|
|
5001
5230
|
async function classifyGitHubPullRequestCommitComposition(args) {
|
|
5002
5231
|
const botEmail = args.botEmail.trim().toLowerCase();
|
|
@@ -5007,7 +5236,7 @@ async function classifyGitHubPullRequestCommitComposition(args) {
|
|
|
5007
5236
|
}
|
|
5008
5237
|
let foundCommit = false;
|
|
5009
5238
|
let inspectedCommits = 0;
|
|
5010
|
-
for (let page = 1; page <=
|
|
5239
|
+
for (let page = 1; page <= MAX_PAGES3; page += 1) {
|
|
5011
5240
|
const commits = commitPageSchema2.parse(
|
|
5012
5241
|
await args.loadPage(page, PAGE_SIZE2)
|
|
5013
5242
|
);
|
|
@@ -5021,7 +5250,7 @@ async function classifyGitHubPullRequestCommitComposition(args) {
|
|
|
5021
5250
|
}
|
|
5022
5251
|
if (inspectedCommits >= MAX_LISTED_COMMITS) return void 0;
|
|
5023
5252
|
if (commits.length < PAGE_SIZE2) break;
|
|
5024
|
-
if (page ===
|
|
5253
|
+
if (page === MAX_PAGES3) return void 0;
|
|
5025
5254
|
}
|
|
5026
5255
|
return foundCommit ? "junior_only" : void 0;
|
|
5027
5256
|
}
|
|
@@ -5494,8 +5723,8 @@ function linkifyLine(line) {
|
|
|
5494
5723
|
if (isReferenceBoundary(index2 === 0 ? void 0 : line[index2 - 1])) {
|
|
5495
5724
|
const match = GITHUB_ISSUE_REFERENCE_PATTERN.exec(line.slice(index2));
|
|
5496
5725
|
if (match) {
|
|
5497
|
-
const [reference, owner, repository2,
|
|
5498
|
-
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${
|
|
5726
|
+
const [reference, owner, repository2, number26] = match;
|
|
5727
|
+
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number26})`;
|
|
5499
5728
|
index2 += reference.length;
|
|
5500
5729
|
continue;
|
|
5501
5730
|
}
|
|
@@ -5637,9 +5866,9 @@ function parseGitHubReferences(text2, config) {
|
|
|
5637
5866
|
}
|
|
5638
5867
|
return [...references.values()];
|
|
5639
5868
|
}
|
|
5640
|
-
function objectTitle(kind,
|
|
5641
|
-
if (!isRecord(
|
|
5642
|
-
const raw = kind === "commit" ? isRecord(
|
|
5869
|
+
function objectTitle(kind, object35) {
|
|
5870
|
+
if (!isRecord(object35)) return void 0;
|
|
5871
|
+
const raw = kind === "commit" ? isRecord(object35.commit) && typeof object35.commit.message === "string" ? object35.commit.message.split("\n")[0] : void 0 : typeof object35.title === "string" ? object35.title : void 0;
|
|
5643
5872
|
return raw?.replace(/\s+/g, " ").trim() || void 0;
|
|
5644
5873
|
}
|
|
5645
5874
|
async function loadGitHubConversationTitleContext(args) {
|
|
@@ -6550,6 +6779,25 @@ function githubPlugin(options = {}) {
|
|
|
6550
6779
|
formatMarkdown({ text: text2 }) {
|
|
6551
6780
|
return linkifyGitHubReferences(text2);
|
|
6552
6781
|
},
|
|
6782
|
+
async heartbeat(ctx) {
|
|
6783
|
+
await runGitHubConflictChecks({
|
|
6784
|
+
db: ctx.db,
|
|
6785
|
+
events: ctx.events,
|
|
6786
|
+
log: ctx.log,
|
|
6787
|
+
now: new Date(ctx.nowMs),
|
|
6788
|
+
search: async (input) => {
|
|
6789
|
+
const login = botLoginFromEmail(requireEnv(botEmailEnv));
|
|
6790
|
+
if (!login) {
|
|
6791
|
+
throw new Error(`${botEmailEnv} is not a GitHub bot address`);
|
|
6792
|
+
}
|
|
6793
|
+
return await searchOpenPullRequestMergeability(
|
|
6794
|
+
{ appIdEnv, installationIdEnv, privateKeyEnv },
|
|
6795
|
+
{ ...input, author: `app/${login.replace(/\[bot\]$/, "")}` }
|
|
6796
|
+
);
|
|
6797
|
+
},
|
|
6798
|
+
state: ctx.state
|
|
6799
|
+
});
|
|
6800
|
+
},
|
|
6553
6801
|
async unfinishedWork(ctx) {
|
|
6554
6802
|
const db = ctx.db;
|
|
6555
6803
|
const [
|
|
@@ -6604,6 +6852,7 @@ function githubPlugin(options = {}) {
|
|
|
6604
6852
|
privateKeyEnv,
|
|
6605
6853
|
events: ctx.events,
|
|
6606
6854
|
reviewItems: ctx.reviewItems,
|
|
6855
|
+
state: ctx.state,
|
|
6607
6856
|
webhookSecret: () => readEnv("GITHUB_WEBHOOK_SECRET")
|
|
6608
6857
|
})
|
|
6609
6858
|
];
|