@sentry/junior-github 0.294.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
@@ -59,7 +59,7 @@ import {
59
59
  readGrantPermissions,
60
60
  requireEnv,
61
61
  resolveUserAccount
62
- } from "./chunk-J4ZSG7SD.js";
62
+ } from "./chunk-D74ZUIJR.js";
63
63
 
64
64
  // src/tool-support/attribution.ts
65
65
  import * as z from "zod";
@@ -156,8 +156,8 @@ var GITHUB_REQUEST_ATTRIBUTION_END = "<!-- junior-request-attribution:end -->";
156
156
  var SLACK_USER_ID_DISPLAY_PATTERN = /^[UW][A-Z0-9]{5,}$/;
157
157
  var GITHUB_LOGIN_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/;
158
158
  function linkedGitHubLogin(user) {
159
- const login = user?.identities.find((identity) => identity.provider === "github")?.handle?.trim().replace(/^@/, "");
160
- return login && GITHUB_LOGIN_PATTERN.test(login) ? login : void 0;
159
+ const login2 = user?.identities.find((identity) => identity.provider === "github")?.handle?.trim().replace(/^@/, "");
160
+ return login2 && GITHUB_LOGIN_PATTERN.test(login2) ? login2 : void 0;
161
161
  }
162
162
  function cleanDisplayValue(value, userId) {
163
163
  const cleaned = value?.replace(/[\r\n<>]/g, " ").trim();
@@ -192,9 +192,9 @@ function requesterLabel(args) {
192
192
  if (!actor || actor.platform === "system") {
193
193
  return void 0;
194
194
  }
195
- const login = linkedGitHubLogin(user);
196
- if (login) {
197
- return `@${login}`;
195
+ const login2 = linkedGitHubLogin(user);
196
+ if (login2) {
197
+ return `@${login2}`;
198
198
  }
199
199
  const userId = actor.userId;
200
200
  const display = cleanDisplayValue(user?.displayName, userId) ?? cleanDisplayValue(identity?.displayName, userId) ?? cleanDisplayValue(identity?.handle, userId) ?? cleanDisplayValue(actor.fullName, userId) ?? cleanDisplayValue(actor.userName, userId);
@@ -854,11 +854,11 @@ function githubLinkedIssues(body, repositoryFullName) {
854
854
  if (!body) return [];
855
855
  const references = /* @__PURE__ */ new Map();
856
856
  const add = (linkedRepository, rawNumber) => {
857
- const number26 = Number.parseInt(rawNumber, 10);
858
- if (!Number.isInteger(number26) || number26 <= 0) return;
857
+ const number27 = Number.parseInt(rawNumber, 10);
858
+ if (!Number.isInteger(number27) || number27 <= 0) return;
859
859
  const normalizedRepository = linkedRepository.toLowerCase();
860
- references.set(`${normalizedRepository}#${number26}`, {
861
- number: number26,
860
+ references.set(`${normalizedRepository}#${number27}`, {
861
+ number: number27,
862
862
  repositoryFullName: linkedRepository
863
863
  });
864
864
  };
@@ -1354,7 +1354,7 @@ var outputSchema5 = pluginToolOutputSchema6.merge(
1354
1354
  issueSchema.extend({ target: z8.literal("getIssue") })
1355
1355
  );
1356
1356
  var providerIssueSchema = z8.object({
1357
- assignees: z8.array(z8.object({ login: z8.string() })).nullish().transform((assignees) => assignees?.map(({ login }) => login) ?? []),
1357
+ assignees: z8.array(z8.object({ login: z8.string() })).nullish().transform((assignees) => assignees?.map(({ login: login2 }) => login2) ?? []),
1358
1358
  body: z8.string().nullable().optional().default(null),
1359
1359
  comments: z8.number().optional().default(0),
1360
1360
  html_url: z8.string(),
@@ -1395,8 +1395,8 @@ function createGitHubGetIssueTool(ctx) {
1395
1395
  }
1396
1396
  const issue = providerIssueSchema.parse(response.body);
1397
1397
  const repoRef = issueRepoRef(issue.repository_url) ?? repo.ref;
1398
- const login = linkedGitHubLogin(requester?.user)?.toLowerCase();
1399
- const needsClaim = login !== void 0 && issue.state === "open" && !issue.assignees.some((assignee) => assignee.toLowerCase() === login);
1398
+ const login2 = linkedGitHubLogin(requester?.user)?.toLowerCase();
1399
+ const needsClaim = login2 !== void 0 && issue.state === "open" && !issue.assignees.some((assignee) => assignee.toLowerCase() === login2);
1400
1400
  const subscribable = gitHubIssueSubscribable({
1401
1401
  canSubscribe: ctx.events.canSubscribe,
1402
1402
  number: issue.number,
@@ -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}`,
@@ -2583,7 +2586,7 @@ var outputSchema10 = pluginToolOutputSchema12.merge(
2583
2586
  })
2584
2587
  );
2585
2588
  var providerIssueSchema2 = z17.object({
2586
- assignees: z17.array(z17.object({ login: z17.string() })).nullish().transform((assignees) => assignees?.map(({ login }) => login) ?? []),
2589
+ assignees: z17.array(z17.object({ login: z17.string() })).nullish().transform((assignees) => assignees?.map(({ login: login2 }) => login2) ?? []),
2587
2590
  body: z17.string().nullable().optional().default(null),
2588
2591
  html_url: z17.string(),
2589
2592
  number: z17.number(),
@@ -2674,7 +2677,7 @@ function createGitHubUpdateIssueTool(ctx) {
2674
2677
  }
2675
2678
  const providerResult = providerIssueSchema2.parse(parsed);
2676
2679
  if (assignee && !providerResult.assignees.some(
2677
- (login) => login.toLowerCase() === assignee.toLowerCase()
2680
+ (login2) => login2.toLowerCase() === assignee.toLowerCase()
2678
2681
  )) {
2679
2682
  throw new PluginToolInputError12(
2680
2683
  `GitHub did not assign @${assignee} to the issue. They may not have access to ${repo.ref}.`
@@ -2927,14 +2930,26 @@ var STATUS_TO_REACTION_CONTENT = {
2927
2930
  var FEEDBACK_REACTION_CONTENTS = new Set(
2928
2931
  Object.values(STATUS_TO_REACTION_CONTENT)
2929
2932
  );
2933
+ var GRAPHQL_REACTION_CONTENT = {
2934
+ eyes: "EYES",
2935
+ "+1": "THUMBS_UP",
2936
+ "-1": "THUMBS_DOWN"
2937
+ };
2938
+ var REST_REACTION_CONTENT = new Map(
2939
+ Object.entries(GRAPHQL_REACTION_CONTENT).map(([rest, graphql]) => [
2940
+ graphql,
2941
+ rest
2942
+ ])
2943
+ );
2930
2944
  var inputSchema12 = z19.object({
2931
2945
  repo: z19.string().describe('Repository in "owner/name" format.'),
2932
- comment_kind: z19.enum(["conversation", "review"]).describe(
2933
- 'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment.'
2946
+ comment_kind: z19.enum(["conversation", "review", "review_body"]).describe(
2947
+ 'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment, "review_body" for the body of a submitted review.'
2934
2948
  ),
2935
2949
  comment_id: z19.number().int().positive().describe(
2936
- "GitHub comment id (conversation comment id or inline review comment id)."
2950
+ "GitHub comment id (conversation comment id, inline review comment id, or review id)."
2937
2951
  ),
2952
+ pull_request: z19.number().int().positive().describe("Pull request number that the comment is on."),
2938
2953
  status: z19.enum(["addressed", "declined"]).describe(
2939
2954
  "Feedback outcome. Maps to a reaction: addressed -> +1, declined -> -1."
2940
2955
  )
@@ -2943,8 +2958,7 @@ var outputSchema12 = pluginToolOutputSchema14.extend({
2943
2958
  target: z19.literal("updatePullRequestFeedback"),
2944
2959
  repo: z19.string(),
2945
2960
  comment_id: z19.number(),
2946
- status: z19.enum(["addressed", "declined"]),
2947
- reaction_id: z19.number()
2961
+ status: z19.enum(["addressed", "declined"])
2948
2962
  });
2949
2963
  function pullRequestCommentPath(input) {
2950
2964
  const segment = input.commentKind === "conversation" ? "issues" : "pulls";
@@ -2961,7 +2975,7 @@ var reactionSchema = z19.object({
2961
2975
  content: z19.string(),
2962
2976
  user: z19.object({ id: z19.number() }).nullable()
2963
2977
  });
2964
- async function assertBotAuthoredPullRequest(egress, input) {
2978
+ async function commentParentNumber(egress, input) {
2965
2979
  const commentResponse = await githubApi(egress, {
2966
2980
  operation: "github.pull.comment.get",
2967
2981
  path: pullRequestCommentPath(input)
@@ -2977,13 +2991,17 @@ async function assertBotAuthoredPullRequest(egress, input) {
2977
2991
  pull_request_url: z19.string().optional()
2978
2992
  }).safeParse(commentPayload);
2979
2993
  const parentUrl = comment.success ? input.commentKind === "conversation" ? comment.data.issue_url : comment.data.pull_request_url : void 0;
2980
- const number26 = /\/(?:issues|pulls)\/(\d+)$/.exec(parentUrl ?? "")?.[1];
2981
- if (!number26) {
2994
+ const number27 = /\/(?:issues|pulls)\/(\d+)$/.exec(parentUrl ?? "")?.[1];
2995
+ if (!number27) {
2982
2996
  throw new Error("GitHub comment did not name its issue or pull request.");
2983
2997
  }
2998
+ return number27;
2999
+ }
3000
+ async function assertBotAuthoredPullRequest(egress, input) {
3001
+ const { number: number27 } = input;
2984
3002
  const pullResponse = await githubApi(egress, {
2985
3003
  operation: "github.pull.get",
2986
- path: `${repoPath(input)}/pulls/${number26}`
3004
+ path: `${repoPath(input)}/pulls/${number27}`
2987
3005
  });
2988
3006
  const pullPayload = pullResponse.body;
2989
3007
  if (!pullResponse.ok && pullResponse.status !== 404) {
@@ -2998,6 +3016,119 @@ async function assertBotAuthoredPullRequest(egress, input) {
2998
3016
  );
2999
3017
  }
3000
3018
  }
3019
+ function pullRequestReviewPath(input) {
3020
+ return `${repoPath(input)}/pulls/${input.pullRequest}/reviews/${input.reviewId}`;
3021
+ }
3022
+ function graphqlReactionContent(content) {
3023
+ return GRAPHQL_REACTION_CONTENT[content] ?? content;
3024
+ }
3025
+ var ADD_REVIEW_REACTION_MUTATION = `mutation AddReviewReaction($subjectId: ID!, $content: ReactionContent!) {
3026
+ addReaction(input: {subjectId: $subjectId, content: $content}) {
3027
+ reaction { content }
3028
+ }
3029
+ }`;
3030
+ var REMOVE_REVIEW_REACTION_MUTATION = `mutation RemoveReviewReaction($subjectId: ID!, $content: ReactionContent!) {
3031
+ removeReaction(input: {subjectId: $subjectId, content: $content}) {
3032
+ reaction { content }
3033
+ }
3034
+ }`;
3035
+ var REVIEW_REACTIONS_QUERY = `query ReviewReactions($subjectId: ID!) {
3036
+ node(id: $subjectId) {
3037
+ ... on PullRequestReview {
3038
+ reactionGroups {
3039
+ content
3040
+ reactors(first: 100) { nodes { ... on Bot { databaseId } } }
3041
+ }
3042
+ }
3043
+ }
3044
+ }`;
3045
+ var reviewReactionsSchema = z19.object({
3046
+ data: z19.object({
3047
+ node: z19.object({
3048
+ reactionGroups: z19.array(
3049
+ z19.object({
3050
+ content: z19.string(),
3051
+ reactors: z19.object({
3052
+ nodes: z19.array(z19.object({ databaseId: z19.number().optional() }))
3053
+ })
3054
+ })
3055
+ )
3056
+ })
3057
+ })
3058
+ });
3059
+ async function commentReactions(egress, input) {
3060
+ const parentNumber = await commentParentNumber(egress, input);
3061
+ if (parentNumber !== String(input.pullRequest)) {
3062
+ throw new PluginToolInputError14(
3063
+ `GitHub comment ${input.commentId} is not on pull request ${input.pullRequest}.`
3064
+ );
3065
+ }
3066
+ const path = pullRequestCommentReactionsPath(input);
3067
+ return {
3068
+ list: () => githubApi(egress, {
3069
+ operation: "github.pull.comment-reaction.list",
3070
+ path: `${path}?per_page=100`
3071
+ }),
3072
+ botReactions: (body) => z19.array(reactionSchema).parse(body).filter((reaction) => reaction.user?.id === input.botUserId),
3073
+ remove: (reaction) => githubApi(egress, {
3074
+ operation: "github.pull.comment-reaction.delete",
3075
+ method: "DELETE",
3076
+ path: `${path}/${reaction.id}`
3077
+ }),
3078
+ add: (content) => githubApi(egress, {
3079
+ operation: "github.pull.comment-reaction.create",
3080
+ method: "POST",
3081
+ path,
3082
+ body: { content }
3083
+ })
3084
+ };
3085
+ }
3086
+ async function reviewBodyReactions(egress, input) {
3087
+ const reviewResponse = await githubApi(egress, {
3088
+ operation: "github.pull.review.get",
3089
+ path: pullRequestReviewPath(input)
3090
+ });
3091
+ if (!reviewResponse.ok) {
3092
+ const message = `GitHub review lookup failed with HTTP ${reviewResponse.status}: ${githubErrorMessage(reviewResponse.body)}`;
3093
+ if (reviewResponse.status === 404) throw new PluginToolInputError14(message);
3094
+ throw new Error(message);
3095
+ }
3096
+ const subjectId = z19.object({ node_id: z19.string().min(1) }).parse(reviewResponse.body).node_id;
3097
+ const graphql = (operation, operationName, query, variables) => githubApi(egress, {
3098
+ operation,
3099
+ method: "POST",
3100
+ path: "/graphql",
3101
+ body: { operationName, query, variables }
3102
+ });
3103
+ const update = `github.pull.review-reaction.update:${input.owner}/${input.name}`.toLowerCase();
3104
+ return {
3105
+ list: () => graphql(
3106
+ "github.pull.review-reaction.list",
3107
+ "ReviewReactions",
3108
+ REVIEW_REACTIONS_QUERY,
3109
+ { subjectId }
3110
+ ),
3111
+ botReactions: (body) => reviewReactionsSchema.parse(body).data.node.reactionGroups.filter(
3112
+ (group) => group.reactors.nodes.some(
3113
+ (reactor) => reactor.databaseId === input.botUserId
3114
+ )
3115
+ ).map((group) => ({
3116
+ content: REST_REACTION_CONTENT.get(group.content) ?? group.content
3117
+ })),
3118
+ remove: (reaction) => graphql(update, "RemoveReviewReaction", REMOVE_REVIEW_REACTION_MUTATION, {
3119
+ subjectId,
3120
+ content: graphqlReactionContent(reaction.content)
3121
+ }),
3122
+ add: (content) => graphql(update, "AddReviewReaction", ADD_REVIEW_REACTION_MUTATION, {
3123
+ subjectId,
3124
+ content: graphqlReactionContent(content)
3125
+ })
3126
+ };
3127
+ }
3128
+ function failed(response) {
3129
+ const errors = response.body?.errors;
3130
+ return !response.ok || Array.isArray(errors) && errors.length > 0;
3131
+ }
3001
3132
  function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
3002
3133
  return definePluginTool14({
3003
3134
  // No action review: the tool checks in code that the bot authored the pull
@@ -3009,7 +3140,7 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
3009
3140
  openWorldHint: true,
3010
3141
  readOnlyHint: false
3011
3142
  },
3012
- description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1). Use the comment_id and comment_kind from the event after acting on the feedback. Replaces only your prior status reaction on that comment. Only works on pull requests the bot authored.",
3143
+ description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1). Use the pull_request, comment_id, and comment_kind from the event after acting on the feedback. Replaces only your prior status reaction on that comment. Only works on pull requests the bot authored.",
3013
3144
  exposure: "direct",
3014
3145
  inputSchema: inputSchema12,
3015
3146
  outputSchema: outputSchema12,
@@ -3024,6 +3155,7 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
3024
3155
  const {
3025
3156
  comment_id: commentId,
3026
3157
  comment_kind: commentKind,
3158
+ pull_request: pullRequest,
3027
3159
  status
3028
3160
  } = parsedInput.data;
3029
3161
  const repo = parseRepo(parsedInput.data.repo);
@@ -3034,74 +3166,55 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
3034
3166
  await assertBotAuthoredPullRequest(ctx.egress, {
3035
3167
  owner: repo.owner,
3036
3168
  name: repo.name,
3037
- commentKind,
3038
- commentId,
3169
+ number: pullRequest,
3039
3170
  botUserId
3040
3171
  });
3041
- const targetContent = pullRequestFeedbackReactionContent(status);
3042
- const reactionsPath = pullRequestCommentReactionsPath({
3172
+ const reactions = commentKind === "review_body" ? await reviewBodyReactions(ctx.egress, {
3173
+ owner: repo.owner,
3174
+ name: repo.name,
3175
+ pullRequest,
3176
+ reviewId: commentId,
3177
+ botUserId
3178
+ }) : await commentReactions(ctx.egress, {
3043
3179
  owner: repo.owner,
3044
3180
  name: repo.name,
3045
3181
  commentKind,
3046
- commentId
3047
- });
3048
- const listResponse = await githubApi(ctx.egress, {
3049
- operation: "github.pull.comment-reaction.list",
3050
- path: `${reactionsPath}?per_page=100`
3182
+ commentId,
3183
+ pullRequest,
3184
+ botUserId
3051
3185
  });
3186
+ const targetContent = pullRequestFeedbackReactionContent(status);
3187
+ const listResponse = await reactions.list();
3052
3188
  const listPayload = listResponse.body;
3053
- if (!listResponse.ok) {
3189
+ if (failed(listResponse)) {
3054
3190
  throw new Error(
3055
3191
  `GitHub reaction lookup failed with HTTP ${listResponse.status}: ${githubErrorMessage(listPayload)}`
3056
3192
  );
3057
3193
  }
3058
- const botReactions = z19.array(reactionSchema).parse(listPayload).filter(
3059
- (reaction) => reaction.user?.id === botUserId && FEEDBACK_REACTION_CONTENTS.has(reaction.content)
3060
- );
3061
- const existing = botReactions.find(
3062
- (reaction) => reaction.content === targetContent
3063
- );
3194
+ const botReactions = reactions.botReactions(listPayload).filter((reaction) => FEEDBACK_REACTION_CONTENTS.has(reaction.content));
3064
3195
  for (const stale of botReactions) {
3065
3196
  if (stale.content === targetContent) continue;
3066
- const deleteResponse = await githubApi(ctx.egress, {
3067
- operation: "github.pull.comment-reaction.delete",
3068
- method: "DELETE",
3069
- path: `${reactionsPath}/${stale.id}`
3070
- });
3071
- if (!deleteResponse.ok && deleteResponse.status !== 404) {
3197
+ const deleteResponse = await reactions.remove(stale);
3198
+ if (failed(deleteResponse) && deleteResponse.status !== 404) {
3072
3199
  throw new Error(
3073
3200
  `GitHub reaction removal failed with HTTP ${deleteResponse.status}: ${githubErrorMessage(deleteResponse.body)}`
3074
3201
  );
3075
3202
  }
3076
3203
  }
3077
- if (existing) {
3078
- return {
3079
- target: "updatePullRequestFeedback",
3080
- repo: repo.ref,
3081
- comment_id: commentId,
3082
- status,
3083
- reaction_id: existing.id
3084
- };
3085
- }
3086
- const createResponse = await githubApi(ctx.egress, {
3087
- operation: "github.pull.comment-reaction.create",
3088
- method: "POST",
3089
- path: reactionsPath,
3090
- body: { content: targetContent }
3091
- });
3092
- const createPayload = createResponse.body;
3093
- if (!createResponse.ok) {
3094
- throw new Error(
3095
- `GitHub reaction creation failed with HTTP ${createResponse.status}: ${githubErrorMessage(createPayload)}`
3096
- );
3204
+ if (!botReactions.some((reaction) => reaction.content === targetContent)) {
3205
+ const createResponse = await reactions.add(targetContent);
3206
+ const createPayload = createResponse.body;
3207
+ if (failed(createResponse)) {
3208
+ throw new Error(
3209
+ `GitHub reaction creation failed with HTTP ${createResponse.status}: ${githubErrorMessage(createPayload)}`
3210
+ );
3211
+ }
3097
3212
  }
3098
- const created = reactionSchema.parse(createPayload);
3099
3213
  return {
3100
3214
  target: "updatePullRequestFeedback",
3101
3215
  repo: repo.ref,
3102
3216
  comment_id: commentId,
3103
- status,
3104
- reaction_id: created.id
3217
+ status
3105
3218
  };
3106
3219
  }
3107
3220
  });
@@ -3394,7 +3507,7 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
3394
3507
 
3395
3508
  // src/webhooks/handler.ts
3396
3509
  import { createHmac, timingSafeEqual } from "crypto";
3397
- import * as z33 from "zod";
3510
+ import * as z34 from "zod";
3398
3511
 
3399
3512
  // src/issue-outcomes/store.ts
3400
3513
  import { and as and2, eq as eq2, lte, sql as sql2 } from "drizzle-orm";
@@ -4264,6 +4377,41 @@ async function markPullRequestFeedbackReviewing(env, target) {
4264
4377
  ...env,
4265
4378
  repositories: [name]
4266
4379
  });
4380
+ const content = pullRequestFeedbackReactionContent("reviewing");
4381
+ if (target.commentKind === "review_body") {
4382
+ const review = z29.object({ node_id: z29.string().min(1) }).parse(
4383
+ await githubRequest(
4384
+ "https://api.github.com",
4385
+ pullRequestReviewPath({
4386
+ owner,
4387
+ name,
4388
+ pullRequest: target.pullRequest,
4389
+ reviewId: target.commentId
4390
+ }),
4391
+ { token: token.token }
4392
+ )
4393
+ );
4394
+ const result = z29.object({ errors: z29.array(z29.unknown()).optional() }).parse(
4395
+ await githubRequest("https://api.github.com", "/graphql", {
4396
+ body: {
4397
+ operationName: "AddReviewReaction",
4398
+ query: ADD_REVIEW_REACTION_MUTATION,
4399
+ variables: {
4400
+ content: graphqlReactionContent(content),
4401
+ subjectId: review.node_id
4402
+ }
4403
+ },
4404
+ method: "POST",
4405
+ token: token.token
4406
+ })
4407
+ );
4408
+ if (result.errors?.length) {
4409
+ throw new Error(
4410
+ `GitHub review reaction failed: ${githubErrorMessage(result)}`
4411
+ );
4412
+ }
4413
+ return;
4414
+ }
4267
4415
  await githubRequest(
4268
4416
  "https://api.github.com",
4269
4417
  pullRequestCommentReactionsPath({
@@ -4273,7 +4421,7 @@ async function markPullRequestFeedbackReviewing(env, target) {
4273
4421
  commentId: target.commentId
4274
4422
  }),
4275
4423
  {
4276
- body: { content: pullRequestFeedbackReactionContent("reviewing") },
4424
+ body: { content },
4277
4425
  method: "POST",
4278
4426
  token: token.token
4279
4427
  }
@@ -4458,7 +4606,8 @@ async function syncOne(args, target) {
4458
4606
  body: `**${state.title}** is approved, and GitHub says that it can merge: ${state.url}`,
4459
4607
  dedupeKey,
4460
4608
  subject: { id: state.url, title: name, url: state.url },
4461
- title: `Ready to merge: ${name}`
4609
+ title: `Ready to merge \xB7 #${target.number}`,
4610
+ waitsOnAssignees: true
4462
4611
  });
4463
4612
  } else {
4464
4613
  await items.close({ dedupeKey, ...closeReason(state) });
@@ -4491,8 +4640,158 @@ async function syncGitHubPullRequestReadyNotices(args) {
4491
4640
  }
4492
4641
  }
4493
4642
 
4494
- // src/webhooks/pull-request-match-data.ts
4643
+ // src/webhooks/pull-request-review-request.ts
4495
4644
  import * as z31 from "zod";
4645
+ var login = z31.object({ login: z31.string().min(1) });
4646
+ var pullRequestEventSchema = z31.object({
4647
+ action: z31.enum([
4648
+ "closed",
4649
+ "reopened",
4650
+ "review_request_removed",
4651
+ "review_requested"
4652
+ ]),
4653
+ pull_request: z31.object({
4654
+ html_url: z31.string().url(),
4655
+ merged: z31.boolean().optional(),
4656
+ number: z31.number().int().positive(),
4657
+ // The people whose review is still requested. Teams are listed apart.
4658
+ requested_reviewers: z31.array(login).optional(),
4659
+ title: z31.string()
4660
+ }),
4661
+ repository: z31.object({ full_name: z31.string().min(1) }),
4662
+ // A team request has `requested_team` instead.
4663
+ requested_reviewer: login.optional()
4664
+ });
4665
+ var reviewEventSchema = z31.object({
4666
+ action: z31.literal("submitted"),
4667
+ pull_request: z31.object({ number: z31.number().int().positive() }),
4668
+ repository: z31.object({ full_name: z31.string().min(1) }),
4669
+ review: z31.object({ user: login })
4670
+ });
4671
+ function reviewRequestChange(eventName, body) {
4672
+ if (eventName === "pull_request_review") {
4673
+ const parsed2 = reviewEventSchema.safeParse(body);
4674
+ if (!parsed2.success) return void 0;
4675
+ return {
4676
+ change: {
4677
+ kind: "ended",
4678
+ reason: "The requester reviewed the pull request.",
4679
+ reviewer: parsed2.data.review.user.login,
4680
+ status: "done"
4681
+ },
4682
+ number: parsed2.data.pull_request.number,
4683
+ repository: parsed2.data.repository.full_name
4684
+ };
4685
+ }
4686
+ if (eventName !== "pull_request") return void 0;
4687
+ const parsed = pullRequestEventSchema.safeParse(body);
4688
+ if (!parsed.success) return void 0;
4689
+ const { action, pull_request: pull } = parsed.data;
4690
+ const reviewer = parsed.data.requested_reviewer?.login;
4691
+ const target = {
4692
+ number: pull.number,
4693
+ repository: parsed.data.repository.full_name
4694
+ };
4695
+ if (action === "reopened") {
4696
+ const reviewers = (pull.requested_reviewers ?? []).map(
4697
+ (person2) => person2.login
4698
+ );
4699
+ if (reviewers.length === 0) return void 0;
4700
+ return {
4701
+ ...target,
4702
+ change: {
4703
+ kind: "requested",
4704
+ reviewers,
4705
+ title: pull.title,
4706
+ url: pull.html_url
4707
+ }
4708
+ };
4709
+ }
4710
+ if (action !== "closed" && !reviewer) {
4711
+ return void 0;
4712
+ }
4713
+ if (action === "review_requested" && reviewer) {
4714
+ return {
4715
+ ...target,
4716
+ change: {
4717
+ kind: "requested",
4718
+ reviewers: [reviewer],
4719
+ title: pull.title,
4720
+ url: pull.html_url
4721
+ }
4722
+ };
4723
+ }
4724
+ if (action === "review_request_removed") {
4725
+ return {
4726
+ ...target,
4727
+ change: {
4728
+ kind: "ended",
4729
+ reason: "The review request was removed.",
4730
+ reviewer,
4731
+ status: "dismissed"
4732
+ }
4733
+ };
4734
+ }
4735
+ return {
4736
+ ...target,
4737
+ change: pull.merged ? { kind: "ended", reason: "The pull request merged.", status: "done" } : {
4738
+ kind: "ended",
4739
+ reason: "The pull request closed without merging.",
4740
+ status: "dismissed"
4741
+ }
4742
+ };
4743
+ }
4744
+ function sameLogin(left, right) {
4745
+ return left.toLowerCase() === right.toLowerCase();
4746
+ }
4747
+ async function syncGitHubPullRequestReviewRequest(args) {
4748
+ const parsed = reviewRequestChange(args.eventName, args.body);
4749
+ if (!parsed) return;
4750
+ const { change, number: number27, repository: repository2 } = parsed;
4751
+ try {
4752
+ const opener = (await listGitHubPullRequestOpeners(args.db, {
4753
+ numbers: [number27],
4754
+ repositoryFullName: repository2
4755
+ })).get(number27);
4756
+ if (!opener?.conversationId) return;
4757
+ const name = `${repository2}#${number27}`;
4758
+ const dedupeKey = `pull-request-review-requested:${name.toLowerCase()}`;
4759
+ const items = args.reviewItems.forConversation(opener.conversationId);
4760
+ const reviewers = change.kind === "requested" ? change.reviewers : change.reviewer === void 0 ? void 0 : [change.reviewer];
4761
+ if (reviewers !== void 0) {
4762
+ const requesterLogin = await args.loadGitHubLogin?.(opener.identityId);
4763
+ if (!requesterLogin || !reviewers.some((reviewer) => sameLogin(reviewer, requesterLogin))) {
4764
+ return;
4765
+ }
4766
+ }
4767
+ if (change.kind === "ended") {
4768
+ await items.close({
4769
+ dedupeKey,
4770
+ reason: change.reason,
4771
+ status: change.status
4772
+ });
4773
+ return;
4774
+ }
4775
+ await items.upsert({
4776
+ assigneeIdentityIds: [opener.identityId],
4777
+ body: `GitHub asks you to review **${change.title}**: ${change.url}`,
4778
+ dedupeKey,
4779
+ subject: { id: change.url, title: name, url: change.url },
4780
+ title: `Review requested \xB7 #${number27}`,
4781
+ waitsOnAssignees: true
4782
+ });
4783
+ } catch (error) {
4784
+ args.log?.error("GitHub pull request review request failed", {
4785
+ deliveryId: args.deliveryId,
4786
+ errorType: error instanceof Error ? error.name : "UnknownError",
4787
+ number: number27,
4788
+ repository: repository2
4789
+ });
4790
+ }
4791
+ }
4792
+
4793
+ // src/webhooks/pull-request-match-data.ts
4794
+ import * as z32 from "zod";
4496
4795
  var LOOKUPS_BY_MATCH_KEY = {
4497
4796
  authors: ["authors"],
4498
4797
  openerEmail: ["opener"],
@@ -4500,22 +4799,22 @@ var LOOKUPS_BY_MATCH_KEY = {
4500
4799
  openerUsername: ["opener"]
4501
4800
  };
4502
4801
  var ALL_LOOKUPS = ["authors", "opener", "openerRole"];
4503
- var lookupDataSchema = z31.object({
4504
- authors: z31.array(z31.string().min(1)).min(1).optional(),
4505
- openerRole: z31.string().min(1).optional(),
4506
- openerUsername: z31.string().min(1).optional()
4802
+ var lookupDataSchema = z32.object({
4803
+ authors: z32.array(z32.string().min(1)).min(1).optional(),
4804
+ openerRole: z32.string().min(1).optional(),
4805
+ openerUsername: z32.string().min(1).optional()
4507
4806
  }).strict();
4508
4807
  function lookupData(input) {
4509
4808
  return lookupDataSchema.parse(definedValues(input));
4510
4809
  }
4511
- var webhookSchema = z31.object({
4512
- repository: z31.object({ full_name: z31.string().min(1) })
4810
+ var webhookSchema = z32.object({
4811
+ repository: z32.object({ full_name: z32.string().min(1) })
4513
4812
  });
4514
4813
  function pullRequestNumbers(events) {
4515
4814
  const numbers = /* @__PURE__ */ new Map();
4516
4815
  for (const event of events) {
4517
- const number26 = event.data?.pullRequest;
4518
- if (typeof number26 === "number") numbers.set(event.eventKey, number26);
4816
+ const number27 = event.data?.pullRequest;
4817
+ if (typeof number27 === "number") numbers.set(event.eventKey, number27);
4519
4818
  }
4520
4819
  return numbers;
4521
4820
  }
@@ -4529,8 +4828,8 @@ function logFailure(context, lookup, error) {
4529
4828
  }
4530
4829
  async function withJuniorOpeners(context, events) {
4531
4830
  const botNumber = (event) => {
4532
- const number26 = context.numbers.get(event.eventKey);
4533
- return number26 !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number26 : void 0;
4831
+ const number27 = context.numbers.get(event.eventKey);
4832
+ return number27 !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number27 : void 0;
4534
4833
  };
4535
4834
  const numbers = events.flatMap((event) => botNumber(event) ?? []);
4536
4835
  if (numbers.length === 0) return events;
@@ -4549,10 +4848,10 @@ async function withJuniorOpeners(context, events) {
4549
4848
  }
4550
4849
  }
4551
4850
  return events.map((event) => {
4552
- const number26 = botNumber(event);
4553
- if (number26 === void 0) return event;
4554
- const identityId = openers.get(number26)?.identityId;
4555
- const login = identityId ? logins.get(identityId) : void 0;
4851
+ const number27 = botNumber(event);
4852
+ if (number27 === void 0) return event;
4853
+ const identityId = openers.get(number27)?.identityId;
4854
+ const login2 = identityId ? logins.get(identityId) : void 0;
4556
4855
  const {
4557
4856
  openerEmail: _email,
4558
4857
  openerUsername: _login,
@@ -4560,7 +4859,7 @@ async function withJuniorOpeners(context, events) {
4560
4859
  } = event.data ?? {};
4561
4860
  return {
4562
4861
  ...event,
4563
- data: { ...data, ...lookupData({ openerUsername: login || void 0 }) }
4862
+ data: { ...data, ...lookupData({ openerUsername: login2 || void 0 }) }
4564
4863
  };
4565
4864
  });
4566
4865
  }
@@ -4573,27 +4872,27 @@ async function withRolesAndAuthors(context, events, lookups) {
4573
4872
  if (!loadRole && !loadAuthors) return events;
4574
4873
  return await Promise.all(
4575
4874
  events.map(async (event) => {
4576
- const number26 = context.numbers.get(event.eventKey);
4577
- if (number26 === void 0) return event;
4578
- const login = event.data?.openerUsername;
4579
- if (loadRole && typeof login === "string" && !roles.has(login)) {
4875
+ const number27 = context.numbers.get(event.eventKey);
4876
+ if (number27 === void 0) return event;
4877
+ const login2 = event.data?.openerUsername;
4878
+ if (loadRole && typeof login2 === "string" && !roles.has(login2)) {
4580
4879
  roles.set(
4581
- login,
4582
- loadRole({ login, repositoryFullName }).catch(
4880
+ login2,
4881
+ loadRole({ login: login2, repositoryFullName }).catch(
4583
4882
  (error) => logFailure(context, "role", error)
4584
4883
  )
4585
4884
  );
4586
4885
  }
4587
- if (loadAuthors && !authors.has(number26)) {
4886
+ if (loadAuthors && !authors.has(number27)) {
4588
4887
  authors.set(
4589
- number26,
4590
- loadAuthors({ number: number26, repositoryFullName }).catch(
4888
+ number27,
4889
+ loadAuthors({ number: number27, repositoryFullName }).catch(
4591
4890
  (error) => logFailure(context, "authors", error)
4592
4891
  )
4593
4892
  );
4594
4893
  }
4595
- const role = loadRole && typeof login === "string" ? await roles.get(login) : void 0;
4596
- const logins = loadAuthors ? await authors.get(number26) : void 0;
4894
+ const role = loadRole && typeof login2 === "string" ? await roles.get(login2) : void 0;
4895
+ const logins = loadAuthors ? await authors.get(number27) : void 0;
4597
4896
  if (!role && !logins?.length) return event;
4598
4897
  return {
4599
4898
  ...event,
@@ -4650,7 +4949,7 @@ async function withGitHubPullRequestMatchData(args) {
4650
4949
  }
4651
4950
 
4652
4951
  // src/webhooks/pull-request-people.ts
4653
- import * as z32 from "zod";
4952
+ import * as z33 from "zod";
4654
4953
  var PEOPLE_EVENTS = /* @__PURE__ */ new Set([
4655
4954
  "pull_request.review.approved",
4656
4955
  "pull_request.merged"
@@ -4660,18 +4959,18 @@ var PAGE_SIZE = 100;
4660
4959
  var MAX_PAGES = 3;
4661
4960
  var CO_AUTHOR_TRAILER = /^co-authored-by:[^<\n]*<([^>\s]+@[^>\s]+)>\s*$/gim;
4662
4961
  var GITHUB_NOREPLY_EMAIL = /^(?:\d+\+)?(?<login>[^@+]+)@users\.noreply\.github\.com$/i;
4663
- var webhookSchema2 = z32.object({
4664
- pull_request: z32.object({
4665
- assignees: z32.array(z32.object({ login: z32.string().min(1) })).nullish(),
4666
- number: z32.number(),
4667
- user: z32.object({ login: z32.string().min(1) }).nullish()
4962
+ var webhookSchema2 = z33.object({
4963
+ pull_request: z33.object({
4964
+ assignees: z33.array(z33.object({ login: z33.string().min(1) })).nullish(),
4965
+ number: z33.number(),
4966
+ user: z33.object({ login: z33.string().min(1) }).nullish()
4668
4967
  }),
4669
- repository: z32.object({ full_name: z32.string().min(1) })
4968
+ repository: z33.object({ full_name: z33.string().min(1) })
4670
4969
  });
4671
- var commitPageSchema = z32.array(
4672
- z32.object({
4673
- author: z32.object({ login: z32.string().min(1) }).nullish(),
4674
- commit: z32.object({ message: z32.string() })
4970
+ var commitPageSchema = z33.array(
4971
+ z33.object({
4972
+ author: z33.object({ login: z33.string().min(1) }).nullish(),
4973
+ commit: z33.object({ message: z33.string() })
4675
4974
  })
4676
4975
  );
4677
4976
  function shareCommitPages(load) {
@@ -4712,15 +5011,15 @@ function noreplyLogin(email) {
4712
5011
  }
4713
5012
  async function loadGitHubPullRequestPeople(args) {
4714
5013
  const people = /* @__PURE__ */ new Map();
4715
- const addLogin = (login) => {
4716
- if (/\[bot\]$/i.test(login)) return;
4717
- const key = `github:${login.toLowerCase()}`;
5014
+ const addLogin = (login2) => {
5015
+ if (/\[bot\]$/i.test(login2)) return;
5016
+ const key = `github:${login2.toLowerCase()}`;
4718
5017
  if (!people.has(key))
4719
- people.set(key, { provider: "github", handle: login });
5018
+ people.set(key, { provider: "github", handle: login2 });
4720
5019
  };
4721
5020
  const addEmail = (value) => {
4722
- const login = noreplyLogin(value);
4723
- if (login) return addLogin(login);
5021
+ const login2 = noreplyLogin(value);
5022
+ if (login2) return addLogin(login2);
4724
5023
  const email = value.toLowerCase();
4725
5024
  if (!people.has(`email:${email}`)) {
4726
5025
  people.set(`email:${email}`, { email });
@@ -4735,9 +5034,9 @@ async function loadGitHubPullRequestPeople(args) {
4735
5034
  }
4736
5035
  async function loadGitHubPullRequestAuthors(args) {
4737
5036
  const authors = /* @__PURE__ */ new Map();
4738
- const add = (login) => {
4739
- if (login && !authors.has(login.toLowerCase())) {
4740
- authors.set(login.toLowerCase(), login);
5037
+ const add = (login2) => {
5038
+ if (login2 && !authors.has(login2.toLowerCase())) {
5039
+ authors.set(login2.toLowerCase(), login2);
4741
5040
  }
4742
5041
  };
4743
5042
  await forEachCommit(args.loadPage, (commit) => {
@@ -4813,17 +5112,19 @@ function webhookInstallationId(body) {
4813
5112
  }
4814
5113
  return parseInstallationId(installation.id);
4815
5114
  }
4816
- var feedbackTargetSchema = z33.object({
4817
- commentId: z33.number(),
4818
- commentKind: z33.enum(["conversation", "review"]),
4819
- repo: z33.string().min(1)
5115
+ var feedbackTargetSchema = z34.object({
5116
+ commentId: z34.number(),
5117
+ commentKind: z34.enum(["conversation", "review", "review_body"]),
5118
+ pullRequest: z34.number(),
5119
+ repo: z34.string().min(1)
4820
5120
  });
4821
5121
  function pullRequestFeedbackTarget(events) {
4822
- const event = events.find(
4823
- (candidate) => candidate.eventType === "pull_request.comment.created" || candidate.eventType === "pull_request.review_comment.created"
4824
- );
4825
- const parsed = feedbackTargetSchema.safeParse(event?.data);
4826
- return parsed.success ? parsed.data : void 0;
5122
+ for (const event of events) {
5123
+ if (!event.eventType.startsWith("pull_request.")) continue;
5124
+ const parsed = feedbackTargetSchema.safeParse(event.data);
5125
+ if (parsed.success) return parsed.data;
5126
+ }
5127
+ return void 0;
4827
5128
  }
4828
5129
  function githubCodeChange(outcome, conversationIds) {
4829
5130
  return {
@@ -5064,6 +5365,15 @@ function createGitHubWebhookRoute(args) {
5064
5365
  reviewItems: args.reviewItems,
5065
5366
  targets: pullRequestReadyTargets(eventName, body)
5066
5367
  });
5368
+ await syncGitHubPullRequestReviewRequest({
5369
+ body,
5370
+ db: args.db,
5371
+ deliveryId,
5372
+ eventName,
5373
+ loadGitHubLogin: args.loadGitHubLogin,
5374
+ log: args.log,
5375
+ reviewItems: args.reviewItems
5376
+ });
5067
5377
  if (!pullRequestOutcome && !issueOutcome && !recordedIssueConversations && !recordedPullRequestConversations && !recordedPullRequestLinkedIssues && events.length === 0) {
5068
5378
  return new Response("Ignored", { status: 202 });
5069
5379
  }
@@ -5073,36 +5383,36 @@ function createGitHubWebhookRoute(args) {
5073
5383
  }
5074
5384
 
5075
5385
  // src/merge-conflict-checks/heartbeat.ts
5076
- import * as z34 from "zod";
5386
+ import * as z35 from "zod";
5077
5387
  var CHECK_LIMIT = 10;
5078
5388
  var MAX_PAGES2 = 5;
5079
5389
  var CLAIM_MS = 5 * 6e4;
5080
5390
  var UNKNOWN_RETRY_MS = 6e4;
5081
5391
  var MAX_ATTEMPTS = 5;
5082
- var searchNodeSchema = z34.union([
5083
- z34.object({
5084
- baseRefName: z34.string().min(1),
5085
- headRefOid: z34.string().min(1),
5086
- mergeable: z34.enum(["CONFLICTING", "MERGEABLE", "UNKNOWN"]),
5087
- number: z34.number().int().positive(),
5088
- state: z34.string(),
5089
- url: z34.string().min(1)
5392
+ var searchNodeSchema = z35.union([
5393
+ z35.object({
5394
+ baseRefName: z35.string().min(1),
5395
+ headRefOid: z35.string().min(1),
5396
+ mergeable: z35.enum(["CONFLICTING", "MERGEABLE", "UNKNOWN"]),
5397
+ number: z35.number().int().positive(),
5398
+ state: z35.string(),
5399
+ url: z35.string().min(1)
5090
5400
  }),
5091
- z34.object({}).strict()
5401
+ z35.object({}).strict()
5092
5402
  ]);
5093
- var searchResponseSchema = z34.object({
5094
- data: z34.object({
5095
- search: z34.object({
5096
- nodes: z34.array(searchNodeSchema.nullable()),
5097
- pageInfo: z34.object({
5098
- endCursor: z34.string().nullable(),
5099
- hasNextPage: z34.boolean()
5403
+ var searchResponseSchema = z35.object({
5404
+ data: z35.object({
5405
+ search: z35.object({
5406
+ nodes: z35.array(searchNodeSchema.nullable()),
5407
+ pageInfo: z35.object({
5408
+ endCursor: z35.string().nullable(),
5409
+ hasNextPage: z35.boolean()
5100
5410
  })
5101
5411
  })
5102
5412
  })
5103
5413
  });
5104
5414
  async function checkRepository(args, repositoryFullName) {
5105
- let unknown2 = false;
5415
+ let unknown3 = false;
5106
5416
  let after;
5107
5417
  for (let page = 0; page < MAX_PAGES2; page += 1) {
5108
5418
  const { search } = searchResponseSchema.parse(
@@ -5110,7 +5420,7 @@ async function checkRepository(args, repositoryFullName) {
5110
5420
  ).data;
5111
5421
  for (const node of search.nodes) {
5112
5422
  if (!node || !("number" in node) || node.state !== "OPEN") continue;
5113
- if (node.mergeable === "UNKNOWN") unknown2 = true;
5423
+ if (node.mergeable === "UNKNOWN") unknown3 = true;
5114
5424
  if (node.mergeable !== "CONFLICTING") continue;
5115
5425
  const events = gitHubMergeConflictEvents({
5116
5426
  conflict: {
@@ -5127,12 +5437,12 @@ async function checkRepository(args, repositoryFullName) {
5127
5437
  if (!search.pageInfo.hasNextPage || !search.pageInfo.endCursor) break;
5128
5438
  after = search.pageInfo.endCursor;
5129
5439
  }
5130
- return unknown2;
5440
+ return unknown3;
5131
5441
  }
5132
5442
  async function runCheck(args, check) {
5133
- let unknown2;
5443
+ let unknown3;
5134
5444
  try {
5135
- unknown2 = await checkRepository(args, check.repositoryFullName);
5445
+ unknown3 = await checkRepository(args, check.repositoryFullName);
5136
5446
  } catch (error) {
5137
5447
  args.log.error("GitHub merge conflict check failed", {
5138
5448
  attempts: check.attempts,
@@ -5147,7 +5457,7 @@ async function runCheck(args, check) {
5147
5457
  await settleGitHubConflictCheck(
5148
5458
  args.state,
5149
5459
  check,
5150
- unknown2 && check.attempts < MAX_ATTEMPTS ? args.now.getTime() + UNKNOWN_RETRY_MS : void 0
5460
+ unknown3 && check.attempts < MAX_ATTEMPTS ? args.now.getTime() + UNKNOWN_RETRY_MS : void 0
5151
5461
  );
5152
5462
  }
5153
5463
  async function runGitHubConflictChecks(args) {
@@ -5193,30 +5503,30 @@ function gitHubResourceUrl(input) {
5193
5503
  if (input.resourceType === "repository") {
5194
5504
  return `https://github.com/${input.identifier}`;
5195
5505
  }
5196
- const [repo, number26] = input.identifier.split("#");
5197
- if (!repo || !number26) return void 0;
5506
+ const [repo, number27] = input.identifier.split("#");
5507
+ if (!repo || !number27) return void 0;
5198
5508
  if (input.resourceType === "pull_request") {
5199
- return `https://github.com/${repo}/pull/${number26}`;
5509
+ return `https://github.com/${repo}/pull/${number27}`;
5200
5510
  }
5201
5511
  if (input.resourceType === "issue") {
5202
- return `https://github.com/${repo}/issues/${number26}`;
5512
+ return `https://github.com/${repo}/issues/${number27}`;
5203
5513
  }
5204
5514
  return void 0;
5205
5515
  }
5206
5516
 
5207
5517
  // src/pull-request-outcomes/commit-composition.ts
5208
- import * as z35 from "zod";
5209
- var canonicalCommitSchema = z35.object({
5210
- authorEmail: z35.string().nullable(),
5211
- authorLogin: z35.string().nullable()
5518
+ import * as z36 from "zod";
5519
+ var canonicalCommitSchema = z36.object({
5520
+ authorEmail: z36.string().nullable(),
5521
+ authorLogin: z36.string().nullable()
5212
5522
  }).strict();
5213
- var providerCommitSchema = z35.object({
5214
- author: z35.object({ login: z35.string() }).passthrough().nullable(),
5215
- commit: z35.object({
5216
- author: z35.object({ email: z35.string() }).passthrough().nullable()
5523
+ var providerCommitSchema = z36.object({
5524
+ author: z36.object({ login: z36.string() }).passthrough().nullable(),
5525
+ commit: z36.object({
5526
+ author: z36.object({ email: z36.string() }).passthrough().nullable()
5217
5527
  }).passthrough()
5218
5528
  }).passthrough();
5219
- var commitPageSchema2 = z35.array(providerCommitSchema).transform(
5529
+ var commitPageSchema2 = z36.array(providerCommitSchema).transform(
5220
5530
  (commits) => commits.map(
5221
5531
  (commit) => canonicalCommitSchema.parse({
5222
5532
  authorEmail: commit.commit.author?.email ?? null,
@@ -5290,15 +5600,15 @@ function githubNoreplyEmail(user) {
5290
5600
  if (identity.provider !== "github") {
5291
5601
  continue;
5292
5602
  }
5293
- const login = cleanIdentityPart(identity.handle);
5603
+ const login2 = cleanIdentityPart(identity.handle);
5294
5604
  const userId = cleanIdentityPart(identity.providerSubjectId);
5295
- if (!login || login.toLowerCase().endsWith("[bot]")) {
5605
+ if (!login2 || login2.toLowerCase().endsWith("[bot]")) {
5296
5606
  continue;
5297
5607
  }
5298
5608
  if (/^[1-9]\d*$/.test(userId)) {
5299
- return `${userId}+${login}@users.noreply.github.com`;
5609
+ return `${userId}+${login2}@users.noreply.github.com`;
5300
5610
  }
5301
- return `${login}@users.noreply.github.com`;
5611
+ return `${login2}@users.noreply.github.com`;
5302
5612
  }
5303
5613
  return void 0;
5304
5614
  }
@@ -5723,8 +6033,8 @@ function linkifyLine(line) {
5723
6033
  if (isReferenceBoundary(index2 === 0 ? void 0 : line[index2 - 1])) {
5724
6034
  const match = GITHUB_ISSUE_REFERENCE_PATTERN.exec(line.slice(index2));
5725
6035
  if (match) {
5726
- const [reference, owner, repository2, number26] = match;
5727
- output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number26})`;
6036
+ const [reference, owner, repository2, number27] = match;
6037
+ output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number27})`;
5728
6038
  index2 += reference.length;
5729
6039
  continue;
5730
6040
  }
@@ -5866,9 +6176,9 @@ function parseGitHubReferences(text2, config) {
5866
6176
  }
5867
6177
  return [...references.values()];
5868
6178
  }
5869
- function objectTitle(kind, object35) {
5870
- if (!isRecord(object35)) return void 0;
5871
- const raw = kind === "commit" ? isRecord(object35.commit) && typeof object35.commit.message === "string" ? object35.commit.message.split("\n")[0] : void 0 : typeof object35.title === "string" ? object35.title : void 0;
6179
+ function objectTitle(kind, object37) {
6180
+ if (!isRecord(object37)) return void 0;
6181
+ const raw = kind === "commit" ? isRecord(object37.commit) && typeof object37.commit.message === "string" ? object37.commit.message.split("\n")[0] : void 0 : typeof object37.title === "string" ? object37.title : void 0;
5872
6182
  return raw?.replace(/\s+/g, " ").trim() || void 0;
5873
6183
  }
5874
6184
  async function loadGitHubConversationTitleContext(args) {
@@ -6083,7 +6393,7 @@ function isGitHubRemote(arg) {
6083
6393
 
6084
6394
  // src/egress-policy.ts
6085
6395
  import {
6086
- EgressPolicyDenied as EgressPolicyDenied2,
6396
+ EgressPolicyDenied as EgressPolicyDenied3,
6087
6397
  enforceEgressPolicy
6088
6398
  } from "@sentry/junior-plugin-api";
6089
6399
 
@@ -6141,6 +6451,98 @@ function assertGitHubPullRequestApprovalDenied(input) {
6141
6451
  }
6142
6452
  }
6143
6453
 
6454
+ // src/receive-pack-policy.ts
6455
+ import {
6456
+ EgressPolicyDenied as EgressPolicyDenied2
6457
+ } from "@sentry/junior-plugin-api";
6458
+
6459
+ // src/default-branch.ts
6460
+ import * as z37 from "zod";
6461
+ var DEFAULT_BRANCH_TTL_MS = 10 * 60 * 1e3;
6462
+ var repositorySchema2 = z37.object({ default_branch: z37.string().min(1) });
6463
+ async function loadDefaultBranch(env, cache, repository2) {
6464
+ const { owner, name } = repository2;
6465
+ return await cache.getOrLoad(
6466
+ `default-branch:${owner}/${name}`.toLowerCase(),
6467
+ async () => {
6468
+ const token = await issueInstallationToken({
6469
+ ...env,
6470
+ permissions: { metadata: "read" },
6471
+ repositories: [name]
6472
+ });
6473
+ const response = repositorySchema2.parse(
6474
+ await githubRequest(
6475
+ "https://api.github.com",
6476
+ `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`,
6477
+ { token: token.token }
6478
+ )
6479
+ );
6480
+ return { value: response.default_branch, ttlMs: DEFAULT_BRANCH_TTL_MS };
6481
+ }
6482
+ );
6483
+ }
6484
+
6485
+ // src/receive-pack-policy.ts
6486
+ var DENIAL_SUFFIX = "This is a runtime policy denial, not a GitHub permission failure. Push to a new branch and open a pull request with github_createPullRequest.";
6487
+ var UNREADABLE_MESSAGES = {
6488
+ gzip: "The runtime cannot read a gzip-compressed Git push.",
6489
+ malformed: "The runtime could not read the Git push command list.",
6490
+ signed: "The runtime does not accept signed Git pushes.",
6491
+ unterminated: "The runtime could not find the end of the Git push command list."
6492
+ };
6493
+ function deny(message, options) {
6494
+ throw new EgressPolicyDenied2(`${message} ${DENIAL_SUFFIX}`, options);
6495
+ }
6496
+ async function assertGitHubPushAllowed(input) {
6497
+ if (!input.gitPush) {
6498
+ deny(UNREADABLE_MESSAGES.malformed);
6499
+ }
6500
+ if (input.gitPush.kind === "unreadable") {
6501
+ deny(UNREADABLE_MESSAGES[input.gitPush.reason]);
6502
+ }
6503
+ const { updates } = input.gitPush;
6504
+ const refs = updates.map((update) => update.ref);
6505
+ const outsideBranches = refs.filter((ref) => !ref.startsWith("refs/heads/"));
6506
+ if (outsideBranches.length > 0) {
6507
+ deny(
6508
+ `The runtime pushes only branches. It refused ${outsideBranches.join(", ")}.`,
6509
+ { auditAttributes: { "app.github.refs": refs } }
6510
+ );
6511
+ }
6512
+ if (updates.length === 0) {
6513
+ return { "app.github.refs": refs };
6514
+ }
6515
+ let defaultBranch;
6516
+ try {
6517
+ defaultBranch = await loadDefaultBranch(
6518
+ input.env,
6519
+ input.cache,
6520
+ input.repository
6521
+ );
6522
+ } catch (error) {
6523
+ deny(
6524
+ `The runtime could not read the default branch of ${input.repository.owner}/${input.repository.name}, so it refused the push.`,
6525
+ { auditAttributes: { "app.github.refs": refs }, cause: error }
6526
+ );
6527
+ }
6528
+ const defaultRef = `refs/heads/${defaultBranch}`.toLowerCase();
6529
+ const defaultUpdate = updates.find(
6530
+ (update) => update.ref.toLowerCase() === defaultRef
6531
+ );
6532
+ const attributes = {
6533
+ "app.github.default_branch": defaultBranch,
6534
+ "app.github.default_branch_targeted": defaultUpdate !== void 0,
6535
+ "app.github.refs": refs
6536
+ };
6537
+ if (defaultUpdate) {
6538
+ deny(
6539
+ `The runtime never ${defaultUpdate.deletes ? "deletes" : "pushes to"} the default branch (${defaultBranch}) of ${input.repository.owner}/${input.repository.name}.`,
6540
+ { auditAttributes: attributes }
6541
+ );
6542
+ }
6543
+ return attributes;
6544
+ }
6545
+
6144
6546
  // src/egress-policy.ts
6145
6547
  function githubSmartHttpAccess(upstreamUrl) {
6146
6548
  const pathname = upstreamUrl.pathname.toLowerCase();
@@ -6172,86 +6574,17 @@ function githubUserReadReason(method, upstreamUrl) {
6172
6574
  }
6173
6575
  return upstreamUrl.pathname.toLowerCase() === "/user" ? "github.user-read" : void 0;
6174
6576
  }
6175
- function parseGitHubGraphqlOperation(bodyText) {
6176
- const parsed = parseGitHubGraphqlRequest(bodyText);
6177
- if (!parsed) {
6178
- return void 0;
6179
- }
6180
- const { normalized, operationName } = parsed;
6181
- if (operationName) {
6182
- const namedOperation = normalized.match(
6183
- new RegExp(
6184
- `\\b(query|mutation|subscription)\\s+${escapeRegExp2(operationName)}\\b`
6185
- )
6186
- )?.[1];
6187
- return namedOperation ? graphqlOperationAccess(namedOperation) : void 0;
6188
- }
6189
- const operation = normalized.match(/\b(query|mutation|subscription)\b/)?.[1];
6190
- const operationAccess = graphqlOperationAccess(operation);
6191
- if (operationAccess) {
6192
- return operationAccess;
6193
- }
6194
- if (normalized.startsWith("{")) {
6195
- return "read";
6196
- }
6197
- return void 0;
6198
- }
6199
- function parseGitHubGraphqlRequest(bodyText) {
6200
- if (typeof bodyText !== "string" || bodyText.trim().length === 0) {
6201
- return void 0;
6202
- }
6203
- let parsed;
6204
- try {
6205
- parsed = JSON.parse(bodyText);
6206
- } catch {
6207
- return void 0;
6208
- }
6209
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
6210
- return void 0;
6211
- }
6212
- const query = parsed.query;
6213
- if (typeof query !== "string") {
6214
- return void 0;
6215
- }
6216
- const operationName = typeof parsed.operationName === "string" ? parsed.operationName.trim() : void 0;
6217
- const normalized = maskGraphqlStringLiterals(
6218
- query.replace(/^\s*#[^\n\r]*(?:\r?\n|$)/gm, "")
6219
- ).trim();
6220
- return {
6221
- normalized,
6222
- ...operationName ? { operationName } : void 0
6223
- };
6224
- }
6225
- function escapeRegExp2(value) {
6226
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
6227
- }
6228
- function graphqlOperationAccess(operation) {
6229
- if (operation === "mutation" || operation === "subscription") {
6230
- return "write";
6231
- }
6232
- if (operation === "query") {
6233
- return "read";
6234
- }
6235
- return void 0;
6236
- }
6237
- function maskGraphqlStringLiterals(query) {
6238
- return query.replace(
6239
- /"""[\s\S]*?"""|"(?:\\.|[^"\\])*"/g,
6240
- (match) => " ".repeat(match.length)
6241
- );
6577
+ function githubGraphqlOperation(graphql) {
6578
+ return graphql?.kind === "operation" ? graphql.operation : void 0;
6242
6579
  }
6243
- function githubGraphqlAccess(method, upstreamUrl, bodyText) {
6580
+ function githubGraphqlAccess(method, upstreamUrl, graphql) {
6244
6581
  if (!isGitHubGraphqlUrl(upstreamUrl)) {
6245
6582
  return void 0;
6246
6583
  }
6247
6584
  if (HTTP_READ_METHODS.has(method)) {
6248
6585
  return "read";
6249
6586
  }
6250
- const operation = parseGitHubGraphqlOperation(bodyText);
6251
- if (operation) {
6252
- return operation;
6253
- }
6254
- return "write";
6587
+ return githubGraphqlOperation(graphql)?.type === "query" ? "read" : "write";
6255
6588
  }
6256
6589
  function githubGraphqlPermissionDeniedMessage(bodyText) {
6257
6590
  let parsed;
@@ -6341,8 +6674,10 @@ var ISSUE_PATH = /^\/repos\/[^/]+\/[^/]+\/issues\/\d+$/;
6341
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}`;
6342
6675
  function isGitHubIssueRead(input) {
6343
6676
  if (isGitHubGraphqlUrl(input.upstreamUrl)) {
6344
- const parsed = parseGitHubGraphqlRequest(input.bodyText);
6345
- 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;
6346
6681
  }
6347
6682
  return isGitHubApiUrl(input.upstreamUrl) && HTTP_READ_METHODS.has(input.method) && ISSUE_PATH.test(input.upstreamUrl.pathname.toLowerCase());
6348
6683
  }
@@ -6458,34 +6793,42 @@ var HOST_GRAPHQL_MUTATIONS = [
6458
6793
  field: "convertPullRequestToDraft",
6459
6794
  operationName: "ConvertPullRequestToDraft",
6460
6795
  operationPrefix: "github.pull.draft.update:"
6796
+ },
6797
+ // Feedback-status reactions on review bodies, which have no REST endpoint.
6798
+ {
6799
+ field: "addReaction",
6800
+ operationName: "AddReviewReaction",
6801
+ operationPrefix: "github.pull.review-reaction.update:"
6802
+ },
6803
+ {
6804
+ field: "removeReaction",
6805
+ operationName: "RemoveReviewReaction",
6806
+ operationPrefix: "github.pull.review-reaction.update:"
6461
6807
  }
6462
6808
  ];
6463
- function hostGraphqlMutationRepository(operation, method, upstreamUrl, bodyText) {
6809
+ function hostGraphqlMutationRepository(operation, method, upstreamUrl, graphql) {
6464
6810
  if (method !== "POST" || !isGitHubGraphqlUrl(upstreamUrl) || !operation) {
6465
6811
  return void 0;
6466
6812
  }
6467
- const parsed = parseGitHubGraphqlRequest(bodyText);
6813
+ const parsed = githubGraphqlOperation(graphql);
6468
6814
  const mutation = HOST_GRAPHQL_MUTATIONS.find(
6469
- (candidate) => operation.startsWith(candidate.operationPrefix) && parsed?.operationName === candidate.operationName && new RegExp(`\\bmutation\\s+${candidate.operationName}\\b`).test(
6470
- parsed.normalized
6471
- ) && 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
6472
6816
  );
6473
6817
  if (!mutation) return void 0;
6474
6818
  const repository2 = operation.slice(mutation.operationPrefix.length);
6475
6819
  return /^[^/]+\/[^/]+$/.test(repository2) ? repository2 : void 0;
6476
6820
  }
6477
- function isGitHubGraphqlMutation(method, upstreamUrl, bodyText, field) {
6821
+ function isGitHubGraphqlMutation(method, upstreamUrl, graphql, field) {
6478
6822
  if (method !== "POST" || !isGitHubGraphqlUrl(upstreamUrl)) return false;
6479
- const parsed = parseGitHubGraphqlRequest(bodyText);
6480
- if (!parsed || !new RegExp(`\\b${field}\\b`).test(parsed.normalized)) {
6481
- return false;
6482
- }
6483
- if (!parsed.operationName) return /\bmutation\b/.test(parsed.normalized);
6484
- return new RegExp(
6485
- `\\bmutation\\s+${escapeRegExp2(parsed.operationName)}\\b`
6486
- ).test(parsed.normalized);
6823
+ const parsed = githubGraphqlOperation(graphql);
6824
+ return parsed?.type === "mutation" && parsed.rootFields.includes(field);
6487
6825
  }
6488
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
+ }
6489
6832
  const reactionWrite = isGitHubApiUrl(input.upstreamUrl) && (input.method === "POST" || input.method === "DELETE") && PULL_REQUEST_COMMENT_REACTIONS_PATH.test(
6490
6833
  input.upstreamUrl.pathname.toLowerCase()
6491
6834
  );
@@ -6512,7 +6855,7 @@ function applyGitHubEgressPolicy(input) {
6512
6855
  (candidate) => candidate.method === input.method && isGitHubApiUrl(input.upstreamUrl) && candidate.restPath.test(pathname) || isGitHubGraphqlMutation(
6513
6856
  input.method,
6514
6857
  input.upstreamUrl,
6515
- input.bodyText,
6858
+ input.graphql,
6516
6859
  candidate.graphqlField
6517
6860
  )
6518
6861
  );
@@ -6531,18 +6874,31 @@ function grantForAccess(access, reason, name) {
6531
6874
  };
6532
6875
  }
6533
6876
  function requireRepositoryTarget(upstreamUrl) {
6534
- if (githubRepositoryFromUrl(upstreamUrl)) {
6535
- return;
6877
+ const repository2 = githubRepositoryFromUrl(upstreamUrl);
6878
+ if (repository2) {
6879
+ return repository2;
6536
6880
  }
6537
- throw new EgressPolicyDenied2(
6881
+ throw new EgressPolicyDenied3(
6538
6882
  "GitHub write request has no repository in its URL. Use a /repos/{owner}/{repo}/... URL or a GitHub tool for the operation."
6539
6883
  );
6540
6884
  }
6541
- async function githubGrantForEgress(ctx) {
6542
- const method = ctx.request.method.toUpperCase();
6885
+ async function githubGrantForEgress(ctx, env) {
6543
6886
  const upstreamUrl = new URL(ctx.request.url);
6887
+ const grant = await selectGitHubGrant(ctx, env, upstreamUrl);
6888
+ const repository2 = githubRepositoryFromUrl(upstreamUrl);
6889
+ return repository2 ? {
6890
+ ...grant,
6891
+ auditAttributes: {
6892
+ ...grant.auditAttributes,
6893
+ "app.github.repository": `${repository2.owner}/${repository2.name}`
6894
+ }
6895
+ } : grant;
6896
+ }
6897
+ async function selectGitHubGrant(ctx, env, upstreamUrl) {
6898
+ const method = ctx.request.method.toUpperCase();
6544
6899
  applyGitHubEgressPolicy({
6545
6900
  ...ctx.request.bodyText !== void 0 ? { bodyText: ctx.request.bodyText } : void 0,
6901
+ ...ctx.request.graphql ? { graphql: ctx.request.graphql } : void 0,
6546
6902
  method,
6547
6903
  ...ctx.request.operation ? { operation: ctx.request.operation } : void 0,
6548
6904
  upstreamUrl
@@ -6553,12 +6909,24 @@ async function githubGrantForEgress(ctx) {
6553
6909
  const smartHttpAccess = githubSmartHttpAccess(upstreamUrl);
6554
6910
  if (smartHttpAccess) {
6555
6911
  if (smartHttpAccess === "write") {
6556
- requireRepositoryTarget(upstreamUrl);
6557
- return grantForAccess(
6912
+ const repository2 = requireRepositoryTarget(upstreamUrl);
6913
+ const grant = grantForAccess(
6558
6914
  "write",
6559
6915
  "github.installation-write",
6560
6916
  "installation-write"
6561
6917
  );
6918
+ if (method !== "POST" || !upstreamUrl.pathname.toLowerCase().endsWith("/git-receive-pack")) {
6919
+ return grant;
6920
+ }
6921
+ return {
6922
+ ...grant,
6923
+ auditAttributes: await assertGitHubPushAllowed({
6924
+ cache: ctx.cache,
6925
+ env,
6926
+ gitPush: ctx.request.gitPush,
6927
+ repository: repository2
6928
+ })
6929
+ };
6562
6930
  }
6563
6931
  return grantForAccess(
6564
6932
  smartHttpAccess,
@@ -6585,23 +6953,27 @@ async function githubGrantForEgress(ctx) {
6585
6953
  ctx.request.operation,
6586
6954
  method,
6587
6955
  upstreamUrl,
6588
- ctx.request.bodyText
6956
+ ctx.request.graphql
6589
6957
  );
6590
6958
  if (hostMutationRepository) {
6591
- return grantForAccess(
6592
- "write",
6593
- "github.installation-write",
6594
- "installation-write"
6595
- );
6959
+ return {
6960
+ ...grantForAccess(
6961
+ "write",
6962
+ "github.installation-write",
6963
+ "installation-write"
6964
+ ),
6965
+ // GraphQL URLs name no repository; the host operation does.
6966
+ auditAttributes: { "app.github.repository": hostMutationRepository }
6967
+ };
6596
6968
  }
6597
6969
  const graphqlAccess = githubGraphqlAccess(
6598
6970
  method,
6599
6971
  upstreamUrl,
6600
- ctx.request.bodyText
6972
+ ctx.request.graphql
6601
6973
  );
6602
6974
  if (graphqlAccess) {
6603
6975
  if (graphqlAccess === "write") {
6604
- throw new EgressPolicyDenied2(
6976
+ throw new EgressPolicyDenied3(
6605
6977
  "GitHub GraphQL mutations are not enabled for runtime credentials. Use the matching GitHub tool or a supported REST endpoint. For pull request reviews, use github_submitPullRequestReview. It posts to /repos/{owner}/{repo}/pulls/{number}/reviews."
6606
6978
  );
6607
6979
  }
@@ -6613,7 +6985,7 @@ async function githubGrantForEgress(ctx) {
6613
6985
  }
6614
6986
  const access = HTTP_READ_METHODS.has(method) ? "read" : "write";
6615
6987
  if (access === "write") {
6616
- throw new EgressPolicyDenied2(
6988
+ throw new EgressPolicyDenied3(
6617
6989
  "This GitHub write request is not supported. Use the matching GitHub tool or a supported REST endpoint."
6618
6990
  );
6619
6991
  }
@@ -6786,13 +7158,13 @@ function githubPlugin(options = {}) {
6786
7158
  log: ctx.log,
6787
7159
  now: new Date(ctx.nowMs),
6788
7160
  search: async (input) => {
6789
- const login = botLoginFromEmail(requireEnv(botEmailEnv));
6790
- if (!login) {
7161
+ const login2 = botLoginFromEmail(requireEnv(botEmailEnv));
7162
+ if (!login2) {
6791
7163
  throw new Error(`${botEmailEnv} is not a GitHub bot address`);
6792
7164
  }
6793
7165
  return await searchOpenPullRequestMergeability(
6794
7166
  { appIdEnv, installationIdEnv, privateKeyEnv },
6795
- { ...input, author: `app/${login.replace(/\[bot\]$/, "")}` }
7167
+ { ...input, author: `app/${login2.replace(/\[bot\]$/, "")}` }
6796
7168
  );
6797
7169
  },
6798
7170
  state: ctx.state
@@ -6903,7 +7275,11 @@ function githubPlugin(options = {}) {
6903
7275
  );
6904
7276
  },
6905
7277
  grantForEgress(ctx) {
6906
- return githubGrantForEgress(ctx);
7278
+ return githubGrantForEgress(ctx, {
7279
+ appIdEnv,
7280
+ installationIdEnv,
7281
+ privateKeyEnv
7282
+ });
6907
7283
  },
6908
7284
  async onEgressResponse(ctx) {
6909
7285
  if (ctx.response.status === 403) {