@sentry/junior-github 0.287.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.
@@ -221,7 +221,7 @@ function gitHubPullRequestEventGuidance(guidance) {
221
221
  var MERGE_STATE_CHECK = "Do not guess whether it can merge. Before you say anything about that, run `gh pr view NUMBER --repo OWNER/REPO --json autoMergeRequest,mergeStateStatus,reviewDecision,baseRefName --jq '{autoMerge: (.autoMergeRequest != null), mergeStateStatus, reviewDecision, baseRefName}'` and `gh pr checks NUMBER --repo OWNER/REPO --required`. If it prints \"no required checks reported\", the required checks may not have started on the latest commit yet. It does not mean that none are required. If auto-merge is on and only required checks remain, say only that it merges when they pass. If GitHub blocks it for another reason, run `gh api repos/OWNER/REPO/rules/branches/BASE` and name the rule that blocks it. Do not say that you did not merge it.";
222
222
  var GITHUB_PULL_REQUEST_OUTCOME_GUIDANCE = {
223
223
  "pull_request.review.approved": `Mention each person in People involved, or the person who asked for the pull request if that line is missing. Say who approved it and link it. Do not merge it unless asked. ${MERGE_STATE_CHECK}`,
224
- "pull_request.merged": `${STACK_CHECK} If open pull requests in the stack remain above it and Junior pushed their branches, restack them before you reply. Do not ask first. Run \`gh stack checkout NUMBER\` with the lowest open pull request, then \`gh stack sync\`. If sync reports a conflict, ${STACK_CONFLICT_STEPS} Then mention each person in People involved, or the person who asked for the pull request if that line is missing. Say that it merged and link it. When you restacked, say so in the same reply.`
224
+ "pull_request.merged": "Mention each person in People involved, or the person who asked for the pull request if that line is missing. Say that it merged and link it."
225
225
  };
226
226
  function gitHubPullRequestCreateWatch(config) {
227
227
  const outcomeEvents = Object.keys(
package/dist/index.js CHANGED
@@ -59,7 +59,7 @@ import {
59
59
  readGrantPermissions,
60
60
  requireEnv,
61
61
  resolveUserAccount
62
- } from "./chunk-XOE6HDSA.js";
62
+ } from "./chunk-RRID5LSH.js";
63
63
 
64
64
  // src/tool-support/attribution.ts
65
65
  import * as z from "zod";
@@ -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 {
@@ -4027,23 +4055,17 @@ function pullRequestRefs(events) {
4027
4055
  }
4028
4056
  return [...refs.values()];
4029
4057
  }
4030
- async function hasMatch(hasMatchEvent, ref) {
4031
- for (const event of gitHubMergeConflictEvents(ref)) {
4032
- if (await hasMatchEvent(event)) return true;
4033
- }
4034
- return false;
4035
- }
4036
4058
  function deliveredPullRequest(payload, ref) {
4037
4059
  const parsed = z26.object({ pull_request: pullRequestSchema3 }).safeParse(payload);
4038
4060
  const pullRequest = parsed.success ? parsed.data.pull_request : void 0;
4039
4061
  return pullRequest?.number === ref.number && typeof pullRequest.mergeable === "boolean" ? pullRequest : void 0;
4040
4062
  }
4041
4063
  async function loadGitHubMergeConflictEvents(args) {
4042
- const { hasMatch: hasMatchEvent, loadPullRequest: loadPullRequest2 } = args;
4043
- if (!hasMatchEvent || !loadPullRequest2) return [];
4064
+ const { hasMatch, loadPullRequest: loadPullRequest2 } = args;
4065
+ if (!hasMatch || !loadPullRequest2) return [];
4044
4066
  const conflicts = [];
4045
4067
  for (const ref of pullRequestRefs(args.events)) {
4046
- if (!await hasMatch(hasMatchEvent, ref)) continue;
4068
+ if (!await hasMatch(gitHubMergeConflictEvents(ref))) continue;
4047
4069
  try {
4048
4070
  const loaded = deliveredPullRequest(args.pullRequestPayload, ref) ?? pullRequestSchema3.parse(await loadPullRequest2(ref));
4049
4071
  if (loaded.state !== "open" || loaded.mergeable !== false || loaded.mergeable_state !== "dirty") {
@@ -4499,12 +4521,10 @@ async function withGitHubPullRequestMatchData(args) {
4499
4521
  );
4500
4522
  const events = filtered.size > 0 ? await withLookups(context, args.events, filtered) : args.events;
4501
4523
  const rest = new Set(ALL_LOOKUPS.filter((lookup) => !filtered.has(lookup)));
4502
- const { hasMatch: hasMatch2 } = args;
4503
- if (rest.size === 0 || !hasMatch2) return events;
4504
- const matches = await Promise.all(
4505
- events.filter((event) => numbers.has(event.eventKey)).map((event) => hasMatch2(event))
4506
- );
4507
- if (!matches.some(Boolean)) return events;
4524
+ const { hasMatch } = args;
4525
+ if (rest.size === 0 || !hasMatch) return events;
4526
+ const matchEvents = events.filter((event) => numbers.has(event.eventKey));
4527
+ if (!await hasMatch(matchEvents)) return events;
4508
4528
  return await withLookups(context, events, rest);
4509
4529
  }
4510
4530
 
@@ -4606,18 +4626,15 @@ async function loadGitHubPullRequestAuthors(args) {
4606
4626
  return [...authors.values()].slice(0, MAX_PEOPLE);
4607
4627
  }
4608
4628
  async function withGitHubPullRequestPeople(args) {
4609
- const { hasMatch: hasMatch2 } = args;
4629
+ const { hasMatch } = args;
4610
4630
  const peopleEvents = args.events.filter(
4611
4631
  (event) => PEOPLE_EVENTS.has(event.eventType)
4612
4632
  );
4613
4633
  const parsed = webhookSchema2.safeParse(args.body);
4614
- if (peopleEvents.length === 0 || !hasMatch2 || !args.load || !parsed.success) {
4634
+ if (peopleEvents.length === 0 || !hasMatch || !args.load || !parsed.success) {
4615
4635
  return args.events;
4616
4636
  }
4617
- const matches = await Promise.all(
4618
- peopleEvents.map((event) => hasMatch2(event))
4619
- );
4620
- if (!matches.some(Boolean)) return args.events;
4637
+ if (!await hasMatch(peopleEvents)) return args.events;
4621
4638
  const { pull_request: pullRequest, repository: repository2 } = parsed.data;
4622
4639
  const target = {
4623
4640
  logins: [
@@ -4836,7 +4853,7 @@ function createGitHubWebhookRoute(args) {
4836
4853
  log: args.log,
4837
4854
  privateKeyEnv: args.privateKeyEnv
4838
4855
  }) : void 0;
4839
- const hasMatch2 = args.events.hasMatch;
4856
+ const hasMatch = args.events.hasMatch;
4840
4857
  const commitPages = args.loadPullRequestCommitPages ? shareCommitPages(args.loadPullRequestCommitPages) : void 0;
4841
4858
  const events = await withGitHubPullRequestPeople({
4842
4859
  body,
@@ -4853,7 +4870,7 @@ function createGitHubWebhookRoute(args) {
4853
4870
  deliveryId,
4854
4871
  eventName
4855
4872
  }),
4856
- hasMatch: hasMatch2,
4873
+ hasMatch,
4857
4874
  ...commitPages ? {
4858
4875
  loadAuthors: async (target) => await loadGitHubPullRequestAuthors({
4859
4876
  loadPage: commitPages(target)
@@ -4864,7 +4881,7 @@ function createGitHubWebhookRoute(args) {
4864
4881
  log: args.log,
4865
4882
  neededMatchKeys: args.events.neededMatchKeys
4866
4883
  }),
4867
- hasMatch: hasMatch2,
4884
+ hasMatch,
4868
4885
  ...commitPages ? {
4869
4886
  load: async (target) => await loadGitHubPullRequestPeople({
4870
4887
  logins: target.logins,
@@ -4874,9 +4891,7 @@ function createGitHubWebhookRoute(args) {
4874
4891
  log: args.log
4875
4892
  });
4876
4893
  const feedbackTarget = pullRequestFeedbackTarget(events);
4877
- const feedbackHasMatch = feedbackTarget && hasMatch2 ? (await Promise.all(events.map((event) => hasMatch2(event)))).some(
4878
- Boolean
4879
- ) : false;
4894
+ const feedbackHasMatch = feedbackTarget && hasMatch ? await hasMatch(events) : false;
4880
4895
  if (feedbackTarget && feedbackHasMatch) {
4881
4896
  try {
4882
4897
  await args.markFeedbackReviewing(feedbackTarget);
@@ -4893,7 +4908,7 @@ function createGitHubWebhookRoute(args) {
4893
4908
  ...await loadGitHubMergeConflictEvents({
4894
4909
  deliveryId,
4895
4910
  events,
4896
- hasMatch: hasMatch2,
4911
+ hasMatch,
4897
4912
  loadPullRequest: args.loadPullRequest,
4898
4913
  log: args.log,
4899
4914
  pullRequestPayload: eventName === "pull_request" ? body : void 0
package/dist/testing.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  normalizeGitHubEvents
3
- } from "./chunk-XOE6HDSA.js";
3
+ } from "./chunk-RRID5LSH.js";
4
4
  export {
5
5
  normalizeGitHubEvents
6
6
  };
@@ -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.287.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.287.0"
35
+ "@sentry/junior-plugin-api": "0.289.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, except in a stack: a stack merges only with a linear history, so stacked PRs restack with `gh stack`. When a stacked PR merges, restack the open PRs above it, because GitHub sends them no event when its own rebase stops at a conflict. 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.
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, except in a stack: a stack merges only with a linear history, so stacked PRs restack with `gh stack`. 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
  - For 5xx, timeout, and connection failures, and for stalled or unexplained check failures, check GitHub status with `github_getStatus` (or the incidents on a `pull_request.checks.failed` event) before diagnosing. Report a matching incident as the likely cause; with no match, do not blame an outage.
@@ -51,4 +51,4 @@ Open this when making repository edits, not for read-only inspection.
51
51
 
52
52
  ## Follow
53
53
 
54
- When PR creation returns a subscribable hint, subscribe to suggested review/CI events. Fix routine review feedback and failed checks without a thread update. When a PR in a stack merges, restack the open PRs above it with `gh stack sync` before you reply; GitHub sends them no event when its own rebase stops at a conflict. Reply only when the requester needs to act, or when the PR merges or closes.
54
+ When PR creation returns a subscribable hint, subscribe to suggested review/CI events. Fix routine review feedback and failed checks without a thread update. Reply only when the requester needs to act, or when the PR merges or closes.
@@ -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