@sentry/junior-github 0.203.0 → 0.205.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.
Files changed (2) hide show
  1. package/dist/index.js +50 -23
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -400,15 +400,29 @@ function requesterLabel(args) {
400
400
  const display = cleanDisplayValue(user?.displayName, userId) ?? cleanDisplayValue(identity?.displayName, userId) ?? cleanDisplayValue(identity?.handle, userId) ?? cleanDisplayValue(actor.fullName, userId) ?? cleanDisplayValue(actor.userName, userId);
401
401
  return display ? `**${display.replaceAll("*", "\\*")}**` : void 0;
402
402
  }
403
+ function parseExistingLabels(blockContents) {
404
+ const trimmed = blockContents.trim().replace(/\.$/, "");
405
+ if (!trimmed) {
406
+ return [];
407
+ }
408
+ const withoutLeadIn = trimmed.replace(/^(?:Requested by|via)\s+/i, "");
409
+ return withoutLeadIn.split(/,\s*(?=\*\*|Junior system actor `|via\s)/i).map((entry) => entry.trim().replace(/^via\s+/i, "")).filter(Boolean);
410
+ }
411
+ function formatAttributionBlock(labels) {
412
+ return `${GITHUB_REQUEST_ATTRIBUTION_START}
413
+ via ${labels.join(", ")}.
414
+ ${GITHUB_REQUEST_ATTRIBUTION_END}`;
415
+ }
403
416
  function applyAttribution(body, label) {
404
- const attribution = label ? `${GITHUB_REQUEST_ATTRIBUTION_START}
405
- Requested by ${label}.
406
- ${GITHUB_REQUEST_ATTRIBUTION_END}` : void 0;
407
417
  const normalizedBody = body.trimEnd();
408
418
  const existing = new RegExp(
409
- `${GITHUB_REQUEST_ATTRIBUTION_START}[\\s\\S]*?${GITHUB_REQUEST_ATTRIBUTION_END}`
419
+ `${GITHUB_REQUEST_ATTRIBUTION_START}([\\s\\S]*?)${GITHUB_REQUEST_ATTRIBUTION_END}`
410
420
  );
411
- if (existing.test(normalizedBody)) {
421
+ const existingMatch = normalizedBody.match(existing);
422
+ const existingLabels = existingMatch ? parseExistingLabels(existingMatch[1]) : [];
423
+ const labels = label && !existingLabels.includes(label) ? [...existingLabels, label] : existingLabels;
424
+ const attribution = labels.length ? formatAttributionBlock(labels) : void 0;
425
+ if (existingMatch) {
412
426
  return attribution ? normalizedBody.replace(existing, attribution) : normalizedBody.replace(existing, "").trimEnd();
413
427
  }
414
428
  if (!attribution) {
@@ -2295,22 +2309,27 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
2295
2309
  `GitHub review thread lookup failed with HTTP ${lookupResponse.status}: ${githubError2(lookupPayload)}`
2296
2310
  );
2297
2311
  }
2298
- const thread = z11.object({
2312
+ const threadNodeSchema = z11.object({
2313
+ id: z11.string(),
2314
+ isResolved: z11.boolean(),
2315
+ pullRequest: z11.object({
2316
+ author: z11.object({ databaseId: z11.number().optional() }).passthrough().nullable(),
2317
+ number: z11.number(),
2318
+ repository: z11.object({ nameWithOwner: z11.string() }).passthrough()
2319
+ }).passthrough()
2320
+ }).passthrough();
2321
+ const lookupResultSchema = z11.object({
2299
2322
  data: z11.object({
2300
- node: z11.object({
2301
- id: z11.string(),
2302
- isResolved: z11.boolean(),
2303
- pullRequest: z11.object({
2304
- author: z11.object({ databaseId: z11.number().optional() }).nullable(),
2305
- number: z11.number(),
2306
- repository: z11.object({ nameWithOwner: z11.string() })
2307
- })
2308
- }).nullable()
2309
- })
2310
- }).parse(lookupPayload).data.node;
2311
- if (!thread) {
2323
+ node: z11.unknown().nullable().optional()
2324
+ }).passthrough()
2325
+ }).passthrough();
2326
+ const lookupResult = lookupResultSchema.safeParse(lookupPayload);
2327
+ const rawNode = lookupResult.success ? lookupResult.data.data.node : void 0;
2328
+ const parsedNode = rawNode == null ? void 0 : threadNodeSchema.safeParse(rawNode);
2329
+ if (!parsedNode?.success) {
2312
2330
  throw new PluginToolInputError12("GitHub review thread was not found.");
2313
2331
  }
2332
+ const thread = parsedNode.data;
2314
2333
  const pullRequest = thread.pullRequest;
2315
2334
  const ownsPullRequest = pullRequest.repository.nameWithOwner.toLowerCase() === repo.ref.toLowerCase() && pullRequest.author?.databaseId === botUserId;
2316
2335
  if (!ownsPullRequest) {
@@ -2351,13 +2370,21 @@ function createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail) {
2351
2370
  `GitHub review thread resolution failed with HTTP ${resolveResponse.status}: ${githubError2(resolvePayload)}`
2352
2371
  );
2353
2372
  }
2354
- const resolved = z11.object({
2373
+ const resolveResultSchema = z11.object({
2355
2374
  data: z11.object({
2356
2375
  resolveReviewThread: z11.object({
2357
- thread: z11.object({ id: z11.string(), isResolved: z11.boolean() })
2358
- })
2359
- })
2360
- }).parse(resolvePayload).data.resolveReviewThread.thread;
2376
+ thread: z11.object({ id: z11.string(), isResolved: z11.boolean() }).passthrough()
2377
+ }).passthrough()
2378
+ }).passthrough()
2379
+ }).passthrough();
2380
+ const resolveResult = resolveResultSchema.safeParse(resolvePayload);
2381
+ if (!resolveResult.success) {
2382
+ throw new Error(
2383
+ "GitHub review thread resolution returned an unexpected response shape.",
2384
+ { cause: resolveResult.error }
2385
+ );
2386
+ }
2387
+ const resolved = resolveResult.data.data.resolveReviewThread.thread;
2361
2388
  if (resolved.id !== thread.id || !resolved.isResolved) {
2362
2389
  throw new Error("GitHub did not resolve the requested review thread.");
2363
2390
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-github",
3
- "version": "0.203.0",
3
+ "version": "0.205.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -31,7 +31,7 @@
31
31
  "@sinclair/typebox": "^0.34.49",
32
32
  "drizzle-orm": "^0.45.2",
33
33
  "zod": "^4.5.4",
34
- "@sentry/junior-plugin-api": "0.203.0"
34
+ "@sentry/junior-plugin-api": "0.205.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@oxlint/plugins": "1.79.0",