@sentry/junior-github 0.318.0 → 0.320.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.
@@ -1,8 +1,8 @@
1
1
  import * as z from "zod";
2
- import pLimit from "p-limit";
3
2
  import { PluginToolInputError, eventMatchFieldsSchema, mergeEventMatchFields } from "@sentry/junior-plugin-api";
4
3
  import { lexer } from "marked";
5
- import { createHash, createPrivateKey, createSign } from "node:crypto";
4
+ import pLimit from "p-limit";
5
+ import { createPrivateKey, createSign } from "node:crypto";
6
6
  // src/tool-support/github-api.ts
7
7
  const GITHUB_API_BASE = "https://api.github.com";
8
8
  const MAX_REDIRECTS = 3;
@@ -959,7 +959,7 @@ function parseGitHubBotIdentity(value) {
959
959
  function botLoginFromEmail(value) {
960
960
  return parseGitHubBotIdentity(value)?.login;
961
961
  }
962
- /** Check whether a GitHub login is the bot encoded in the configured bot email. */
962
+ /** Whether a GitHub login is the bot that the configured bot email encodes. */
963
963
  function isBotLogin(login, botEmail) {
964
964
  const botLogin = botLoginFromEmail(botEmail)?.toLowerCase();
965
965
  return Boolean(botLogin && login?.trim().toLowerCase() === botLogin);
@@ -984,23 +984,11 @@ function hasHtmlQuote(token) {
984
984
  return token.type === "html" && HTML_QUOTE_OPEN.test(token.raw) || childTokens(token).some(hasHtmlQuote);
985
985
  }
986
986
  /**
987
- * Split a comment into the text that its author wrote (`own`) and the rest
988
- * (`other`), such as quotes. Each part is undefined when it is empty. This is
989
- * the one parser for a GitHub author's own text.
990
- *
991
- * A quote repeats text that someone else wrote, so it is never the author's
992
- * own words. Markdown quotes and HTML are removed, also in lists and tables.
993
- * An HTML quote has no reliable end: Markdown splits it at blank lines, and a
994
- * closing tag can hide in an HTML comment or attribute. So the block with the
995
- * first HTML quote tag and all text after it are removed. Each rule removes
996
- * text, so a parse that GitHub renders differently can only drop the
997
- * author's words, never add words that someone else wrote.
998
- *
999
- * Code stays, because an instruction can name a command. `withoutCode` also
1000
- * removes code, where text in code does not count, such as a mention.
1001
- *
1002
- * The removed text goes to `other`, so it is shown once, as text that the
1003
- * author did not write.
987
+ * Split a comment into the author's own text (`own`) and the rest (`other`),
988
+ * such as quotes, so the rest shows once as not theirs. The one parser for a
989
+ * GitHub author's text. Quotes and HTML go, also in lists and tables; an HTML
990
+ * quote has no reliable end, so all text from it on goes. Rules only remove,
991
+ * so a misparse drops the author's words, never adds others'. Code stays.
1004
992
  */
1005
993
  function splitCommentText(text, options = {}) {
1006
994
  if (!text) return {};
@@ -1043,70 +1031,6 @@ function mentionsBotLogin(text, botEmail) {
1043
1031
  const escaped = slug.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1044
1032
  return new RegExp(`(?:^|[^\\w-])@${escaped}(?![\\w-])`, "i").test(splitCommentText(text, { withoutCode: true }).own ?? "");
1045
1033
  }
1046
- // src/conditional-requests.ts
1047
- /**
1048
- * Conditional GitHub reads. GitHub does not count a `304 Not Modified`
1049
- * answer against the rate limit, so a repeat read of an unchanged resource,
1050
- * such as a pull request that every check suite webhook reads, is free.
1051
- *
1052
- * Saved bodies are plaintext in plugin state. A breach of that store exposes
1053
- * up to 6 hours of webhook reads: pull requests, their commits with author
1054
- * names and emails, and collaborator roles. It exposes no token.
1055
- */
1056
- /**
1057
- * How long a saved response stays. Webhooks for one pull request come in
1058
- * bursts, such as one for each check suite, so most repeat reads are minutes
1059
- * apart.
1060
- */
1061
- const SAVED_RESPONSE_TTL_MS = 216e5;
1062
- /** Larger bodies, such as long commit lists, are not saved. */
1063
- const MAX_SAVED_BODY_LENGTH = 262144;
1064
- const savedResponseSchema = z.object({
1065
- body: z.string(),
1066
- etag: z.string().min(1)
1067
- });
1068
- /**
1069
- * The state key of a saved response. It has no token: GitHub answers 304
1070
- * only to a request that it authorized, and only when the response to that
1071
- * request did not change, so a saved body never reaches a token that cannot
1072
- * read it.
1073
- */
1074
- function savedResponseKey(url) {
1075
- return `github-response:${createHash("sha256").update(url).digest("hex")}`;
1076
- }
1077
- /**
1078
- * Send one GitHub GET with the ETag of its saved response. On 304, return
1079
- * the saved body as a 200 response. On a 200 with an ETag, save the body.
1080
- * Without `responses`, send the request as it is.
1081
- *
1082
- * Saved responses only save rate limit. A read or write failure of plugin
1083
- * state is a cache miss, so it never fails the GitHub read.
1084
- */
1085
- async function sendConditionalRequest(responses, url, send) {
1086
- if (!responses) return await send({});
1087
- const key = savedResponseKey(url);
1088
- const saved = savedResponseSchema.safeParse(await responses.get(key).catch(() => void 0));
1089
- const response = await send(saved.success ? { "If-None-Match": saved.data.etag } : {});
1090
- if (response.status === 304 && saved.success) {
1091
- await response.body?.cancel();
1092
- return new Response(saved.data.body, {
1093
- headers: { etag: saved.data.etag },
1094
- status: 200
1095
- });
1096
- }
1097
- const etag = response.headers.get("etag");
1098
- if (!response.ok || !etag) return response;
1099
- const body = await response.text();
1100
- if (body.length <= MAX_SAVED_BODY_LENGTH) await responses.set(key, {
1101
- body,
1102
- etag
1103
- }, SAVED_RESPONSE_TTL_MS).catch(() => void 0);
1104
- return new Response(body, {
1105
- headers: response.headers,
1106
- status: response.status,
1107
- statusText: response.statusText
1108
- });
1109
- }
1110
1034
  // src/installation-responses.ts
1111
1035
  /** Parsers for GitHub App installation API responses. */
1112
1036
  const installationTokenResponseSchema = z.object({
@@ -1296,7 +1220,7 @@ function createAppJwt(appId, privateKeyEnv) {
1296
1220
  async function githubRequest(apiBase, path, params) {
1297
1221
  const method = params.method ?? "GET";
1298
1222
  const url = `${apiBase}${path}`;
1299
- const response = await sendConditionalRequest(method === "GET" ? params.responses : void 0, url, (headers) => fetch(url, {
1223
+ const send = (headers) => fetch(url, {
1300
1224
  method,
1301
1225
  headers: {
1302
1226
  ...headers,
@@ -1306,7 +1230,8 @@ async function githubRequest(apiBase, path, params) {
1306
1230
  ...params.body ? { "Content-Type": "application/json" } : void 0
1307
1231
  },
1308
1232
  ...params.body ? { body: JSON.stringify(params.body) } : void 0
1309
- }));
1233
+ });
1234
+ const response = method === "GET" && params.responses ? await params.responses(url, send) : await send({});
1310
1235
  const text = await response.text();
1311
1236
  let parsed;
1312
1237
  if (text) try {