@sentry/junior-github 0.105.0 → 0.106.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/index.js CHANGED
@@ -472,6 +472,42 @@ import {
472
472
  import { Type as Type2 } from "@sinclair/typebox";
473
473
  import { Value as Value2 } from "@sinclair/typebox/value";
474
474
  import { z as z2 } from "zod";
475
+ import { subscribableResourceSchema } from "@sentry/junior-plugin-api";
476
+
477
+ // src/resource-events/pull-request.ts
478
+ var SUPPORTED_EVENTS = [
479
+ "checks.failed",
480
+ "checks.recovered",
481
+ "comment.created",
482
+ "review.approved",
483
+ "review.changes_requested",
484
+ "review.commented",
485
+ "review_comment.created",
486
+ "state.merged",
487
+ "state.closed_unmerged"
488
+ ];
489
+ var SUGGESTED_EVENTS = [
490
+ "checks.failed",
491
+ "comment.created",
492
+ "review.changes_requested",
493
+ "review.commented",
494
+ "review_comment.created",
495
+ "state.merged",
496
+ "state.closed_unmerged"
497
+ ];
498
+ function gitHubPullRequestSubscribable(input) {
499
+ if (!process.env.GITHUB_WEBHOOK_SECRET?.trim()) return void 0;
500
+ return {
501
+ label: `GitHub PR ${input.repo}#${input.number}`,
502
+ provider: "github",
503
+ resourceRef: `github:pull_request:${input.repo}#${input.number}`,
504
+ suggestedEvents: SUGGESTED_EVENTS,
505
+ supportedEvents: SUPPORTED_EVENTS,
506
+ type: "pull_request"
507
+ };
508
+ }
509
+
510
+ // src/tools/create-pull-request.ts
475
511
  var GITHUB_PULL_REQUEST_CREATE_IDEMPOTENCY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
476
512
  var GITHUB_PULL_REQUEST_CREATE_LOCK_TTL_MS = 6e4;
477
513
  var GitHubPullRequestCreateRejectedError = class extends Error {
@@ -537,14 +573,6 @@ var createPullRequestStateSchema = Type2.Union([
537
573
  { additionalProperties: false }
538
574
  )
539
575
  ]);
540
- var subscribableResourceSchema = z2.object({
541
- provider: z2.string(),
542
- type: z2.string(),
543
- resourceRef: z2.string(),
544
- label: z2.string(),
545
- supportedEvents: z2.array(z2.string()),
546
- suggestedEvents: z2.array(z2.string()).optional()
547
- }).strict();
548
576
  var gitHubPullRequestDataSchema = z2.object({
549
577
  number: z2.number(),
550
578
  url: z2.string(),
@@ -706,45 +734,13 @@ async function createGitHubPullRequest(ctx, request) {
706
734
  url: pullRequest.html_url
707
735
  };
708
736
  }
709
- function gitHubPullRequestSubscribable(input, result) {
710
- const repo = parseRepo2(input.repo);
711
- const repoRef = `${repo.owner}/${repo.name}`;
712
- const supportedEvents = [
713
- "checks.failed",
714
- "checks.recovered",
715
- "comment.created",
716
- "review.approved",
717
- "review.changes_requested",
718
- "review.commented",
719
- "review_comment.created",
720
- "state.merged",
721
- "state.closed_unmerged"
722
- ];
723
- return {
724
- label: `GitHub PR ${repoRef}#${result.number}`,
725
- provider: "github",
726
- resourceRef: `github:pull_request:${repoRef}#${result.number}`,
727
- suggestedEvents: [
728
- "checks.failed",
729
- "comment.created",
730
- "review.changes_requested",
731
- "review.commented",
732
- "review_comment.created",
733
- "state.merged",
734
- "state.closed_unmerged"
735
- ],
736
- supportedEvents,
737
- type: "pull_request"
738
- };
739
- }
740
737
  function gitHubPullRequestToolResult(input, result) {
741
- if (!process.env.GITHUB_WEBHOOK_SECRET?.trim()) {
742
- return result;
743
- }
744
- return {
745
- ...result,
746
- subscribable: gitHubPullRequestSubscribable(input, result)
747
- };
738
+ const repo = parseRepo2(input.repo);
739
+ const subscribable = gitHubPullRequestSubscribable({
740
+ number: result.number,
741
+ repo: `${repo.owner}/${repo.name}`
742
+ });
743
+ return { ...result, ...subscribable ? { subscribable } : {} };
748
744
  }
749
745
  function gitHubPullRequestStructuredResult(input, result) {
750
746
  const data = gitHubPullRequestToolResult(input, result);
@@ -832,11 +828,119 @@ function createGitHubPullRequestTool(ctx) {
832
828
  });
833
829
  }
834
830
 
831
+ // src/tools/get-pull-request.ts
832
+ import {
833
+ definePluginTool as definePluginTool3,
834
+ PluginToolInputError as PluginToolInputError4,
835
+ pluginToolResultSchema as pluginToolResultSchema3
836
+ } from "@sentry/junior-plugin-api";
837
+ import { z as z3 } from "zod";
838
+ import { subscribableResourceSchema as subscribableResourceSchema2 } from "@sentry/junior-plugin-api";
839
+ var inputSchema = z3.object({
840
+ repo: z3.string().describe('Repository in "owner/name" format.'),
841
+ number: z3.number().int().positive().describe("Pull request number.")
842
+ }).strict();
843
+ var pullRequestSchema = z3.object({
844
+ base: z3.string(),
845
+ draft: z3.boolean(),
846
+ head: z3.string(),
847
+ merged: z3.boolean(),
848
+ number: z3.number(),
849
+ state: z3.string(),
850
+ subscribable: subscribableResourceSchema2.optional(),
851
+ title: z3.string(),
852
+ url: z3.string()
853
+ });
854
+ var outputSchema = pluginToolResultSchema3.extend({
855
+ ok: z3.literal(true),
856
+ status: z3.literal("success"),
857
+ target: z3.literal("getPullRequest"),
858
+ data: pullRequestSchema,
859
+ ...pullRequestSchema.shape
860
+ });
861
+ function parseRepo3(value) {
862
+ const parts = value.split("/").map((part) => part.trim());
863
+ if (parts.length !== 2 || !parts[0] || !parts[1]) {
864
+ throw new PluginToolInputError4('repo must use "owner/name" format');
865
+ }
866
+ return { owner: parts[0], name: parts[1], ref: `${parts[0]}/${parts[1]}` };
867
+ }
868
+ async function readJson(response) {
869
+ const text = await response.text();
870
+ if (!text) return void 0;
871
+ try {
872
+ return JSON.parse(text);
873
+ } catch {
874
+ return text;
875
+ }
876
+ }
877
+ function createGitHubGetPullRequestTool(ctx) {
878
+ return definePluginTool3({
879
+ description: "Get a GitHub pull request. Use this when an existing PR may need resource-event monitoring; the result includes a subscribable hint when GitHub webhooks are configured.",
880
+ inputSchema,
881
+ outputSchema,
882
+ async execute(input) {
883
+ const repo = parseRepo3(input.repo);
884
+ const response = await ctx.egress.fetch({
885
+ provider: "github",
886
+ operation: "github.pull.get",
887
+ request: new Request(
888
+ `https://api.github.com/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/pulls/${input.number}`,
889
+ {
890
+ headers: {
891
+ Accept: "application/vnd.github+json",
892
+ "X-GitHub-Api-Version": "2022-11-28"
893
+ }
894
+ }
895
+ )
896
+ });
897
+ const parsed = await readJson(response);
898
+ if (!response.ok)
899
+ throw new Error(
900
+ `GitHub pull request lookup failed with HTTP ${response.status}`
901
+ );
902
+ const providerResult = z3.object({
903
+ base: z3.object({ ref: z3.string() }),
904
+ draft: z3.boolean(),
905
+ head: z3.object({ ref: z3.string() }),
906
+ html_url: z3.string(),
907
+ merged: z3.boolean().optional().default(false),
908
+ number: z3.number(),
909
+ state: z3.string(),
910
+ title: z3.string()
911
+ }).parse(parsed);
912
+ const subscribable = gitHubPullRequestSubscribable({
913
+ number: providerResult.number,
914
+ repo: repo.ref
915
+ });
916
+ const data = {
917
+ base: providerResult.base.ref,
918
+ draft: providerResult.draft,
919
+ head: providerResult.head.ref,
920
+ merged: providerResult.merged,
921
+ number: providerResult.number,
922
+ state: providerResult.state,
923
+ ...subscribable ? { subscribable } : {},
924
+ title: providerResult.title,
925
+ url: providerResult.html_url
926
+ };
927
+ return {
928
+ ok: true,
929
+ status: "success",
930
+ target: "getPullRequest",
931
+ data,
932
+ ...data
933
+ };
934
+ }
935
+ });
936
+ }
937
+
835
938
  // src/tools.ts
836
939
  function createGitHubTools(ctx) {
837
940
  return {
838
941
  createIssue: createGitHubIssueTool(ctx),
839
- createPullRequest: createGitHubPullRequestTool(ctx)
942
+ createPullRequest: createGitHubPullRequestTool(ctx),
943
+ getPullRequest: createGitHubGetPullRequestTool(ctx)
840
944
  };
841
945
  }
842
946
 
@@ -0,0 +1,6 @@
1
+ import type { SubscribableResource } from "@sentry/junior-plugin-api";
2
+ /** Build the stable resource identity shared by GitHub PR tool results and webhooks. */
3
+ export declare function gitHubPullRequestSubscribable(input: {
4
+ number: number;
5
+ repo: string;
6
+ }): SubscribableResource | undefined;
@@ -16,11 +16,11 @@ export declare function createGitHubPullRequestTool(ctx: ToolRegistrationHookCon
16
16
  number: number;
17
17
  url: string;
18
18
  subscribable?: {
19
+ label: string;
19
20
  provider: string;
20
- type: string;
21
21
  resourceRef: string;
22
- label: string;
23
22
  supportedEvents: string[];
23
+ type: string;
24
24
  suggestedEvents?: string[] | undefined;
25
25
  } | undefined;
26
26
  };
@@ -37,11 +37,11 @@ export declare function createGitHubPullRequestTool(ctx: ToolRegistrationHookCon
37
37
  retryable?: boolean | undefined;
38
38
  } | undefined;
39
39
  subscribable?: {
40
+ label: string;
40
41
  provider: string;
41
- type: string;
42
42
  resourceRef: string;
43
- label: string;
44
43
  supportedEvents: string[];
44
+ type: string;
45
45
  suggestedEvents?: string[] | undefined;
46
46
  } | undefined;
47
47
  }>;
@@ -0,0 +1,55 @@
1
+ import { type ToolRegistrationHookContext } from "@sentry/junior-plugin-api";
2
+ /** Read one PR and expose its stable subscription identity when webhooks are enabled. */
3
+ export declare function createGitHubGetPullRequestTool(ctx: ToolRegistrationHookContext): import("@sentry/junior-plugin-api").PluginToolDefinition<{
4
+ repo: string;
5
+ number: number;
6
+ }, {
7
+ [x: string]: unknown;
8
+ base: string;
9
+ draft: boolean;
10
+ head: string;
11
+ merged: boolean;
12
+ number: number;
13
+ state: string;
14
+ title: string;
15
+ url: string;
16
+ ok: true;
17
+ status: "success";
18
+ target: "getPullRequest";
19
+ data: {
20
+ base: string;
21
+ draft: boolean;
22
+ head: string;
23
+ merged: boolean;
24
+ number: number;
25
+ state: string;
26
+ title: string;
27
+ url: string;
28
+ subscribable?: {
29
+ label: string;
30
+ provider: string;
31
+ resourceRef: string;
32
+ supportedEvents: string[];
33
+ type: string;
34
+ suggestedEvents?: string[] | undefined;
35
+ } | undefined;
36
+ };
37
+ truncated?: boolean | undefined;
38
+ continuation?: {
39
+ arguments: Record<string, unknown>;
40
+ reason?: string | undefined;
41
+ } | undefined;
42
+ error?: string | {
43
+ kind: string;
44
+ message: string;
45
+ retryable?: boolean | undefined;
46
+ } | undefined;
47
+ subscribable?: {
48
+ label: string;
49
+ provider: string;
50
+ resourceRef: string;
51
+ supportedEvents: string[];
52
+ type: string;
53
+ suggestedEvents?: string[] | undefined;
54
+ } | undefined;
55
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-github",
3
- "version": "0.105.0",
3
+ "version": "0.106.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@sinclair/typebox": "^0.34.49",
27
27
  "zod": "^4.4.3",
28
- "@sentry/junior-plugin-api": "0.105.0"
28
+ "@sentry/junior-plugin-api": "0.106.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^25.9.1",