@sentry/junior-github 0.269.0 → 0.271.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.
@@ -184,11 +184,13 @@ var GITHUB_PULL_REQUEST_EVENTS = [
184
184
  "pull_request.review.commented",
185
185
  "pull_request.review_comment.created",
186
186
  "pull_request.merged",
187
- "pull_request.closed_unmerged"
187
+ "pull_request.closed_unmerged",
188
+ "pull_request.merge_conflict"
188
189
  ];
189
190
  var GITHUB_PULL_REQUEST_EVENT_GUIDANCE = {
190
191
  "pull_request.comment.created": 'After acting on actionable feedback, call github_updatePullRequestFeedback with the exact repo, commentId, and commentKind from Verified details, and status "addressed" or "declined".',
191
- "pull_request.review_comment.created": 'After acting on actionable feedback, call github_updatePullRequestFeedback with the exact repo, commentId, and commentKind from Verified details, and status "addressed" or "declined". Then resolve the thread with github_resolvePullRequestReviewThread.'
192
+ "pull_request.review_comment.created": 'After acting on actionable feedback, call github_updatePullRequestFeedback with the exact repo, commentId, and commentKind from Verified details, and status "addressed" or "declined". Then resolve the thread with github_resolvePullRequestReviewThread.',
193
+ "pull_request.merge_conflict": "Fetch baseBranch from Verified details and merge it into the pull request branch. Do not rebase. Resolve each conflict so that both the pull request change and the base branch change stay intact. Run the checks again, push, and confirm that the pull request can merge. Report the files that had conflicts."
192
194
  };
193
195
  function gitHubPullRequestEventGuidance(guidance) {
194
196
  const merged = { ...GITHUB_PULL_REQUEST_EVENT_GUIDANCE };
@@ -209,7 +211,15 @@ function gitHubPullRequestCreateWatch(config) {
209
211
  GITHUB_PULL_REQUEST_OUTCOME_GUIDANCE
210
212
  );
211
213
  return {
212
- events: [.../* @__PURE__ */ new Set([...config.events, ...outcomeEvents])],
214
+ events: [
215
+ .../* @__PURE__ */ new Set([
216
+ ...config.events,
217
+ // GitHub sends no webhook for a new conflict, so keep the pull
218
+ // request ready to merge even when the app config omits this event.
219
+ "pull_request.merge_conflict",
220
+ ...outcomeEvents
221
+ ])
222
+ ],
213
223
  guidance: GITHUB_PULL_REQUEST_OUTCOME_GUIDANCE,
214
224
  intent: config.intent
215
225
  };
@@ -222,8 +232,12 @@ var GITHUB_PULL_REQUEST_SUGGESTED_EVENTS = [
222
232
  "pull_request.review.commented",
223
233
  "pull_request.review_comment.created",
224
234
  "pull_request.merged",
225
- "pull_request.closed_unmerged"
235
+ "pull_request.closed_unmerged",
236
+ "pull_request.merge_conflict"
226
237
  ];
238
+ var GITHUB_PULL_REQUEST_PAYLOAD_EVENTS = GITHUB_PULL_REQUEST_EVENTS.filter(
239
+ (eventType) => eventType !== "pull_request.merge_conflict"
240
+ );
227
241
  var GITHUB_PULL_REQUEST_COMMENT_EVENTS = [
228
242
  "pull_request.comment.created",
229
243
  "pull_request.review.approved",
@@ -248,34 +262,34 @@ var GITHUB_PULL_REQUEST_MATCH_FIELDS = eventMatchFieldsSchema5.parse({
248
262
  kind: "string",
249
263
  list: true,
250
264
  description: "GitHub logins of the commit authors and Co-authored-by people, including bots such as this GitHub App",
251
- events: [...GITHUB_PULL_REQUEST_EVENTS]
265
+ events: [...GITHUB_PULL_REQUEST_PAYLOAD_EVENTS]
252
266
  },
253
267
  headBranch: {
254
268
  kind: "string",
255
269
  description: "head branch name from the webhook",
256
- events: GITHUB_PULL_REQUEST_EVENTS.filter(
270
+ events: GITHUB_PULL_REQUEST_PAYLOAD_EVENTS.filter(
257
271
  (eventType) => eventType !== "pull_request.comment.created"
258
272
  )
259
273
  },
260
274
  isDraft: {
261
275
  kind: "boolean",
262
276
  description: "true when the pull request is a draft",
263
- events: [...GITHUB_PULL_REQUEST_EVENTS]
277
+ events: [...GITHUB_PULL_REQUEST_PAYLOAD_EVENTS]
264
278
  },
265
279
  openerEmail: {
266
280
  kind: "string",
267
281
  description: "opener email when GitHub sends it; missing on pull requests that this GitHub App opened",
268
- events: [...GITHUB_PULL_REQUEST_EVENTS]
282
+ events: [...GITHUB_PULL_REQUEST_PAYLOAD_EVENTS]
269
283
  },
270
284
  openerUsername: {
271
285
  kind: "string",
272
286
  description: "login of who opened the pull request; on pull requests that this GitHub App opened, the person who asked for it, missing until that person is saved",
273
- events: [...GITHUB_PULL_REQUEST_EVENTS]
287
+ events: [...GITHUB_PULL_REQUEST_PAYLOAD_EVENTS]
274
288
  },
275
289
  openerRole: {
276
290
  kind: "string",
277
291
  description: "opener's repository role: admin, maintain, write, triage, read, none (no access, such as most bots), or a custom role name",
278
- events: [...GITHUB_PULL_REQUEST_EVENTS]
292
+ events: [...GITHUB_PULL_REQUEST_PAYLOAD_EVENTS]
279
293
  }
280
294
  });
281
295
  var GITHUB_PULL_REQUEST_IDENTIFIER = {
@@ -2194,6 +2208,7 @@ export {
2194
2208
  GITHUB_PULL_REQUEST_SUGGESTED_EVENTS,
2195
2209
  GITHUB_PULL_REQUEST_MATCH_FIELDS,
2196
2210
  GITHUB_PULL_REQUEST_IDENTIFIER,
2211
+ gitHubPullRequestResource,
2197
2212
  gitHubPullRequestSubscribable,
2198
2213
  GITHUB_RELEASE_EVENTS,
2199
2214
  GITHUB_RELEASE_MATCH_FIELDS,
@@ -2228,6 +2243,7 @@ export {
2228
2243
  issueGitHubCredential,
2229
2244
  createPermissionCache,
2230
2245
  definedValues,
2246
+ pullRequestTargets,
2231
2247
  checkSuitePullRequests,
2232
2248
  parseCheckSuitePublishTargets,
2233
2249
  needsCheckSuitePullRequestFacts,
@@ -1,5 +1,5 @@
1
1
  import { type SubscribableResource } from "@sentry/junior-plugin-api";
2
- export declare const GITHUB_PULL_REQUEST_EVENTS: readonly ["pull_request.checks.failed", "pull_request.checks.recovered", "pull_request.comment.created", "pull_request.opened", "pull_request.ready_for_review", "pull_request.review.approved", "pull_request.review.changes_requested", "pull_request.review.commented", "pull_request.review_comment.created", "pull_request.merged", "pull_request.closed_unmerged"];
2
+ export declare const GITHUB_PULL_REQUEST_EVENTS: readonly ["pull_request.checks.failed", "pull_request.checks.recovered", "pull_request.comment.created", "pull_request.opened", "pull_request.ready_for_review", "pull_request.review.approved", "pull_request.review.changes_requested", "pull_request.review.commented", "pull_request.review_comment.created", "pull_request.merged", "pull_request.closed_unmerged", "pull_request.merge_conflict"];
3
3
  export type GitHubPullRequestEvent = (typeof GITHUB_PULL_REQUEST_EVENTS)[number];
4
4
  /** Combine provider defaults with app guidance for pull request events. */
5
5
  export declare function gitHubPullRequestEventGuidance(guidance?: Partial<Record<GitHubPullRequestEvent, string>>): Partial<Record<GitHubPullRequestEvent, string>>;
@@ -21,13 +21,16 @@ export declare function gitHubPullRequestCreateWatch(config: GitHubPullRequestSu
21
21
  guidance: Partial<Record<GitHubPullRequestEvent, string>>;
22
22
  intent: string;
23
23
  };
24
- export declare const GITHUB_PULL_REQUEST_SUGGESTED_EVENTS: readonly ["pull_request.checks.failed", "pull_request.comment.created", "pull_request.ready_for_review", "pull_request.review.changes_requested", "pull_request.review.commented", "pull_request.review_comment.created", "pull_request.merged", "pull_request.closed_unmerged"];
24
+ export declare const GITHUB_PULL_REQUEST_SUGGESTED_EVENTS: readonly ["pull_request.checks.failed", "pull_request.comment.created", "pull_request.ready_for_review", "pull_request.review.changes_requested", "pull_request.review.commented", "pull_request.review_comment.created", "pull_request.merged", "pull_request.closed_unmerged", "pull_request.merge_conflict"];
25
25
  /**
26
26
  * Exact values GitHub may set on pull request event data. Missing keys do not
27
27
  * match. The opener and author values load in
28
- * `webhooks/pull-request-match-data.ts` for every pull request event. The
29
- * pull request comment webhook has no head branch. A check suite result that
30
- * GitHub links to no pull request has no `pullRequest`.
28
+ * `webhooks/pull-request-match-data.ts` for every payload pull request event.
29
+ * The pull request comment webhook has no head branch. A check suite result
30
+ * that GitHub links to no pull request has no `pullRequest`. The webhook
31
+ * checks for a Watch or event automation before it reads a pull request for
32
+ * a conflict, so `pull_request.merge_conflict` matches only `repo` and
33
+ * `pullRequest`.
31
34
  */
32
35
  export declare const GITHUB_PULL_REQUEST_MATCH_FIELDS: Record<string, {
33
36
  kind: "boolean" | "number" | "string";
@@ -9,9 +9,9 @@ export declare function gitHubRepositoryResource(input: {
9
9
  repo: string;
10
10
  }): Pick<SubscribableResource, "label" | "namespace" | "identifier">;
11
11
  /** Events that a repository Watch gets: deployments, issues, and pull requests. */
12
- export declare const GITHUB_REPOSITORY_EVENTS: readonly ["deployment.created", "deployment.queued", "deployment.pending", "deployment.in_progress", "deployment.succeeded", "deployment.failed", "deployment.error", ...string[], "pull_request.checks.failed", "pull_request.checks.recovered", "pull_request.comment.created", "pull_request.opened", "pull_request.ready_for_review", "pull_request.review.approved", "pull_request.review.changes_requested", "pull_request.review.commented", "pull_request.review_comment.created", "pull_request.merged", "pull_request.closed_unmerged"];
12
+ export declare const GITHUB_REPOSITORY_EVENTS: readonly ["deployment.created", "deployment.queued", "deployment.pending", "deployment.in_progress", "deployment.succeeded", "deployment.failed", "deployment.error", ...string[], "pull_request.checks.failed", "pull_request.checks.recovered", "pull_request.comment.created", "pull_request.opened", "pull_request.ready_for_review", "pull_request.review.approved", "pull_request.review.changes_requested", "pull_request.review.commented", "pull_request.review_comment.created", "pull_request.merged", "pull_request.closed_unmerged", "pull_request.merge_conflict"];
13
13
  /** Repository events to suggest when a conversation starts a Watch. */
14
- export declare const GITHUB_REPOSITORY_SUGGESTED_EVENTS: readonly ["issue.opened", "pull_request.opened", ...string[], "pull_request.checks.failed", "pull_request.comment.created", "pull_request.ready_for_review", "pull_request.review.changes_requested", "pull_request.review.commented", "pull_request.review_comment.created", "pull_request.merged", "pull_request.closed_unmerged"];
14
+ export declare const GITHUB_REPOSITORY_SUGGESTED_EVENTS: readonly ["issue.opened", "pull_request.opened", ...string[], "pull_request.checks.failed", "pull_request.comment.created", "pull_request.ready_for_review", "pull_request.review.changes_requested", "pull_request.review.commented", "pull_request.review_comment.created", "pull_request.merged", "pull_request.closed_unmerged", "pull_request.merge_conflict"];
15
15
  /**
16
16
  * Describe a repository as a resource that a conversation can watch.
17
17
  * Return undefined when the host cannot create Watches.
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ import {
36
36
  gitHubIssueSubscribable,
37
37
  gitHubPullRequestCreateWatch,
38
38
  gitHubPullRequestEventGuidance,
39
+ gitHubPullRequestResource,
39
40
  gitHubPullRequestSubscribable,
40
41
  gitHubReleaseSourceSubscribable,
41
42
  gitHubRepoDataSchema,
@@ -53,11 +54,12 @@ import {
53
54
  normalizePermissions,
54
55
  normalizeScopeList,
55
56
  parseCheckSuitePublishTargets,
57
+ pullRequestTargets,
56
58
  readEnv,
57
59
  readGrantPermissions,
58
60
  requireEnv,
59
61
  resolveUserAccount
60
- } from "./chunk-DGGPIWTT.js";
62
+ } from "./chunk-MUWR6X24.js";
61
63
 
62
64
  // src/tool-support/attribution.ts
63
65
  var GITHUB_REQUEST_ATTRIBUTION_START = "<!-- junior-request-attribution:start -->";
@@ -3191,7 +3193,7 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
3191
3193
 
3192
3194
  // src/webhooks/handler.ts
3193
3195
  import { createHmac, timingSafeEqual } from "crypto";
3194
- import { z as z23 } from "zod";
3196
+ import { z as z24 } from "zod";
3195
3197
 
3196
3198
  // src/issue-outcomes/store.ts
3197
3199
  import { and as and2, eq as eq2, lte, sql as sql2 } from "drizzle-orm";
@@ -3803,11 +3805,102 @@ function normalizeGitHubPullRequestLinkedIssues(args) {
3803
3805
  } : void 0;
3804
3806
  }
3805
3807
 
3808
+ // src/webhooks/merge-conflict.ts
3809
+ import { z as z19 } from "zod";
3810
+ var EVENT_TYPE = "pull_request.merge_conflict";
3811
+ var CLOSED_EVENT_TYPES = /* @__PURE__ */ new Set([
3812
+ "pull_request.closed_unmerged",
3813
+ "pull_request.merged"
3814
+ ]);
3815
+ var pullRequestSchema3 = z19.object({
3816
+ base: z19.object({ ref: z19.string().min(1) }),
3817
+ number: z19.number().int().positive().optional(),
3818
+ head: z19.object({ sha: z19.string().min(1) }),
3819
+ html_url: z19.string().min(1).optional(),
3820
+ mergeable: z19.boolean().nullable().optional(),
3821
+ mergeable_state: z19.string().optional(),
3822
+ state: z19.string()
3823
+ });
3824
+ function gitHubMergeConflictEvents(input) {
3825
+ const { conflict } = input;
3826
+ const repo = gitHubRepoDataSchema.parse(input.repositoryFullName);
3827
+ const resource = gitHubPullRequestResource({ number: input.number, repo });
3828
+ return pullRequestTargets(
3829
+ {
3830
+ eventKey: `github:merge-conflict:${resource.identifier}${conflict ? `:${conflict.headSha}` : ""}`,
3831
+ eventType: EVENT_TYPE,
3832
+ identifier: resource.identifier,
3833
+ objectType: "code_change",
3834
+ occurredAtMs: Date.now(),
3835
+ trustedSummary: `${resource.label} has merge conflicts${conflict ? ` with ${conflict.baseBranch}` : ""}.`,
3836
+ data: { repo, pullRequest: input.number, ...conflict }
3837
+ },
3838
+ repo
3839
+ );
3840
+ }
3841
+ function pullRequestRefs(events) {
3842
+ const refs = /* @__PURE__ */ new Map();
3843
+ for (const event of events) {
3844
+ const { pullRequest, repo } = event.data ?? {};
3845
+ if (!event.eventType.startsWith("pull_request.") || CLOSED_EVENT_TYPES.has(event.eventType) || typeof pullRequest !== "number" || typeof repo !== "string") {
3846
+ continue;
3847
+ }
3848
+ refs.set(`${repo}#${pullRequest}`, {
3849
+ number: pullRequest,
3850
+ repositoryFullName: repo
3851
+ });
3852
+ }
3853
+ return [...refs.values()];
3854
+ }
3855
+ async function hasMatch(hasMatchEvent, ref) {
3856
+ for (const event of gitHubMergeConflictEvents(ref)) {
3857
+ if (await hasMatchEvent(event)) return true;
3858
+ }
3859
+ return false;
3860
+ }
3861
+ function deliveredPullRequest(payload, ref) {
3862
+ const parsed = z19.object({ pull_request: pullRequestSchema3 }).safeParse(payload);
3863
+ const pullRequest = parsed.success ? parsed.data.pull_request : void 0;
3864
+ return pullRequest?.number === ref.number && typeof pullRequest.mergeable === "boolean" ? pullRequest : void 0;
3865
+ }
3866
+ async function loadGitHubMergeConflictEvents(args) {
3867
+ const { hasMatch: hasMatchEvent, loadPullRequest: loadPullRequest2 } = args;
3868
+ if (!hasMatchEvent || !loadPullRequest2) return [];
3869
+ const conflicts = [];
3870
+ for (const ref of pullRequestRefs(args.events)) {
3871
+ if (!await hasMatch(hasMatchEvent, ref)) continue;
3872
+ try {
3873
+ const loaded = deliveredPullRequest(args.pullRequestPayload, ref) ?? pullRequestSchema3.parse(await loadPullRequest2(ref));
3874
+ if (loaded.state !== "open" || loaded.mergeable !== false || loaded.mergeable_state !== "dirty") {
3875
+ continue;
3876
+ }
3877
+ conflicts.push(
3878
+ ...gitHubMergeConflictEvents({
3879
+ ...ref,
3880
+ conflict: {
3881
+ baseBranch: loaded.base.ref,
3882
+ headSha: loaded.head.sha,
3883
+ ...loaded.html_url ? { url: loaded.html_url } : void 0
3884
+ }
3885
+ })
3886
+ );
3887
+ } catch (error) {
3888
+ args.log?.error("GitHub pull request merge conflict check failed", {
3889
+ deliveryId: args.deliveryId,
3890
+ errorType: error instanceof Error ? error.name : "UnknownError",
3891
+ pullRequest: ref.number,
3892
+ repository: ref.repositoryFullName
3893
+ });
3894
+ }
3895
+ }
3896
+ return conflicts;
3897
+ }
3898
+
3806
3899
  // src/webhooks/pull-request-ready.ts
3807
- import { z as z20 } from "zod";
3900
+ import { z as z21 } from "zod";
3808
3901
 
3809
3902
  // src/webhooks/installation-requests.ts
3810
- import { z as z19 } from "zod";
3903
+ import { z as z20 } from "zod";
3811
3904
  function splitRepository(fullName, label) {
3812
3905
  const [owner, name, ...extra] = fullName.split("/");
3813
3906
  if (!owner || !name || extra.length > 0) {
@@ -3831,6 +3924,22 @@ async function loadPullRequestCommitPages(env, pullRequest) {
3831
3924
  { token: token.token }
3832
3925
  );
3833
3926
  }
3927
+ async function loadPullRequest(env, pullRequest) {
3928
+ const { owner, name } = splitRepository(
3929
+ pullRequest.repositoryFullName,
3930
+ "pull request"
3931
+ );
3932
+ const token = await issueInstallationToken({
3933
+ ...env,
3934
+ permissions: { pull_requests: "read" },
3935
+ repositories: [name]
3936
+ });
3937
+ return await githubRequest(
3938
+ "https://api.github.com",
3939
+ `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${pullRequest.number}`,
3940
+ { token: token.token }
3941
+ );
3942
+ }
3834
3943
  async function markPullRequestFeedbackReviewing(env, target) {
3835
3944
  const { owner, name } = splitRepository(target.repo, "pull request feedback");
3836
3945
  const token = await issueInstallationToken({
@@ -3852,9 +3961,9 @@ async function markPullRequestFeedbackReviewing(env, target) {
3852
3961
  }
3853
3962
  );
3854
3963
  }
3855
- var repositoryPermissionSchema = z19.object({
3856
- permission: z19.string().min(1),
3857
- role_name: z19.string().optional()
3964
+ var repositoryPermissionSchema = z20.object({
3965
+ permission: z20.string().min(1),
3966
+ role_name: z20.string().optional()
3858
3967
  });
3859
3968
  var REPOSITORY_ROLE_TTL_MS = 10 * 60 * 1e3;
3860
3969
  async function loadRepositoryRole(env, cache, target) {
@@ -3884,18 +3993,18 @@ async function loadRepositoryRole(env, cache, target) {
3884
3993
  }
3885
3994
  );
3886
3995
  }
3887
- var pullRequestSchema3 = z19.object({
3888
- draft: z19.boolean().optional(),
3889
- html_url: z19.string().url(),
3890
- mergeable_state: z19.string().nullable().optional(),
3891
- merged: z19.boolean(),
3892
- state: z19.enum(["open", "closed"]),
3893
- title: z19.string()
3996
+ var pullRequestSchema4 = z20.object({
3997
+ draft: z20.boolean().optional(),
3998
+ html_url: z20.string().url(),
3999
+ mergeable_state: z20.string().nullable().optional(),
4000
+ merged: z20.boolean(),
4001
+ state: z20.enum(["open", "closed"]),
4002
+ title: z20.string()
3894
4003
  });
3895
- var reviewsSchema = z19.array(
3896
- z19.object({
3897
- state: z19.string(),
3898
- user: z19.object({ login: z19.string() }).nullable()
4004
+ var reviewsSchema = z20.array(
4005
+ z20.object({
4006
+ state: z20.string(),
4007
+ user: z20.object({ login: z20.string() }).nullable()
3899
4008
  })
3900
4009
  );
3901
4010
  async function loadPullRequestMergeState(env, pullRequest) {
@@ -3914,7 +4023,7 @@ async function loadPullRequestMergeState(env, pullRequest) {
3914
4023
  { token: token.token }
3915
4024
  );
3916
4025
  const readPull = async () => {
3917
- const pull = pullRequestSchema3.parse(await read(""));
4026
+ const pull = pullRequestSchema4.parse(await read(""));
3918
4027
  const mergeableState = pull.mergeable_state && pull.mergeable_state !== "unknown" ? pull.mergeable_state : void 0;
3919
4028
  return {
3920
4029
  approved: false,
@@ -3960,10 +4069,10 @@ var READY_ACTIONS = {
3960
4069
  ]),
3961
4070
  pull_request_review: /* @__PURE__ */ new Set(["dismissed", "submitted"])
3962
4071
  };
3963
- var pullRequestWebhookSchema = z20.object({
3964
- action: z20.string(),
3965
- pull_request: z20.object({ number: z20.number().int().positive() }),
3966
- repository: z20.object({ full_name: z20.string().min(1) })
4072
+ var pullRequestWebhookSchema = z21.object({
4073
+ action: z21.string(),
4074
+ pull_request: z21.object({ number: z21.number().int().positive() }),
4075
+ repository: z21.object({ full_name: z21.string().min(1) })
3967
4076
  });
3968
4077
  function pullRequestReadyTargets(eventName, body) {
3969
4078
  if (eventName === "check_suite") return checkSuitePullRequests(body);
@@ -4058,7 +4167,7 @@ async function syncGitHubPullRequestReadyNotices(args) {
4058
4167
  }
4059
4168
 
4060
4169
  // src/webhooks/pull-request-match-data.ts
4061
- import { z as z21 } from "zod";
4170
+ import { z as z22 } from "zod";
4062
4171
  var LOOKUPS_BY_MATCH_KEY = {
4063
4172
  authors: ["authors"],
4064
4173
  openerEmail: ["opener"],
@@ -4066,16 +4175,16 @@ var LOOKUPS_BY_MATCH_KEY = {
4066
4175
  openerUsername: ["opener"]
4067
4176
  };
4068
4177
  var ALL_LOOKUPS = ["authors", "opener", "openerRole"];
4069
- var lookupDataSchema = z21.object({
4070
- authors: z21.array(z21.string().min(1)).min(1).optional(),
4071
- openerRole: z21.string().min(1).optional(),
4072
- openerUsername: z21.string().min(1).optional()
4178
+ var lookupDataSchema = z22.object({
4179
+ authors: z22.array(z22.string().min(1)).min(1).optional(),
4180
+ openerRole: z22.string().min(1).optional(),
4181
+ openerUsername: z22.string().min(1).optional()
4073
4182
  }).strict();
4074
4183
  function lookupData(input) {
4075
4184
  return lookupDataSchema.parse(definedValues(input));
4076
4185
  }
4077
- var webhookSchema = z21.object({
4078
- repository: z21.object({ full_name: z21.string().min(1) })
4186
+ var webhookSchema = z22.object({
4187
+ repository: z22.object({ full_name: z22.string().min(1) })
4079
4188
  });
4080
4189
  function pullRequestNumbers(events) {
4081
4190
  const numbers = /* @__PURE__ */ new Map();
@@ -4208,17 +4317,17 @@ async function withGitHubPullRequestMatchData(args) {
4208
4317
  );
4209
4318
  const events = filtered.size > 0 ? await withLookups(context, args.events, filtered) : args.events;
4210
4319
  const rest = new Set(ALL_LOOKUPS.filter((lookup) => !filtered.has(lookup)));
4211
- const { hasMatch } = args;
4212
- if (rest.size === 0 || !hasMatch) return events;
4320
+ const { hasMatch: hasMatch2 } = args;
4321
+ if (rest.size === 0 || !hasMatch2) return events;
4213
4322
  const matches = await Promise.all(
4214
- events.filter((event) => numbers.has(event.eventKey)).map((event) => hasMatch(event))
4323
+ events.filter((event) => numbers.has(event.eventKey)).map((event) => hasMatch2(event))
4215
4324
  );
4216
4325
  if (!matches.some(Boolean)) return events;
4217
4326
  return await withLookups(context, events, rest);
4218
4327
  }
4219
4328
 
4220
4329
  // src/webhooks/pull-request-people.ts
4221
- import { z as z22 } from "zod";
4330
+ import { z as z23 } from "zod";
4222
4331
  var PEOPLE_EVENTS = /* @__PURE__ */ new Set([
4223
4332
  "pull_request.review.approved",
4224
4333
  "pull_request.merged"
@@ -4228,18 +4337,18 @@ var PAGE_SIZE = 100;
4228
4337
  var MAX_PAGES = 3;
4229
4338
  var CO_AUTHOR_TRAILER = /^co-authored-by:[^<\n]*<([^>\s]+@[^>\s]+)>\s*$/gim;
4230
4339
  var GITHUB_NOREPLY_EMAIL = /^(?:\d+\+)?(?<login>[^@+]+)@users\.noreply\.github\.com$/i;
4231
- var webhookSchema2 = z22.object({
4232
- pull_request: z22.object({
4233
- assignees: z22.array(z22.object({ login: z22.string().min(1) })).nullish(),
4234
- number: z22.number(),
4235
- user: z22.object({ login: z22.string().min(1) }).nullish()
4340
+ var webhookSchema2 = z23.object({
4341
+ pull_request: z23.object({
4342
+ assignees: z23.array(z23.object({ login: z23.string().min(1) })).nullish(),
4343
+ number: z23.number(),
4344
+ user: z23.object({ login: z23.string().min(1) }).nullish()
4236
4345
  }),
4237
- repository: z22.object({ full_name: z22.string().min(1) })
4346
+ repository: z23.object({ full_name: z23.string().min(1) })
4238
4347
  });
4239
- var commitPageSchema = z22.array(
4240
- z22.object({
4241
- author: z22.object({ login: z22.string().min(1) }).nullish(),
4242
- commit: z22.object({ message: z22.string() })
4348
+ var commitPageSchema = z23.array(
4349
+ z23.object({
4350
+ author: z23.object({ login: z23.string().min(1) }).nullish(),
4351
+ commit: z23.object({ message: z23.string() })
4243
4352
  })
4244
4353
  );
4245
4354
  function shareCommitPages(load) {
@@ -4315,16 +4424,16 @@ async function loadGitHubPullRequestAuthors(args) {
4315
4424
  return [...authors.values()].slice(0, MAX_PEOPLE);
4316
4425
  }
4317
4426
  async function withGitHubPullRequestPeople(args) {
4318
- const { hasMatch } = args;
4427
+ const { hasMatch: hasMatch2 } = args;
4319
4428
  const peopleEvents = args.events.filter(
4320
4429
  (event) => PEOPLE_EVENTS.has(event.eventType)
4321
4430
  );
4322
4431
  const parsed = webhookSchema2.safeParse(args.body);
4323
- if (peopleEvents.length === 0 || !hasMatch || !args.load || !parsed.success) {
4432
+ if (peopleEvents.length === 0 || !hasMatch2 || !args.load || !parsed.success) {
4324
4433
  return args.events;
4325
4434
  }
4326
4435
  const matches = await Promise.all(
4327
- peopleEvents.map((event) => hasMatch(event))
4436
+ peopleEvents.map((event) => hasMatch2(event))
4328
4437
  );
4329
4438
  if (!matches.some(Boolean)) return args.events;
4330
4439
  const { pull_request: pullRequest, repository: repository2 } = parsed.data;
@@ -4384,10 +4493,10 @@ function webhookInstallationId(body) {
4384
4493
  }
4385
4494
  return parseInstallationId(installation.id);
4386
4495
  }
4387
- var feedbackTargetSchema = z23.object({
4388
- commentId: z23.number(),
4389
- commentKind: z23.enum(["conversation", "review"]),
4390
- repo: z23.string().min(1)
4496
+ var feedbackTargetSchema = z24.object({
4497
+ commentId: z24.number(),
4498
+ commentKind: z24.enum(["conversation", "review"]),
4499
+ repo: z24.string().min(1)
4391
4500
  });
4392
4501
  function pullRequestFeedbackTarget(events) {
4393
4502
  const event = events.find(
@@ -4544,7 +4653,7 @@ function createGitHubWebhookRoute(args) {
4544
4653
  log: args.log,
4545
4654
  privateKeyEnv: args.privateKeyEnv
4546
4655
  }) : void 0;
4547
- const hasMatch = args.events.hasMatch;
4656
+ const hasMatch2 = args.events.hasMatch;
4548
4657
  const commitPages = args.loadPullRequestCommitPages ? shareCommitPages(args.loadPullRequestCommitPages) : void 0;
4549
4658
  const events = await withGitHubPullRequestPeople({
4550
4659
  body,
@@ -4561,7 +4670,7 @@ function createGitHubWebhookRoute(args) {
4561
4670
  deliveryId,
4562
4671
  eventName
4563
4672
  }),
4564
- hasMatch,
4673
+ hasMatch: hasMatch2,
4565
4674
  ...commitPages ? {
4566
4675
  loadAuthors: async (target) => await loadGitHubPullRequestAuthors({
4567
4676
  loadPage: commitPages(target)
@@ -4572,7 +4681,7 @@ function createGitHubWebhookRoute(args) {
4572
4681
  log: args.log,
4573
4682
  neededMatchKeys: args.events.neededMatchKeys
4574
4683
  }),
4575
- hasMatch,
4684
+ hasMatch: hasMatch2,
4576
4685
  ...commitPages ? {
4577
4686
  load: async (target) => await loadGitHubPullRequestPeople({
4578
4687
  logins: target.logins,
@@ -4582,7 +4691,7 @@ function createGitHubWebhookRoute(args) {
4582
4691
  log: args.log
4583
4692
  });
4584
4693
  const feedbackTarget = pullRequestFeedbackTarget(events);
4585
- const feedbackHasMatch = feedbackTarget && hasMatch ? (await Promise.all(events.map((event) => hasMatch(event)))).some(
4694
+ const feedbackHasMatch = feedbackTarget && hasMatch2 ? (await Promise.all(events.map((event) => hasMatch2(event)))).some(
4586
4695
  Boolean
4587
4696
  ) : false;
4588
4697
  if (feedbackTarget && feedbackHasMatch) {
@@ -4597,6 +4706,16 @@ function createGitHubWebhookRoute(args) {
4597
4706
  });
4598
4707
  }
4599
4708
  }
4709
+ events.push(
4710
+ ...await loadGitHubMergeConflictEvents({
4711
+ deliveryId,
4712
+ events,
4713
+ hasMatch: hasMatch2,
4714
+ loadPullRequest: args.loadPullRequest,
4715
+ log: args.log,
4716
+ pullRequestPayload: eventName === "pull_request" ? body : void 0
4717
+ })
4718
+ );
4600
4719
  for (const event of events) {
4601
4720
  await args.events.publish({
4602
4721
  ...event,
@@ -4643,18 +4762,18 @@ function gitHubEventDeclarations(pullRequestGuidance) {
4643
4762
  }
4644
4763
 
4645
4764
  // src/pull-request-outcomes/commit-composition.ts
4646
- import { z as z24 } from "zod";
4647
- var canonicalCommitSchema = z24.object({
4648
- authorEmail: z24.string().nullable(),
4649
- authorLogin: z24.string().nullable()
4765
+ import { z as z25 } from "zod";
4766
+ var canonicalCommitSchema = z25.object({
4767
+ authorEmail: z25.string().nullable(),
4768
+ authorLogin: z25.string().nullable()
4650
4769
  }).strict();
4651
- var providerCommitSchema = z24.object({
4652
- author: z24.object({ login: z24.string() }).passthrough().nullable(),
4653
- commit: z24.object({
4654
- author: z24.object({ email: z24.string() }).passthrough().nullable()
4770
+ var providerCommitSchema = z25.object({
4771
+ author: z25.object({ login: z25.string() }).passthrough().nullable(),
4772
+ commit: z25.object({
4773
+ author: z25.object({ email: z25.string() }).passthrough().nullable()
4655
4774
  }).passthrough()
4656
4775
  }).passthrough();
4657
- var commitPageSchema2 = z24.array(providerCommitSchema).transform(
4776
+ var commitPageSchema2 = z25.array(providerCommitSchema).transform(
4658
4777
  (commits) => commits.map(
4659
4778
  (commit) => canonicalCommitSchema.parse({
4660
4779
  authorEmail: commit.commit.author?.email ?? null,
@@ -6146,6 +6265,7 @@ function githubPlugin(options = {}) {
6146
6265
  loadGitHubLogin: async (identityId) => linkedGitHubLogin(
6147
6266
  (await ctx.users.readIdentity(identityId))?.user
6148
6267
  ),
6268
+ loadPullRequest: async (pullRequest) => await loadPullRequest(installationEnv, pullRequest),
6149
6269
  loadPullRequestCommitPages: async (pullRequest) => await loadPullRequestCommitPages(installationEnv, pullRequest),
6150
6270
  log: ctx.log,
6151
6271
  markFeedbackReviewing: async (target) => await markPullRequestFeedbackReviewing(installationEnv, target),
package/dist/testing.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  normalizeGitHubEvents
3
- } from "./chunk-DGGPIWTT.js";
3
+ } from "./chunk-MUWR6X24.js";
4
4
  export {
5
5
  normalizeGitHubEvents
6
6
  };
@@ -2,6 +2,7 @@ import type { CodeChangePublisher, PluginConversationAnnotations, PluginConversa
2
2
  import { z } from "zod";
3
3
  import type { GitHubDb } from "../db/database.js";
4
4
  import type { GitHubPullRequestCommitComposition } from "../db/schema.js";
5
+ import { type GitHubPullRequestRef } from "./merge-conflict.js";
5
6
  import { type GitHubRoleTarget } from "./pull-request-match-data.js";
6
7
  import { type GitHubCommitPageLoader, type GitHubPullRequestTarget } from "./pull-request-people.js";
7
8
  /** The pull request comment data that the feedback reaction needs. */
@@ -32,6 +33,8 @@ export declare function createGitHubWebhookRoute(args: {
32
33
  * involved.
33
34
  */
34
35
  loadPullRequestCommitPages?(target: GitHubPullRequestTarget): Promise<GitHubCommitPageLoader>;
36
+ /** Read one pull request for its mergeability. */
37
+ loadPullRequest?(pullRequest: GitHubPullRequestRef): Promise<unknown>;
35
38
  /** Load a repository role for `openerRole`. */
36
39
  loadRepositoryRole?(target: GitHubRoleTarget): Promise<string>;
37
40
  /** Linked GitHub login of the user of one Junior identity, if any. */
@@ -16,6 +16,11 @@ export declare function loadPullRequestCommitPages(env: GitHubInstallationEnv, p
16
16
  number: number;
17
17
  repositoryFullName: string;
18
18
  }): Promise<(page: number, perPage: number) => Promise<unknown>>;
19
+ /** Read one pull request, with a read-only token. */
20
+ export declare function loadPullRequest(env: GitHubInstallationEnv, pullRequest: {
21
+ number: number;
22
+ repositoryFullName: string;
23
+ }): Promise<unknown>;
19
24
  /** Add the "reviewing" reaction to one pull request feedback comment. */
20
25
  export declare function markPullRequestFeedbackReviewing(env: GitHubInstallationEnv, target: {
21
26
  commentId: number;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Merge conflict checks on pull request webhook events.
3
+ *
4
+ * GitHub sends no webhook when a pull request gets a conflict, and a
5
+ * conflicted pull request gets no new checks. So when a webhook delivers
6
+ * another event for a watched pull request, such as a comment, a review, or a
7
+ * check result, the webhook also reads its mergeability and publishes
8
+ * `pull_request.merge_conflict`.
9
+ */
10
+ import type { EventInput, EventPublisher, PluginLogger } from "@sentry/junior-plugin-api";
11
+ /** Values that GitHub reports for a conflicted pull request. */
12
+ export interface GitHubMergeConflict {
13
+ baseBranch: string;
14
+ headSha: string;
15
+ url?: string;
16
+ }
17
+ /** One pull request in one repository. */
18
+ export interface GitHubPullRequestRef {
19
+ number: number;
20
+ repositoryFullName: string;
21
+ }
22
+ /**
23
+ * Build the `pull_request.merge_conflict` copies for one pull request. With
24
+ * no conflict, the copies have only the values that filters can match. The
25
+ * event key names the head commit, so each head commit publishes once.
26
+ */
27
+ export declare function gitHubMergeConflictEvents(input: GitHubPullRequestRef & {
28
+ conflict?: GitHubMergeConflict;
29
+ }): EventInput[];
30
+ /**
31
+ * Return `pull_request.merge_conflict` events for the open pull requests that
32
+ * these events are about, when a Watch or event automation wants them and
33
+ * GitHub reports a conflict. A `pull_request` webhook payload gives the
34
+ * mergeability when GitHub knows it. Otherwise the check reads the pull
35
+ * request, which also makes GitHub calculate its mergeability. When GitHub
36
+ * does not know it yet, a later event reads it again.
37
+ */
38
+ export declare function loadGitHubMergeConflictEvents(args: {
39
+ deliveryId: string;
40
+ events: EventInput[];
41
+ hasMatch: EventPublisher["hasMatch"];
42
+ loadPullRequest?(ref: GitHubPullRequestRef): Promise<unknown>;
43
+ log?: Pick<PluginLogger, "error">;
44
+ /** The body of a `pull_request` webhook. */
45
+ pullRequestPayload?: unknown;
46
+ }): Promise<EventInput[]>;
@@ -3,10 +3,10 @@
3
3
  *
4
4
  * A pull request is ready to merge when it is open, not a draft, approved,
5
5
  * and GitHub's merge state is `clean`. Each webhook that can change one of
6
- * these facts reads them again from GitHub. The notice goes to the person
7
- * who asked Junior to open the pull request, in the Conversation where they
8
- * asked. It closes when the pull request merges, closes, or is no longer
9
- * ready.
6
+ * these facts reads them again from GitHub. The notice goes to the
7
+ * Conversation where a person asked Junior to open the pull request. It is
8
+ * assigned to that person only when they are in that Conversation. It closes
9
+ * when the pull request merges, closes, or is no longer ready.
10
10
  */
11
11
  import type { PluginConversationReviewItems, PluginLogger } from "@sentry/junior-plugin-api";
12
12
  import type { GitHubDb } from "../db/database.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-github",
3
- "version": "0.269.0",
3
+ "version": "0.271.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -32,7 +32,7 @@
32
32
  "drizzle-orm": "^0.45.2",
33
33
  "marked": "^18.1.2",
34
34
  "zod": "^4.5.4",
35
- "@sentry/junior-plugin-api": "0.269.0"
35
+ "@sentry/junior-plugin-api": "0.271.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@oxlint/plugins": "1.79.0",
@@ -11,7 +11,7 @@ Guide evidence-first GitHub repository work from inspection through a reviewable
11
11
  - Treat shallow clones as inspection checkouts; deepen before history work; never force-push around missing ancestry.
12
12
  - Install dependencies with the lockfile frozen mode before verification when needed.
13
13
  - Finish every code change with a pushed PR, without asking, unless the user opts out or asked for investigation only. Open it ready when work and checks are done; open a draft when work, checks, or decisions remain. An open scope question goes in the PR body, not in a stop.
14
- - After each push to a branch with an open PR, check mergeability. Resolve conflicts without asking, by merging the PR base branch (usually the default branch). Never rebase for this. GitHub sends no event for a new conflict, and conflicted PRs get no new checks.
14
+ - After each push to a branch with an open PR, check mergeability. Resolve conflicts without asking, by merging the PR base branch (usually the default branch). Never rebase for this. GitHub sends no event for a new conflict, and conflicted PRs get no new checks. The plugin publishes `pull_request.merge_conflict` for a watched PR only when another webhook event arrives for it, so the post-push check stays.
15
15
  - Write conventional PR titles and short plain-English bodies; keep check results out of the PR body.
16
16
  - Report exact validation and permission failures.
17
17
 
@@ -34,7 +34,7 @@ Open this when making repository edits, not for read-only inspection.
34
34
  1. Reuse the current non-default branch or create a focused branch.
35
35
  2. Commit with repo conventions, else `<type>(<scope>): <Subject>` imperative present, no agent branding.
36
36
  3. Push with `git push -u origin BRANCH`.
37
- If the branch has an open PR, check that it can merge. Do this after every push, including fixes for review feedback or failed checks. A conflicted PR gets no new checks, so no event shows it.
37
+ If the branch has an open PR, check that it can merge. Do this after every push, including fixes for review feedback or failed checks. A conflicted PR gets no new checks. A watched PR gets `pull_request.merge_conflict` only with its next event, so do not wait for it.
38
38
  - Run `gh pr view NUMBER --repo owner/repo --json mergeable,baseRefName`.
39
39
  - `UNKNOWN`: GitHub is still calculating it. Wait about 5 seconds and check again, up to 3 times. If it stays `UNKNOWN`, report that and continue.
40
40
  - `CONFLICTING`: resolve it now. Do not ask first. GitHub checks mergeability against the PR base (`baseRefName`), which is usually the default branch. Fetch the base and merge `origin/BASE` into the PR branch. Do not rebase. Resolve each conflict so that both the PR change and the base branch change stay intact. Run the checks again, push, and check mergeability again.