@sentry/junior-github 0.288.0 → 0.289.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
@@ -69,28 +69,47 @@ import {
69
69
  PluginToolInputError
70
70
  } from "@sentry/junior-plugin-api";
71
71
  var GITHUB_API_BASE = "https://api.github.com";
72
+ var MAX_REDIRECTS = 3;
73
+ var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 307, 308]);
72
74
  async function githubApi(egress, input) {
73
75
  const headers = {
74
76
  Accept: "application/vnd.github+json",
75
77
  "X-GitHub-Api-Version": input.apiVersion ?? "2022-11-28"
76
78
  };
77
79
  if (input.body !== void 0) headers["Content-Type"] = "application/json";
78
- const response = await egress.fetch({
79
- provider: "github",
80
- operation: input.operation,
81
- request: new Request(`${GITHUB_API_BASE}${input.path}`, {
82
- method: input.method ?? "GET",
83
- headers,
84
- signal: input.signal,
85
- ...input.body !== void 0 ? { body: JSON.stringify(input.body) } : void 0
86
- })
87
- });
80
+ const method = input.method ?? "GET";
81
+ let url = `${GITHUB_API_BASE}${input.path}`;
82
+ let response;
83
+ const follow = input.followRedirects === true && method === "GET";
84
+ for (let hop = 0; ; hop++) {
85
+ response = await egress.fetch({
86
+ provider: "github",
87
+ operation: input.operation,
88
+ request: new Request(url, {
89
+ method,
90
+ headers,
91
+ signal: input.signal,
92
+ ...input.body !== void 0 ? { body: JSON.stringify(input.body) } : void 0
93
+ })
94
+ });
95
+ const next = follow ? redirectTarget(response, url) : void 0;
96
+ if (!next || hop >= MAX_REDIRECTS) break;
97
+ await response.body?.cancel();
98
+ url = next;
99
+ }
88
100
  return {
89
101
  body: await readBody(response),
90
102
  ok: response.ok,
91
103
  status: response.status
92
104
  };
93
105
  }
106
+ function redirectTarget(response, from) {
107
+ if (!REDIRECT_STATUSES.has(response.status)) return void 0;
108
+ const location = response.headers.get("location");
109
+ if (!location) return void 0;
110
+ const target = new URL(location, from);
111
+ return target.origin === GITHUB_API_BASE ? target.href : void 0;
112
+ }
94
113
  async function readBody(response) {
95
114
  const text2 = await response.text();
96
115
  if (!text2) return void 0;
@@ -1341,6 +1360,7 @@ var providerIssueSchema = z8.object({
1341
1360
  html_url: z8.string(),
1342
1361
  labels: z8.array(z8.object({ name: z8.string() })).optional().default([]).transform((labels) => labels.map(({ name }) => name)),
1343
1362
  number: z8.number(),
1363
+ repository_url: z8.string().optional(),
1344
1364
  state: z8.string(),
1345
1365
  title: z8.string(),
1346
1366
  user: z8.object({ login: z8.string() }).nullish()
@@ -1360,6 +1380,7 @@ function createGitHubGetIssueTool(ctx) {
1360
1380
  const repo = parseRepo(input.repo);
1361
1381
  const [response, requester] = await Promise.all([
1362
1382
  githubApi(ctx.egress, {
1383
+ followRedirects: true,
1363
1384
  operation: "github.issue.get",
1364
1385
  path: `${repoPath(repo)}/issues/${input.number}`
1365
1386
  }),
@@ -1373,18 +1394,19 @@ function createGitHubGetIssueTool(ctx) {
1373
1394
  throw new Error(message);
1374
1395
  }
1375
1396
  const issue = providerIssueSchema.parse(response.body);
1397
+ const repoRef = issueRepoRef(issue.repository_url) ?? repo.ref;
1376
1398
  const login = linkedGitHubLogin(requester?.user)?.toLowerCase();
1377
1399
  const needsClaim = login !== void 0 && issue.state === "open" && !issue.assignees.some((assignee) => assignee.toLowerCase() === login);
1378
1400
  const subscribable = gitHubIssueSubscribable({
1379
1401
  canSubscribe: ctx.events.canSubscribe,
1380
1402
  number: issue.number,
1381
- repo: repo.ref
1403
+ repo: repoRef
1382
1404
  });
1383
1405
  return {
1384
1406
  objectAnnotations: [
1385
1407
  githubObjectAnnotation({
1386
1408
  ...githubObjectFacts("task", response.body),
1387
- repo: repo.ref,
1409
+ repo: repoRef,
1388
1410
  number: issue.number,
1389
1411
  title: issue.title,
1390
1412
  url: issue.html_url,
@@ -1408,6 +1430,12 @@ function createGitHubGetIssueTool(ctx) {
1408
1430
  }
1409
1431
  });
1410
1432
  }
1433
+ function issueRepoRef(repositoryUrl) {
1434
+ const match = repositoryUrl?.match(
1435
+ /^https:\/\/api\.github\.com\/repos\/([^/]+\/[^/]+)$/
1436
+ );
1437
+ return match?.[1];
1438
+ }
1411
1439
 
1412
1440
  // src/tools/create-pull-request.ts
1413
1441
  import {
@@ -11,10 +11,14 @@ export interface GitHubApiResponse {
11
11
  * Egress injects credentials, so tools never see a token. `operation` names
12
12
  * the provider action for grant selection and diagnostics. Callers own the
13
13
  * error mapping, because the status that means bad input differs per route.
14
+ * `followRedirects` follows GET redirects on the GitHub API host. Set it only
15
+ * when the caller reads the object identity from the response, because the
16
+ * redirect target can be in another repository.
14
17
  */
15
18
  export declare function githubApi(egress: PluginEgress, input: {
16
19
  apiVersion?: string;
17
20
  body?: unknown;
21
+ followRedirects?: boolean;
18
22
  method?: "DELETE" | "GET" | "PATCH" | "POST" | "PUT";
19
23
  operation: string;
20
24
  path: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-github",
3
- "version": "0.288.0",
3
+ "version": "0.289.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.288.0"
35
+ "@sentry/junior-plugin-api": "0.289.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@oxlint/plugins": "1.79.0",
@@ -97,7 +97,7 @@ Run [references/issue-quality-checklist.md](references/issue-quality-checklist.m
97
97
  - Use `github_commentOnIssue` to comment on an issue.
98
98
  - Use `gh` commands from [references/api-surface.md](references/api-surface.md) for labels, assignees, and issue lists.
99
99
  - For issue listing or other read-only inspection, prefer `--json` output so empty results still produce deterministic stdout.
100
- - Check duplicates silently before creating a new issue. Do not mention this check in the final reply unless a duplicate blocks creation.
100
+ - Check duplicates silently before creating a new issue. Do not mention this check in the final response unless a duplicate blocks creation.
101
101
 
102
102
  ### 6. Report result
103
103