@sentry/junior-github 0.295.0 → 0.296.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
@@ -1642,6 +1642,7 @@ var GITHUB_STACKS_API_VERSION = "2026-03-10";
1642
1642
  var stackTargetSchema = z10.object({
1643
1643
  number: z10.number().int().positive(),
1644
1644
  head: z10.object({
1645
+ ref: z10.string().min(1),
1645
1646
  repo: z10.object({ full_name: z10.string().min(1) }).nullable()
1646
1647
  }),
1647
1648
  base: z10.object({
@@ -1664,7 +1665,8 @@ var stackSchema = z10.object({
1664
1665
  });
1665
1666
  async function stackGitHubPullRequest(ctx, target) {
1666
1667
  const repo = target.base.repo.full_name;
1667
- if (target.base.ref === target.base.repo.default_branch || target.head.repo?.full_name !== repo) {
1668
+ const trunk = target.base.repo.default_branch;
1669
+ if (target.base.ref === trunk || target.head.ref === trunk || target.head.repo?.full_name !== repo) {
1668
1670
  return void 0;
1669
1671
  }
1670
1672
  const [owner, name] = repo.split("/");
@@ -1694,7 +1696,7 @@ async function stackGitHubPullRequest(ctx, target) {
1694
1696
  try {
1695
1697
  const chain = [target.number];
1696
1698
  let branch = target.base.ref;
1697
- for (let depth = 0; depth < MAX_STACK_DEPTH; depth += 1) {
1699
+ for (let depth = 0; depth < MAX_STACK_DEPTH && branch !== trunk; depth += 1) {
1698
1700
  const parents = await github(
1699
1701
  "github.pull.list",
1700
1702
  `${api}/pulls?state=open&per_page=2&head=${encodeURIComponent(`${owner}:${branch}`)}`,
@@ -1703,6 +1705,7 @@ async function stackGitHubPullRequest(ctx, target) {
1703
1705
  if (!parents) return void 0;
1704
1706
  if (parents.length !== 1) break;
1705
1707
  const parent = parents[0];
1708
+ if (chain.includes(parent.number)) return void 0;
1706
1709
  const stacks = await github(
1707
1710
  "github.stack.read",
1708
1711
  `${api}/stacks?pull_request=${parent.number}`,
@@ -6571,86 +6574,17 @@ function githubUserReadReason(method, upstreamUrl) {
6571
6574
  }
6572
6575
  return upstreamUrl.pathname.toLowerCase() === "/user" ? "github.user-read" : void 0;
6573
6576
  }
6574
- function parseGitHubGraphqlOperation(bodyText) {
6575
- const parsed = parseGitHubGraphqlRequest(bodyText);
6576
- if (!parsed) {
6577
- return void 0;
6578
- }
6579
- const { normalized, operationName } = parsed;
6580
- if (operationName) {
6581
- const namedOperation = normalized.match(
6582
- new RegExp(
6583
- `\\b(query|mutation|subscription)\\s+${escapeRegExp2(operationName)}\\b`
6584
- )
6585
- )?.[1];
6586
- return namedOperation ? graphqlOperationAccess(namedOperation) : void 0;
6587
- }
6588
- const operation = normalized.match(/\b(query|mutation|subscription)\b/)?.[1];
6589
- const operationAccess = graphqlOperationAccess(operation);
6590
- if (operationAccess) {
6591
- return operationAccess;
6592
- }
6593
- if (normalized.startsWith("{")) {
6594
- return "read";
6595
- }
6596
- return void 0;
6577
+ function githubGraphqlOperation(graphql) {
6578
+ return graphql?.kind === "operation" ? graphql.operation : void 0;
6597
6579
  }
6598
- function parseGitHubGraphqlRequest(bodyText) {
6599
- if (typeof bodyText !== "string" || bodyText.trim().length === 0) {
6600
- return void 0;
6601
- }
6602
- let parsed;
6603
- try {
6604
- parsed = JSON.parse(bodyText);
6605
- } catch {
6606
- return void 0;
6607
- }
6608
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
6609
- return void 0;
6610
- }
6611
- const query = parsed.query;
6612
- if (typeof query !== "string") {
6613
- return void 0;
6614
- }
6615
- const operationName = typeof parsed.operationName === "string" ? parsed.operationName.trim() : void 0;
6616
- const normalized = maskGraphqlStringLiterals(
6617
- query.replace(/^\s*#[^\n\r]*(?:\r?\n|$)/gm, "")
6618
- ).trim();
6619
- return {
6620
- normalized,
6621
- ...operationName ? { operationName } : void 0
6622
- };
6623
- }
6624
- function escapeRegExp2(value) {
6625
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
6626
- }
6627
- function graphqlOperationAccess(operation) {
6628
- if (operation === "mutation" || operation === "subscription") {
6629
- return "write";
6630
- }
6631
- if (operation === "query") {
6632
- return "read";
6633
- }
6634
- return void 0;
6635
- }
6636
- function maskGraphqlStringLiterals(query) {
6637
- return query.replace(
6638
- /"""[\s\S]*?"""|"(?:\\.|[^"\\])*"/g,
6639
- (match) => " ".repeat(match.length)
6640
- );
6641
- }
6642
- function githubGraphqlAccess(method, upstreamUrl, bodyText) {
6580
+ function githubGraphqlAccess(method, upstreamUrl, graphql) {
6643
6581
  if (!isGitHubGraphqlUrl(upstreamUrl)) {
6644
6582
  return void 0;
6645
6583
  }
6646
6584
  if (HTTP_READ_METHODS.has(method)) {
6647
6585
  return "read";
6648
6586
  }
6649
- const operation = parseGitHubGraphqlOperation(bodyText);
6650
- if (operation) {
6651
- return operation;
6652
- }
6653
- return "write";
6587
+ return githubGraphqlOperation(graphql)?.type === "query" ? "read" : "write";
6654
6588
  }
6655
6589
  function githubGraphqlPermissionDeniedMessage(bodyText) {
6656
6590
  let parsed;
@@ -6740,8 +6674,10 @@ var ISSUE_PATH = /^\/repos\/[^/]+\/[^/]+\/issues\/\d+$/;
6740
6674
  var ISSUE_READ_DENIAL = `Use github_getIssue to read a GitHub issue, not gh issue view or gh api. Read comments with gh api repos/OWNER/REPO/issues/NUMBER/comments. ${CREATE_TOOL_ROUTING_GUIDANCE}`;
6741
6675
  function isGitHubIssueRead(input) {
6742
6676
  if (isGitHubGraphqlUrl(input.upstreamUrl)) {
6743
- const parsed = parseGitHubGraphqlRequest(input.bodyText);
6744
- return input.method === "POST" && parsed !== void 0 && /\b(?:issue|issueOrPullRequest)\s*\(/.test(parsed.normalized);
6677
+ const operation = input.method === "POST" ? githubGraphqlOperation(input.graphql) : void 0;
6678
+ return operation?.fields.some(
6679
+ (field) => (field.name === "issue" || field.name === "issueOrPullRequest") && field.arguments.length > 0
6680
+ ) ?? false;
6745
6681
  }
6746
6682
  return isGitHubApiUrl(input.upstreamUrl) && HTTP_READ_METHODS.has(input.method) && ISSUE_PATH.test(input.upstreamUrl.pathname.toLowerCase());
6747
6683
  }
@@ -6870,32 +6806,29 @@ var HOST_GRAPHQL_MUTATIONS = [
6870
6806
  operationPrefix: "github.pull.review-reaction.update:"
6871
6807
  }
6872
6808
  ];
6873
- function hostGraphqlMutationRepository(operation, method, upstreamUrl, bodyText) {
6809
+ function hostGraphqlMutationRepository(operation, method, upstreamUrl, graphql) {
6874
6810
  if (method !== "POST" || !isGitHubGraphqlUrl(upstreamUrl) || !operation) {
6875
6811
  return void 0;
6876
6812
  }
6877
- const parsed = parseGitHubGraphqlRequest(bodyText);
6813
+ const parsed = githubGraphqlOperation(graphql);
6878
6814
  const mutation = HOST_GRAPHQL_MUTATIONS.find(
6879
- (candidate) => operation.startsWith(candidate.operationPrefix) && parsed?.operationName === candidate.operationName && new RegExp(`\\bmutation\\s+${candidate.operationName}\\b`).test(
6880
- parsed.normalized
6881
- ) && new RegExp(`\\b${candidate.field}\\b`).test(parsed.normalized)
6815
+ (candidate) => operation.startsWith(candidate.operationPrefix) && parsed?.type === "mutation" && parsed.name === candidate.operationName && parsed.rootFields.length === 1 && parsed.rootFields[0] === candidate.field
6882
6816
  );
6883
6817
  if (!mutation) return void 0;
6884
6818
  const repository2 = operation.slice(mutation.operationPrefix.length);
6885
6819
  return /^[^/]+\/[^/]+$/.test(repository2) ? repository2 : void 0;
6886
6820
  }
6887
- function isGitHubGraphqlMutation(method, upstreamUrl, bodyText, field) {
6821
+ function isGitHubGraphqlMutation(method, upstreamUrl, graphql, field) {
6888
6822
  if (method !== "POST" || !isGitHubGraphqlUrl(upstreamUrl)) return false;
6889
- const parsed = parseGitHubGraphqlRequest(bodyText);
6890
- if (!parsed || !new RegExp(`\\b${field}\\b`).test(parsed.normalized)) {
6891
- return false;
6892
- }
6893
- if (!parsed.operationName) return /\bmutation\b/.test(parsed.normalized);
6894
- return new RegExp(
6895
- `\\bmutation\\s+${escapeRegExp2(parsed.operationName)}\\b`
6896
- ).test(parsed.normalized);
6823
+ const parsed = githubGraphqlOperation(graphql);
6824
+ return parsed?.type === "mutation" && parsed.rootFields.includes(field);
6897
6825
  }
6898
6826
  function applyGitHubEgressPolicy(input) {
6827
+ if (isGitHubGraphqlUrl(input.upstreamUrl) && input.graphql?.kind === "unreadable" && input.graphql.reason === "too-large") {
6828
+ throw new EgressPolicyDenied3(
6829
+ "GitHub GraphQL request body is too large to inspect before issuing credentials."
6830
+ );
6831
+ }
6899
6832
  const reactionWrite = isGitHubApiUrl(input.upstreamUrl) && (input.method === "POST" || input.method === "DELETE") && PULL_REQUEST_COMMENT_REACTIONS_PATH.test(
6900
6833
  input.upstreamUrl.pathname.toLowerCase()
6901
6834
  );
@@ -6922,7 +6855,7 @@ function applyGitHubEgressPolicy(input) {
6922
6855
  (candidate) => candidate.method === input.method && isGitHubApiUrl(input.upstreamUrl) && candidate.restPath.test(pathname) || isGitHubGraphqlMutation(
6923
6856
  input.method,
6924
6857
  input.upstreamUrl,
6925
- input.bodyText,
6858
+ input.graphql,
6926
6859
  candidate.graphqlField
6927
6860
  )
6928
6861
  );
@@ -6965,6 +6898,7 @@ async function selectGitHubGrant(ctx, env, upstreamUrl) {
6965
6898
  const method = ctx.request.method.toUpperCase();
6966
6899
  applyGitHubEgressPolicy({
6967
6900
  ...ctx.request.bodyText !== void 0 ? { bodyText: ctx.request.bodyText } : void 0,
6901
+ ...ctx.request.graphql ? { graphql: ctx.request.graphql } : void 0,
6968
6902
  method,
6969
6903
  ...ctx.request.operation ? { operation: ctx.request.operation } : void 0,
6970
6904
  upstreamUrl
@@ -7019,7 +6953,7 @@ async function selectGitHubGrant(ctx, env, upstreamUrl) {
7019
6953
  ctx.request.operation,
7020
6954
  method,
7021
6955
  upstreamUrl,
7022
- ctx.request.bodyText
6956
+ ctx.request.graphql
7023
6957
  );
7024
6958
  if (hostMutationRepository) {
7025
6959
  return {
@@ -7035,7 +6969,7 @@ async function selectGitHubGrant(ctx, env, upstreamUrl) {
7035
6969
  const graphqlAccess = githubGraphqlAccess(
7036
6970
  method,
7037
6971
  upstreamUrl,
7038
- ctx.request.bodyText
6972
+ ctx.request.graphql
7039
6973
  );
7040
6974
  if (graphqlAccess) {
7041
6975
  if (graphqlAccess === "write") {
@@ -13,6 +13,7 @@ import * as z from "zod";
13
13
  export declare const stackTargetSchema: z.ZodObject<{
14
14
  number: z.ZodNumber;
15
15
  head: z.ZodObject<{
16
+ ref: z.ZodString;
16
17
  repo: z.ZodNullable<z.ZodObject<{
17
18
  full_name: z.ZodString;
18
19
  }, z.core.$strip>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-github",
3
- "version": "0.295.0",
3
+ "version": "0.296.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.295.0"
35
+ "@sentry/junior-plugin-api": "0.296.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@oxlint/plugins": "1.79.0",