@sentry/junior-github 0.126.1 → 0.127.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.
@@ -11,7 +11,7 @@ var GITHUB_DEPLOYMENT_EVENTS = [
11
11
  "deployment.failed",
12
12
  "deployment.error"
13
13
  ];
14
- var SUGGESTED_EVENTS = [
14
+ var GITHUB_DEPLOYMENT_SUGGESTED_EVENTS = [
15
15
  "deployment.succeeded",
16
16
  "deployment.failed",
17
17
  "deployment.error"
@@ -22,58 +22,105 @@ function gitHubDeploymentSourceResource(input) {
22
22
  const repo = input.repo.toLowerCase();
23
23
  return {
24
24
  label: `GitHub deployment for ${repo} at ${commitSha.slice(0, 12)}`,
25
- provider: "github",
26
- resourceRef: environment ? `github:deployment-source:${repo}:${encodeURIComponent(environment.toLowerCase())}:${commitSha}` : `github:deployment-source:${repo}:${commitSha}`
25
+ namespace: "github",
26
+ identifier: environment ? `deployment-source:${repo}:${encodeURIComponent(environment.toLowerCase())}:${commitSha}` : `deployment-source:${repo}:${commitSha}`
27
27
  };
28
28
  }
29
29
  function gitHubDeploymentSourceSubscribable(input) {
30
30
  if (!process.env.GITHUB_WEBHOOK_SECRET?.trim()) return void 0;
31
31
  return {
32
32
  ...gitHubDeploymentSourceResource(input),
33
- suggestedEvents: SUGGESTED_EVENTS,
33
+ suggestedEvents: GITHUB_DEPLOYMENT_SUGGESTED_EVENTS,
34
34
  supportedEvents: [...GITHUB_DEPLOYMENT_EVENTS],
35
35
  type: "deployment_source"
36
36
  };
37
37
  }
38
38
 
39
+ // src/resource-events/issue.ts
40
+ var GITHUB_ISSUE_EVENTS = [
41
+ "issue.comment.created",
42
+ "issue.opened",
43
+ "issue.closed",
44
+ "issue.reopened"
45
+ ];
46
+ var GITHUB_ISSUE_SUGGESTED_EVENTS = [
47
+ "issue.comment.created",
48
+ "issue.closed",
49
+ "issue.reopened"
50
+ ];
51
+ function gitHubIssueResource(input) {
52
+ return {
53
+ label: `GitHub issue ${input.repo}#${input.number}`,
54
+ namespace: "github",
55
+ identifier: `${input.repo.toLowerCase()}#${input.number}`
56
+ };
57
+ }
58
+ function gitHubIssueSubscribable(input) {
59
+ if (!process.env.GITHUB_WEBHOOK_SECRET?.trim()) return void 0;
60
+ return {
61
+ ...gitHubIssueResource(input),
62
+ suggestedEvents: GITHUB_ISSUE_SUGGESTED_EVENTS,
63
+ supportedEvents: GITHUB_ISSUE_EVENTS,
64
+ type: "issue"
65
+ };
66
+ }
67
+
39
68
  // src/resource-events/pull-request.ts
40
- var SUPPORTED_EVENTS = [
41
- "checks.failed",
42
- "checks.recovered",
43
- "comment.created",
44
- "review.approved",
45
- "review.changes_requested",
46
- "review.commented",
47
- "review_comment.created",
48
- "state.merged",
49
- "state.closed_unmerged"
69
+ var GITHUB_PULL_REQUEST_EVENTS = [
70
+ "pull_request.checks.failed",
71
+ "pull_request.checks.recovered",
72
+ "pull_request.comment.created",
73
+ "pull_request.review.approved",
74
+ "pull_request.review.changes_requested",
75
+ "pull_request.review.commented",
76
+ "pull_request.review_comment.created",
77
+ "pull_request.merged",
78
+ "pull_request.closed_unmerged"
50
79
  ];
51
- var SUGGESTED_EVENTS2 = [
52
- "checks.failed",
53
- "comment.created",
54
- "review.changes_requested",
55
- "review.commented",
56
- "review_comment.created",
57
- "state.merged",
58
- "state.closed_unmerged"
80
+ var GITHUB_PULL_REQUEST_SUGGESTED_EVENTS = [
81
+ "pull_request.checks.failed",
82
+ "pull_request.comment.created",
83
+ "pull_request.review.changes_requested",
84
+ "pull_request.review.commented",
85
+ "pull_request.review_comment.created",
86
+ "pull_request.merged",
87
+ "pull_request.closed_unmerged"
59
88
  ];
60
89
  function gitHubPullRequestResource(input) {
61
90
  return {
62
91
  label: `GitHub PR ${input.repo}#${input.number}`,
63
- provider: "github",
64
- resourceRef: `github:pull_request:${input.repo}#${input.number}`
92
+ namespace: "github",
93
+ identifier: `${input.repo.toLowerCase()}#${input.number}`
65
94
  };
66
95
  }
67
96
  function gitHubPullRequestSubscribable(input) {
68
97
  if (!process.env.GITHUB_WEBHOOK_SECRET?.trim()) return void 0;
69
98
  return {
70
99
  ...gitHubPullRequestResource(input),
71
- suggestedEvents: SUGGESTED_EVENTS2,
72
- supportedEvents: SUPPORTED_EVENTS,
100
+ suggestedEvents: GITHUB_PULL_REQUEST_SUGGESTED_EVENTS,
101
+ supportedEvents: GITHUB_PULL_REQUEST_EVENTS,
73
102
  type: "pull_request"
74
103
  };
75
104
  }
76
105
 
106
+ // src/resource-events/repository.ts
107
+ function gitHubRepositoryResource(input) {
108
+ return {
109
+ label: `GitHub repository ${input.repo}`,
110
+ namespace: "github",
111
+ identifier: input.repo.toLowerCase()
112
+ };
113
+ }
114
+ function gitHubRepositorySubscribable(input) {
115
+ if (!process.env.GITHUB_WEBHOOK_SECRET?.trim()) return void 0;
116
+ return {
117
+ ...gitHubRepositoryResource(input),
118
+ suggestedEvents: ["issue.opened", ...GITHUB_ISSUE_SUGGESTED_EVENTS],
119
+ supportedEvents: GITHUB_ISSUE_EVENTS,
120
+ type: "repository"
121
+ };
122
+ }
123
+
77
124
  // src/webhooks/resource-events.ts
78
125
  function gitHubEventKey(deliveryId, eventType) {
79
126
  return `github:${deliveryId}:${eventType}`;
@@ -118,8 +165,7 @@ function normalizeDeploymentEvent(deliveryId, body) {
118
165
  eventKey: gitHubEventKey(deliveryId, eventType),
119
166
  eventType,
120
167
  occurredAtMs: providerTime(parsed.createdAt) ?? Date.now(),
121
- provider: "github",
122
- resourceRef: resource.resourceRef,
168
+ identifier: resource.identifier,
123
169
  trustedSummary: `${resource.label} was created (deployment ${parsed.deploymentId}).`
124
170
  }));
125
171
  }
@@ -181,8 +227,7 @@ function normalizeDeploymentStatusEvent(deliveryId, body) {
181
227
  eventKey: gitHubEventKey(deliveryId, eventType),
182
228
  eventType,
183
229
  occurredAtMs: providerTime(parsed.statusCreatedAt) ?? Date.now(),
184
- provider: "github",
185
- resourceRef: resource.resourceRef,
230
+ identifier: resource.identifier,
186
231
  ...terminal && completeOnTerminalEvent ? { terminal: true } : {},
187
232
  trustedSummary: `${resource.label} ${outcome} (deployment ${parsed.deploymentId}).`,
188
233
  untrustedText: parsed.description ?? void 0
@@ -217,7 +262,7 @@ function normalizeCheckSuiteEvents(deliveryId, body) {
217
262
  const parsed = checkSuiteWebhookSchema.safeParse(body);
218
263
  if (!parsed.success || parsed.data.action !== "completed") return [];
219
264
  const conclusion = parsed.data.check_suite.conclusion;
220
- const eventType = conclusion === "failure" || conclusion === "timed_out" ? "checks.failed" : conclusion === "success" ? "checks.recovered" : void 0;
265
+ const eventType = conclusion === "failure" || conclusion === "timed_out" ? "pull_request.checks.failed" : conclusion === "success" ? "pull_request.checks.recovered" : void 0;
221
266
  if (!eventType) return [];
222
267
  const sha = parsed.data.check_suite.head_sha?.slice(0, 12);
223
268
  return parsed.data.check_suite.pull_requests.map((pullRequest) => {
@@ -232,9 +277,8 @@ function normalizeCheckSuiteEvents(deliveryId, body) {
232
277
  ),
233
278
  eventType,
234
279
  occurredAtMs: Date.now(),
235
- provider: "github",
236
- resourceRef: resource.resourceRef,
237
- trustedSummary: eventType === "checks.failed" ? `${resource.label} checks failed${sha ? ` for ${sha}` : ""}.` : `${resource.label} checks recovered${sha ? ` for ${sha}` : ""}.`
280
+ identifier: resource.identifier,
281
+ trustedSummary: eventType === "pull_request.checks.failed" ? `${resource.label} checks failed${sha ? ` for ${sha}` : ""}.` : `${resource.label} checks recovered${sha ? ` for ${sha}` : ""}.`
238
282
  };
239
283
  });
240
284
  }
@@ -250,26 +294,101 @@ var issueCommentWebhookSchema = z.object({
250
294
  }),
251
295
  repository: repositorySchema
252
296
  });
253
- function normalizeIssueCommentEvent(deliveryId, body) {
297
+ function normalizeIssueCommentEvents(deliveryId, body) {
254
298
  const parsed = issueCommentWebhookSchema.safeParse(body);
255
- if (!parsed.success || parsed.data.action !== "created" || !parsed.data.issue.pull_request) {
256
- return void 0;
257
- }
258
- const eventType = "comment.created";
259
- const resource = gitHubPullRequestResource({
299
+ if (!parsed.success || parsed.data.action !== "created") return [];
300
+ const input = {
260
301
  number: parsed.data.issue.number,
261
302
  repo: parsed.data.repository.full_name
262
- });
303
+ };
263
304
  const author = parsed.data.comment.user?.login;
264
- return {
265
- eventKey: gitHubEventKey(deliveryId, eventType),
266
- eventType,
267
- occurredAtMs: Date.now(),
268
- provider: "github",
269
- resourceRef: resource.resourceRef,
270
- trustedSummary: `${resource.label} received a comment${author ? ` from ${author}` : ""}.`,
271
- untrustedText: parsed.data.comment.body
305
+ if (parsed.data.issue.pull_request) {
306
+ const eventType = "pull_request.comment.created";
307
+ const resource = gitHubPullRequestResource(input);
308
+ return [
309
+ {
310
+ eventKey: gitHubEventKey(deliveryId, eventType),
311
+ eventType,
312
+ occurredAtMs: Date.now(),
313
+ identifier: resource.identifier,
314
+ trustedSummary: `${resource.label} received a comment${author ? ` from ${author}` : ""}.`,
315
+ untrustedText: parsed.data.comment.body
316
+ }
317
+ ];
318
+ }
319
+ const issue = gitHubIssueResource(input);
320
+ const repository = gitHubRepositoryResource(input);
321
+ return [
322
+ {
323
+ eventKey: gitHubEventKey(deliveryId, "issue.comment.created"),
324
+ eventType: "issue.comment.created",
325
+ occurredAtMs: Date.now(),
326
+ identifier: issue.identifier,
327
+ trustedSummary: `${issue.label} received a comment${author ? ` from ${author}` : ""}.`,
328
+ untrustedText: parsed.data.comment.body
329
+ },
330
+ {
331
+ eventKey: gitHubEventKey(deliveryId, "issue.comment.created"),
332
+ eventType: "issue.comment.created",
333
+ occurredAtMs: Date.now(),
334
+ identifier: repository.identifier,
335
+ trustedSummary: `${issue.label} received a comment${author ? ` from ${author}` : ""}.`,
336
+ untrustedText: parsed.data.comment.body
337
+ }
338
+ ];
339
+ }
340
+ var issueWebhookSchema = z.object({
341
+ action: z.string(),
342
+ issue: z.object({
343
+ body: z.string().optional().nullable(),
344
+ closed_at: z.string().optional().nullable(),
345
+ created_at: z.string().optional(),
346
+ number: z.number(),
347
+ title: z.string().optional(),
348
+ updated_at: z.string().optional()
349
+ }),
350
+ repository: repositorySchema
351
+ });
352
+ function issueEventText(issue) {
353
+ const parts = [
354
+ issue.title ? `Title: ${issue.title}` : void 0,
355
+ issue.body?.trim() || void 0
356
+ ].filter((part) => part !== void 0);
357
+ return parts.length > 0 ? parts.join("\n\n") : void 0;
358
+ }
359
+ function normalizeIssueEvents(deliveryId, body) {
360
+ const parsed = issueWebhookSchema.safeParse(body);
361
+ if (!parsed.success) return [];
362
+ const state = parsed.data.action === "opened" ? "opened" : parsed.data.action === "closed" ? "closed" : parsed.data.action === "reopened" ? "reopened" : void 0;
363
+ if (!state) return [];
364
+ const input = {
365
+ number: parsed.data.issue.number,
366
+ repo: parsed.data.repository.full_name
272
367
  };
368
+ const issue = gitHubIssueResource(input);
369
+ const repository = gitHubRepositoryResource(input);
370
+ const occurredAtMs = providerTime(
371
+ state === "opened" ? parsed.data.issue.created_at : state === "closed" ? parsed.data.issue.closed_at : parsed.data.issue.updated_at
372
+ ) ?? Date.now();
373
+ const untrustedText = issueEventText(parsed.data.issue);
374
+ return [
375
+ {
376
+ eventKey: gitHubEventKey(deliveryId, `issue.${state}`),
377
+ eventType: `issue.${state}`,
378
+ occurredAtMs,
379
+ identifier: issue.identifier,
380
+ trustedSummary: `${issue.label} was ${state}.`,
381
+ ...untrustedText ? { untrustedText } : {}
382
+ },
383
+ {
384
+ eventKey: gitHubEventKey(deliveryId, `issue.${state}`),
385
+ eventType: `issue.${state}`,
386
+ occurredAtMs,
387
+ identifier: repository.identifier,
388
+ trustedSummary: `${issue.label} was ${state}.`,
389
+ ...untrustedText ? { untrustedText } : {}
390
+ }
391
+ ];
273
392
  }
274
393
  var pullRequestReviewCommentWebhookSchema = z.object({
275
394
  action: z.string(),
@@ -283,7 +402,7 @@ var pullRequestReviewCommentWebhookSchema = z.object({
283
402
  function normalizePullRequestReviewCommentEvent(deliveryId, body) {
284
403
  const parsed = pullRequestReviewCommentWebhookSchema.safeParse(body);
285
404
  if (!parsed.success || parsed.data.action !== "created") return void 0;
286
- const eventType = "review_comment.created";
405
+ const eventType = "pull_request.review_comment.created";
287
406
  const resource = gitHubPullRequestResource({
288
407
  number: parsed.data.pull_request.number,
289
408
  repo: parsed.data.repository.full_name
@@ -293,8 +412,7 @@ function normalizePullRequestReviewCommentEvent(deliveryId, body) {
293
412
  eventKey: gitHubEventKey(deliveryId, eventType),
294
413
  eventType,
295
414
  occurredAtMs: Date.now(),
296
- provider: "github",
297
- resourceRef: resource.resourceRef,
415
+ identifier: resource.identifier,
298
416
  trustedSummary: `${resource.label} received an inline review comment${author ? ` from ${author}` : ""}.`,
299
417
  untrustedText: parsed.data.comment.body
300
418
  };
@@ -313,7 +431,7 @@ function normalizePullRequestReviewEvent(deliveryId, body) {
313
431
  const parsed = pullRequestReviewWebhookSchema.safeParse(body);
314
432
  if (!parsed.success || parsed.data.action !== "submitted") return void 0;
315
433
  const reviewState = parsed.data.review.state.toUpperCase();
316
- const eventType = reviewState === "APPROVED" ? "review.approved" : reviewState === "CHANGES_REQUESTED" ? "review.changes_requested" : reviewState === "COMMENTED" ? "review.commented" : void 0;
434
+ const eventType = reviewState === "APPROVED" ? "pull_request.review.approved" : reviewState === "CHANGES_REQUESTED" ? "pull_request.review.changes_requested" : reviewState === "COMMENTED" ? "pull_request.review.commented" : void 0;
317
435
  if (!eventType) return void 0;
318
436
  const resource = gitHubPullRequestResource({
319
437
  number: parsed.data.pull_request.number,
@@ -324,9 +442,8 @@ function normalizePullRequestReviewEvent(deliveryId, body) {
324
442
  eventKey: gitHubEventKey(deliveryId, eventType),
325
443
  eventType,
326
444
  occurredAtMs: Date.now(),
327
- provider: "github",
328
- resourceRef: resource.resourceRef,
329
- trustedSummary: eventType === "review.approved" ? `${resource.label} was approved${reviewer ? ` by ${reviewer}` : ""}.` : eventType === "review.changes_requested" ? `${resource.label} received requested changes${reviewer ? ` from ${reviewer}` : ""}.` : `${resource.label} received a review comment${reviewer ? ` from ${reviewer}` : ""}.`,
445
+ identifier: resource.identifier,
446
+ trustedSummary: eventType === "pull_request.review.approved" ? `${resource.label} was approved${reviewer ? ` by ${reviewer}` : ""}.` : eventType === "pull_request.review.changes_requested" ? `${resource.label} received requested changes${reviewer ? ` from ${reviewer}` : ""}.` : `${resource.label} received a review comment${reviewer ? ` from ${reviewer}` : ""}.`,
330
447
  untrustedText: parsed.data.review.body ?? void 0
331
448
  };
332
449
  }
@@ -348,7 +465,7 @@ function providerTime(value) {
348
465
  function normalizePullRequestEvent(deliveryId, body) {
349
466
  const parsed = pullRequestWebhookSchema.safeParse(body);
350
467
  if (!parsed.success || parsed.data.action !== "closed") return void 0;
351
- const eventType = parsed.data.pull_request.merged ? "state.merged" : "state.closed_unmerged";
468
+ const eventType = parsed.data.pull_request.merged ? "pull_request.merged" : "pull_request.closed_unmerged";
352
469
  const resource = gitHubPullRequestResource({
353
470
  number: parsed.data.pull_request.number,
354
471
  repo: parsed.data.repository.full_name
@@ -359,10 +476,9 @@ function normalizePullRequestEvent(deliveryId, body) {
359
476
  occurredAtMs: providerTime(
360
477
  parsed.data.pull_request.merged ? parsed.data.pull_request.merged_at : parsed.data.pull_request.closed_at
361
478
  ) ?? Date.now(),
362
- provider: "github",
363
- resourceRef: resource.resourceRef,
479
+ identifier: resource.identifier,
364
480
  terminal: true,
365
- trustedSummary: eventType === "state.merged" ? `${resource.label} was merged.` : `${resource.label} was closed without being merged.`
481
+ trustedSummary: eventType === "pull_request.merged" ? `${resource.label} was merged.` : `${resource.label} was closed without being merged.`
366
482
  };
367
483
  }
368
484
  function normalizeGitHubResourceEvents(args) {
@@ -377,13 +493,15 @@ function normalizeGitHubResourceEvents(args) {
377
493
  const event = normalizePullRequestEvent(args.deliveryId, args.body);
378
494
  return event ? [event] : [];
379
495
  }
496
+ case "issues": {
497
+ return normalizeIssueEvents(args.deliveryId, args.body);
498
+ }
380
499
  case "pull_request_review": {
381
500
  const event = normalizePullRequestReviewEvent(args.deliveryId, args.body);
382
501
  return event ? [event] : [];
383
502
  }
384
503
  case "issue_comment": {
385
- const event = normalizeIssueCommentEvent(args.deliveryId, args.body);
386
- return event ? [event] : [];
504
+ return normalizeIssueCommentEvents(args.deliveryId, args.body);
387
505
  }
388
506
  case "pull_request_review_comment": {
389
507
  const event = normalizePullRequestReviewCommentEvent(
@@ -400,7 +518,15 @@ function normalizeGitHubResourceEvents(args) {
400
518
  }
401
519
 
402
520
  export {
521
+ GITHUB_ISSUE_EVENTS,
522
+ GITHUB_ISSUE_SUGGESTED_EVENTS,
523
+ gitHubIssueSubscribable,
524
+ GITHUB_DEPLOYMENT_EVENTS,
525
+ GITHUB_DEPLOYMENT_SUGGESTED_EVENTS,
403
526
  gitHubDeploymentSourceSubscribable,
527
+ GITHUB_PULL_REQUEST_EVENTS,
528
+ GITHUB_PULL_REQUEST_SUGGESTED_EVENTS,
404
529
  gitHubPullRequestSubscribable,
530
+ gitHubRepositorySubscribable,
405
531
  normalizeGitHubResourceEvents
406
532
  };