@sentry/junior-github 0.266.0 → 0.268.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/SETUP.md CHANGED
@@ -162,6 +162,7 @@ Use `additionalUserScopes` only when a human-identity integration flow requires
162
162
  - `user-read` and explicitly human `user-write` operations require the actor, or an explicitly delegated user subject, to authorize the GitHub App through the private OAuth flow. Junior-owned issue, pull request, review, inline review comment, and branch operations do not fall back to user OAuth.
163
163
  - Headless event turns use the `event` system actor and may receive the same installation grants. This lets Junior respond to subscribed pull request events by committing and pushing fixes without inheriting a subscriber's OAuth credential.
164
164
  - Git commits use Junior as author and committer. Resolvable human run actors are credited once with `Co-Authored-By` trailers. When the current actor has a linked GitHub identity, Junior prefers a GitHub noreply address so external automation can resolve a login for assignment.
165
+ - Junior points `core.hooksPath` at its own hooks directory for every sandbox command. It sets the value in the command env, so it also wins over a repository `core.hooksPath` such as husky's. That directory runs Junior's commit attribution hook and passes every other client hook to the repository's own hooks directory: its `core.hooksPath` if set, or `.git/hooks` (simple-git-hooks, Git LFS). A failing repository hook stops the commit or push.
165
166
  - Installation credential leases are cached on the host by grant name and reused across sandboxes until near expiry. User grants stay actor-scoped. Upstream 403 after injection clears the cached lease, issues a new token, and retries the hop once before recording permission denied.
166
167
  - Sandbox does not receive raw tokens via env; host applies Authorization header transforms for GitHub API and upload calls.
167
168
 
@@ -17,6 +17,7 @@ function gitHubRepoMatchFields(events) {
17
17
  return eventMatchFieldsSchema.parse({
18
18
  repo: {
19
19
  kind: "string",
20
+ case: "lower",
20
21
  description: "lowercase repository as owner/repo, such as getsentry/junior",
21
22
  events
22
23
  }
@@ -26,6 +27,7 @@ function gitHubCommitMatchFields(events) {
26
27
  return eventMatchFieldsSchema.parse({
27
28
  commitSha: {
28
29
  kind: "string",
30
+ case: "lower",
29
31
  description: "full lowercase Git commit SHA",
30
32
  events
31
33
  }
@@ -57,6 +59,7 @@ var GITHUB_DEPLOYMENT_MATCH_FIELDS = eventMatchFieldsSchema2.parse({
57
59
  },
58
60
  environment: {
59
61
  kind: "string",
62
+ case: "lower",
60
63
  description: "lowercase deployment environment name, such as production",
61
64
  events: [...GITHUB_DEPLOYMENT_EVENTS]
62
65
  },
@@ -1336,6 +1339,9 @@ function parseCheckSuitePublishTargets(body) {
1336
1339
  );
1337
1340
  }
1338
1341
  return {
1342
+ // Every copy sets this repo, so a broad trigger for another repo adds
1343
+ // no lazy keys.
1344
+ data: { repo: gitHubRepoDataSchema.parse(repo) },
1339
1345
  eventTypes: [eventType],
1340
1346
  identifiers: [...identifiers]
1341
1347
  };
@@ -2160,6 +2166,7 @@ function normalizeGitHubEvents(args) {
2160
2166
  export {
2161
2167
  normalizePermissions,
2162
2168
  readGrantPermissions,
2169
+ gitHubRepoDataSchema,
2163
2170
  GITHUB_ISSUE_EVENTS,
2164
2171
  GITHUB_ISSUE_SUGGESTED_EVENTS,
2165
2172
  GITHUB_ISSUE_MATCH_FIELDS,
@@ -0,0 +1,18 @@
1
+ import type { PluginEventDeclaration } from "@sentry/junior-plugin-api";
2
+ import { type GitHubPullRequestEvent } from "./pull-request.js";
3
+ /**
4
+ * Declare the reach and guidance of every GitHub event.
5
+ *
6
+ * - Deployment events reach every repository. They carry status facts,
7
+ * Junior adds no reaction, and they load nothing from GitHub.
8
+ * - Release, issue, and pull request events need a `repo` filter. They carry
9
+ * release notes, titles, bodies, comments, or reviews from repositories
10
+ * that can be private, and comments and reviews make Junior add a
11
+ * reaction. The filter limits how many repositories a trigger covers. It
12
+ * does not check that the person can see the repository.
13
+ *
14
+ * Pull request filters such as `authors` and `openerRole` load data from
15
+ * GitHub. Core skips a trigger with no identifier when its `repo` filter does
16
+ * not match the event, so it loads nothing for other repositories.
17
+ */
18
+ export declare function gitHubEventDeclarations(pullRequestGuidance: Partial<Record<GitHubPullRequestEvent, string>>): Record<string, PluginEventDeclaration>;
@@ -11,6 +11,7 @@ export declare const GITHUB_DEPLOYMENT_MATCH_FIELDS: Record<string, {
11
11
  description: string;
12
12
  enum?: string[] | undefined;
13
13
  list?: true | undefined;
14
+ case?: "lower" | "upper" | undefined;
14
15
  events?: string[] | undefined;
15
16
  }>;
16
17
  /** The identifier shape that `gitHubDeploymentSourceResource` builds. */
@@ -11,6 +11,7 @@ export declare const GITHUB_ISSUE_MATCH_FIELDS: Record<string, {
11
11
  description: string;
12
12
  enum?: string[] | undefined;
13
13
  list?: true | undefined;
14
+ case?: "lower" | "upper" | undefined;
14
15
  events?: string[] | undefined;
15
16
  }>;
16
17
  /** The identifier shape that `gitHubIssueResource` builds. */
@@ -34,6 +34,7 @@ export declare const GITHUB_PULL_REQUEST_MATCH_FIELDS: Record<string, {
34
34
  description: string;
35
35
  enum?: string[] | undefined;
36
36
  list?: true | undefined;
37
+ case?: "lower" | "upper" | undefined;
37
38
  events?: string[] | undefined;
38
39
  }>;
39
40
  /** The identifier shape that `gitHubPullRequestResource` builds. */
@@ -16,6 +16,7 @@ export declare const GITHUB_RELEASE_MATCH_FIELDS: Record<string, {
16
16
  description: string;
17
17
  enum?: string[] | undefined;
18
18
  list?: true | undefined;
19
+ case?: "lower" | "upper" | undefined;
19
20
  events?: string[] | undefined;
20
21
  }>;
21
22
  export declare const GITHUB_RELEASE_SUGGESTED_EVENTS: string[];
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Git identity and commit-hook setup for GitHub sandboxes.
3
3
  */
4
- import type { Actor, SandboxPrepareHookContext, User } from "@sentry/junior-plugin-api";
4
+ import type { Actor, PluginEnv, SandboxPrepareHookContext, User } from "@sentry/junior-plugin-api";
5
5
  /**
6
6
  * Build `Co-Authored-By` trailers crediting human run actors.
7
7
  *
@@ -20,6 +20,27 @@ export declare function additionalActorCoauthorTrailers(args: {
20
20
  /** Linked user for the current run actor, when already resolved. */
21
21
  currentUser?: User;
22
22
  }): string[];
23
+ /**
24
+ * Client hooks that Junior's hooks directory passes to the repository.
25
+ *
26
+ * Junior's `core.hooksPath` replaces the repository hooks directory: the
27
+ * repository's own `core.hooksPath` (husky) or `.git/hooks` (simple-git-hooks,
28
+ * Git LFS). Git would skip those hooks without these pass-through hooks.
29
+ * `prepare-commit-msg` is not in the list because Junior's own hook runs the
30
+ * repository hook first.
31
+ */
32
+ export declare const REPOSITORY_HOOK_NAMES: readonly ["applypatch-msg", "pre-applypatch", "post-applypatch", "pre-commit", "pre-merge-commit", "commit-msg", "post-commit", "pre-rebase", "post-checkout", "post-merge", "pre-push", "post-rewrite", "pre-auto-gc"];
33
+ /** Directory for Junior's Git hooks under the sandbox Junior root. */
34
+ export declare function gitHooksPath(juniorRoot: string): string;
35
+ /**
36
+ * Point Git at Junior's hooks for one command.
37
+ *
38
+ * Command env config has a higher priority than every config file, so it
39
+ * also wins over a repository `core.hooksPath` such as husky's.
40
+ */
41
+ export declare function setGitHooksPathEnv(env: PluginEnv, hooksPath: string): void;
42
+ /** Build a hook that runs the repository's own hook with the same name. */
43
+ export declare function repositoryHook(name: string): string;
23
44
  /** Build the hook that replaces model-supplied commit attribution. */
24
45
  export declare function prepareCommitMsgHook(): string;
25
46
  /** Set one global Git option inside the prepared sandbox. */
package/dist/index.js CHANGED
@@ -37,6 +37,7 @@ import {
37
37
  gitHubPullRequestEventGuidance,
38
38
  gitHubPullRequestSubscribable,
39
39
  gitHubReleaseSourceSubscribable,
40
+ gitHubRepoDataSchema,
40
41
  gitHubRepositorySubscribable,
41
42
  githubRepositoryFromUrl,
42
43
  githubRequest,
@@ -55,7 +56,7 @@ import {
55
56
  readGrantPermissions,
56
57
  requireEnv,
57
58
  resolveUserAccount
58
- } from "./chunk-B6WCXAII.js";
59
+ } from "./chunk-PQFFT2UO.js";
59
60
 
60
61
  // src/tool-support/attribution.ts
61
62
  var GITHUB_REQUEST_ATTRIBUTION_START = "<!-- junior-request-attribution:start -->";
@@ -3808,6 +3809,9 @@ async function withGitHubPullRequestMatchData(args) {
3808
3809
  repositoryFullName: parsed.data.repository.full_name
3809
3810
  };
3810
3811
  const keys = await args.neededMatchKeys?.({
3812
+ // Every copy sets this repo, so a broad trigger for another repo adds
3813
+ // no lazy keys.
3814
+ data: { repo: gitHubRepoDataSchema.parse(context.repositoryFullName) },
3811
3815
  eventTypes: [...new Set(pullRequestEvents.map((e) => e.eventType))],
3812
3816
  identifiers: [...new Set(pullRequestEvents.map((e) => e.identifier))]
3813
3817
  }) ?? [];
@@ -4219,6 +4223,25 @@ function createGitHubWebhookRoute(args) {
4219
4223
  };
4220
4224
  }
4221
4225
 
4226
+ // src/events/declarations.ts
4227
+ var NEEDS_REPO = { anyOf: ["repo"] };
4228
+ function gitHubEventDeclarations(pullRequestGuidance) {
4229
+ const declarations = {};
4230
+ for (const eventType of GITHUB_DEPLOYMENT_EVENTS) {
4231
+ declarations[eventType] = { reach: "all" };
4232
+ }
4233
+ for (const eventType of [...GITHUB_RELEASE_EVENTS, ...GITHUB_ISSUE_EVENTS]) {
4234
+ declarations[eventType] = { reach: NEEDS_REPO };
4235
+ }
4236
+ for (const eventType of GITHUB_PULL_REQUEST_EVENTS) {
4237
+ const declaration = { reach: NEEDS_REPO };
4238
+ const guidance = pullRequestGuidance[eventType];
4239
+ if (guidance) declaration.guidance = guidance;
4240
+ declarations[eventType] = declaration;
4241
+ }
4242
+ return declarations;
4243
+ }
4244
+
4222
4245
  // src/webhooks/installation-requests.ts
4223
4246
  import { z as z22 } from "zod";
4224
4247
  function splitRepository(fullName, label) {
@@ -4431,6 +4454,53 @@ function additionalActorCoauthorTrailers(args) {
4431
4454
  }
4432
4455
  return trailers;
4433
4456
  }
4457
+ var REPOSITORY_HOOK_NAMES = [
4458
+ "applypatch-msg",
4459
+ "pre-applypatch",
4460
+ "post-applypatch",
4461
+ "pre-commit",
4462
+ "pre-merge-commit",
4463
+ "commit-msg",
4464
+ "post-commit",
4465
+ "pre-rebase",
4466
+ "post-checkout",
4467
+ "post-merge",
4468
+ "pre-push",
4469
+ "post-rewrite",
4470
+ "pre-auto-gc"
4471
+ ];
4472
+ function gitHooksPath(juniorRoot) {
4473
+ return `${juniorRoot}/git-hooks`;
4474
+ }
4475
+ function setGitHooksPathEnv(env, hooksPath) {
4476
+ const index2 = Number.parseInt(env.get("GIT_CONFIG_COUNT") ?? "0", 10) || 0;
4477
+ env.set(`GIT_CONFIG_KEY_${index2}`, "core.hooksPath");
4478
+ env.set(`GIT_CONFIG_VALUE_${index2}`, hooksPath);
4479
+ env.set("GIT_CONFIG_COUNT", String(index2 + 1));
4480
+ }
4481
+ function findRepositoryHook(name) {
4482
+ return `repository_hook=""
4483
+ repository_hooks_dir=$(git config --local --type=path core.hooksPath 2>/dev/null) || repository_hooks_dir=""
4484
+ if [ -z "$repository_hooks_dir" ]; then
4485
+ git_common_dir=$(git rev-parse --git-common-dir 2>/dev/null) || git_common_dir=""
4486
+ if [ -n "$git_common_dir" ]; then
4487
+ repository_hooks_dir="$git_common_dir/hooks"
4488
+ fi
4489
+ fi
4490
+ if [ -n "$repository_hooks_dir" ] && [ -x "$repository_hooks_dir/${name}" ] && ! [ "$repository_hooks_dir/${name}" -ef "$0" ]; then
4491
+ repository_hook="$repository_hooks_dir/${name}"
4492
+ fi`;
4493
+ }
4494
+ function repositoryHook(name) {
4495
+ return `#!/usr/bin/env bash
4496
+ set -eu
4497
+
4498
+ ${findRepositoryHook(name)}
4499
+ if [ -n "$repository_hook" ]; then
4500
+ exec "$repository_hook" "$@"
4501
+ fi
4502
+ `;
4503
+ }
4434
4504
  function prepareCommitMsgHook() {
4435
4505
  return `#!/usr/bin/env bash
4436
4506
  set -eu
@@ -4440,6 +4510,12 @@ if [ -z "$message_file" ]; then
4440
4510
  exit 1
4441
4511
  fi
4442
4512
 
4513
+ # Run the repository hook first so Junior's trailers stay final.
4514
+ ${findRepositoryHook("prepare-commit-msg")}
4515
+ if [ -n "$repository_hook" ]; then
4516
+ "$repository_hook" "$@"
4517
+ fi
4518
+
4443
4519
  if [ -z "\${JUNIOR_GIT_AUTHOR_NAME:-}" ] || [ -z "\${JUNIOR_GIT_AUTHOR_EMAIL:-}" ]; then
4444
4520
  echo "GitHub plugin internal error: the host runtime did not inject the Git author identity. Do not set Git author env vars manually; report this configuration error." >&2
4445
4521
  exit 1
@@ -5577,10 +5653,7 @@ function githubPlugin(options = {}) {
5577
5653
  identifier: GITHUB_PULL_REQUEST_IDENTIFIER,
5578
5654
  supportedEvents: [...GITHUB_PULL_REQUEST_EVENTS],
5579
5655
  suggestedEvents: [...GITHUB_PULL_REQUEST_SUGGESTED_EVENTS],
5580
- matchFields: GITHUB_PULL_REQUEST_MATCH_FIELDS,
5581
- guidance: gitHubPullRequestEventGuidance(
5582
- options.pullRequestEvents?.guidance
5583
- )
5656
+ matchFields: GITHUB_PULL_REQUEST_MATCH_FIELDS
5584
5657
  },
5585
5658
  {
5586
5659
  type: "release_source",
@@ -5598,12 +5671,12 @@ function githubPlugin(options = {}) {
5598
5671
  GITHUB_DEPLOYMENT_MATCH_FIELDS,
5599
5672
  GITHUB_ISSUE_MATCH_FIELDS,
5600
5673
  GITHUB_PULL_REQUEST_MATCH_FIELDS
5601
- ),
5602
- guidance: gitHubPullRequestEventGuidance(
5603
- options.pullRequestEvents?.guidance
5604
5674
  )
5605
5675
  }
5606
5676
  ],
5677
+ events: gitHubEventDeclarations(
5678
+ gitHubPullRequestEventGuidance(options.pullRequestEvents?.guidance)
5679
+ ),
5607
5680
  isEnabled: () => Boolean(readEnv("GITHUB_WEBHOOK_SECRET")),
5608
5681
  normalizeIdentifier: (identifier) => identifier.toLowerCase()
5609
5682
  },
@@ -5770,12 +5843,19 @@ function githubPlugin(options = {}) {
5770
5843
  },
5771
5844
  workspacePrepare: prepareWorkspace,
5772
5845
  async sandboxPrepare(ctx) {
5773
- const hooksPath = `${ctx.sandbox.juniorRoot}/git-hooks`;
5846
+ const hooksPath = gitHooksPath(ctx.sandbox.juniorRoot);
5774
5847
  await ctx.sandbox.writeFile({
5775
5848
  path: `${hooksPath}/prepare-commit-msg`,
5776
5849
  mode: 493,
5777
5850
  content: prepareCommitMsgHook()
5778
5851
  });
5852
+ for (const name of REPOSITORY_HOOK_NAMES) {
5853
+ await ctx.sandbox.writeFile({
5854
+ path: `${hooksPath}/${name}`,
5855
+ mode: 493,
5856
+ content: repositoryHook(name)
5857
+ });
5858
+ }
5779
5859
  await configureGit(ctx, "core.hooksPath", hooksPath);
5780
5860
  await configureGit(ctx, "commit.gpgsign", "false");
5781
5861
  await configureGit(ctx, "credential.helper", "");
@@ -5798,6 +5878,7 @@ function githubPlugin(options = {}) {
5798
5878
  ctx.env.set("JUNIOR_GIT_AUTHOR_EMAIL", botEmail);
5799
5879
  ctx.env.set("GIT_COMMITTER_NAME", botName);
5800
5880
  ctx.env.set("GIT_COMMITTER_EMAIL", botEmail);
5881
+ setGitHooksPathEnv(ctx.env, gitHooksPath(ctx.juniorRoot));
5801
5882
  let currentUser;
5802
5883
  if (ctx.actor) {
5803
5884
  try {
package/dist/testing.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  normalizeGitHubEvents
3
- } from "./chunk-B6WCXAII.js";
3
+ } from "./chunk-PQFFT2UO.js";
4
4
  export {
5
5
  normalizeGitHubEvents
6
6
  };
@@ -52,6 +52,9 @@ export declare function selectFailingChecks(checkRuns: unknown, options?: {
52
52
  export declare function normalizeCheckSuiteEvents(deliveryId: string, body: unknown, options?: GitHubCheckSuiteFacts): EventInput[];
53
53
  /** Identifiers and event types one completed check suite may publish. */
54
54
  export declare function parseCheckSuitePublishTargets(body: unknown): {
55
+ data: {
56
+ repo: string;
57
+ };
55
58
  eventTypes: string[];
56
59
  identifiers: string[];
57
60
  } | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-github",
3
- "version": "0.266.0",
3
+ "version": "0.268.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.266.0"
35
+ "@sentry/junior-plugin-api": "0.268.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@oxlint/plugins": "1.79.0",