@mastra/github-signals 0.5.0-alpha.0 → 0.5.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 +1 @@
1
- {"version":3,"file":"github-app-owner.d.ts","sourceRoot":"","sources":["../src/github-app-owner.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAqBnG,qBAAa,sBAAsB;;IAIjC,YAAY,QAAQ,GAAE,2BAA6C,EAElE;IAEK,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,mBAAmB,CAAC,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CA2BzG;CAWF"}
1
+ {"version":3,"file":"github-app-owner.d.ts","sourceRoot":"","sources":["../src/github-app-owner.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAyBnG,qBAAa,sBAAsB;;IAIjC,YAAY,QAAQ,GAAE,2BAA6C,EAElE;IAEK,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,mBAAmB,CAAC,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CA2BzG;CAWF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Resolve a GitHub credential from the global `gh` CLI and return an environment
3
+ * that presents it to a child process.
4
+ *
5
+ * gitcrawl takes the first non-empty value of the environment variable named by
6
+ * `[github].token_env` (default `GITHUB_TOKEN`) and only discovers it is invalid
7
+ * when GitHub rejects it, so a stale exported token fails `sync` outright even
8
+ * when `gh` can still mint a working credential. Injecting a credential here
9
+ * makes gitcrawl's own env lookup win, so the stale value is never consulted.
10
+ *
11
+ * `gh auth token` is asked with the token variables removed: `gh` answers with
12
+ * `GH_TOKEN`/`GITHUB_TOKEN` verbatim when either is set, which would hand back
13
+ * the very credential being replaced.
14
+ *
15
+ * Returns `undefined` when no credential can be resolved, so callers leave the
16
+ * inherited environment untouched rather than stripping a working token.
17
+ */
18
+ export declare function resolveGithubAuthEnv(): Promise<NodeJS.ProcessEnv | undefined>;
19
+ //# sourceMappingURL=github-auth-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-auth-env.d.ts","sourceRoot":"","sources":["../src/github-auth-env.ts"],"names":[],"mappings":"AA0BA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC,CAqBnF"}
package/dist/index.cjs CHANGED
@@ -30,6 +30,54 @@ let _mastra_core_signals = require("@mastra/core/signals");
30
30
  let _mastra_core_tools = require("@mastra/core/tools");
31
31
  let zod = require("zod");
32
32
  zod = __toESM(zod, 1);
33
+ //#region src/github-auth-env.ts
34
+ let execFileAsync$2;
35
+ /** Environment variables both gitcrawl and the `gh` CLI treat as a GitHub credential. */
36
+ const GITHUB_TOKEN_ENV_VARS = ["GH_TOKEN", "GITHUB_TOKEN"];
37
+ /** Remove every casing of the token variables: Windows treats environment names case-insensitively. */
38
+ function withoutGithubTokens(env) {
39
+ const scrubbed = { ...env };
40
+ for (const name of Object.keys(scrubbed)) if (GITHUB_TOKEN_ENV_VARS.some((tokenEnv) => tokenEnv.toLowerCase() === name.toLowerCase())) delete scrubbed[name];
41
+ return scrubbed;
42
+ }
43
+ /**
44
+ * Resolve a GitHub credential from the global `gh` CLI and return an environment
45
+ * that presents it to a child process.
46
+ *
47
+ * gitcrawl takes the first non-empty value of the environment variable named by
48
+ * `[github].token_env` (default `GITHUB_TOKEN`) and only discovers it is invalid
49
+ * when GitHub rejects it, so a stale exported token fails `sync` outright even
50
+ * when `gh` can still mint a working credential. Injecting a credential here
51
+ * makes gitcrawl's own env lookup win, so the stale value is never consulted.
52
+ *
53
+ * `gh auth token` is asked with the token variables removed: `gh` answers with
54
+ * `GH_TOKEN`/`GITHUB_TOKEN` verbatim when either is set, which would hand back
55
+ * the very credential being replaced.
56
+ *
57
+ * Returns `undefined` when no credential can be resolved, so callers leave the
58
+ * inherited environment untouched rather than stripping a working token.
59
+ */
60
+ async function resolveGithubAuthEnv() {
61
+ const scrubbed = withoutGithubTokens(process.env);
62
+ if (!execFileAsync$2) {
63
+ const { execFile } = await import("child_process");
64
+ execFileAsync$2 = (0, util.promisify)(execFile);
65
+ }
66
+ let token;
67
+ try {
68
+ const { stdout } = await execFileAsync$2("gh", ["auth", "token"], { env: scrubbed });
69
+ token = stdout.trim();
70
+ } catch {
71
+ return;
72
+ }
73
+ if (!token) return void 0;
74
+ return {
75
+ ...process.env,
76
+ GH_TOKEN: token,
77
+ GITHUB_TOKEN: token
78
+ };
79
+ }
80
+ //#endregion
33
81
  //#region src/github-app-owner.ts
34
82
  const OWNER_CACHE_TTL_MS = 1440 * 60 * 1e3;
35
83
  let execFileAsync$1;
@@ -38,7 +86,7 @@ const defaultRunGhApi = async (args) => {
38
86
  const { execFile } = await import("child_process");
39
87
  execFileAsync$1 = (0, util.promisify)(execFile);
40
88
  }
41
- return execFileAsync$1("gh", args);
89
+ return execFileAsync$1("gh", args, { env: await resolveGithubAuthEnv() });
42
90
  };
43
91
  var GithubAppOwnerResolver = class {
44
92
  #cache = /* @__PURE__ */ new Map();
@@ -660,7 +708,8 @@ var GitcrawlSyncClient = class {
660
708
  const { stdout, stderr } = await execFileAsync(this.#command, args, {
661
709
  cwd: input.cwd,
662
710
  signal: input.abortSignal,
663
- maxBuffer: 10 * 1024 * 1024
711
+ maxBuffer: 10 * 1024 * 1024,
712
+ env: await resolveGithubAuthEnv()
664
713
  });
665
714
  return {
666
715
  ok: true,
@@ -1554,7 +1603,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
1554
1603
  `repos/${owner}/${repo}/collaborators/${user}/permission`,
1555
1604
  "--jq",
1556
1605
  ".permission"
1557
- ]);
1606
+ ], { env: await resolveGithubAuthEnv() });
1558
1607
  const raw = stdout.trim();
1559
1608
  permission = [
1560
1609
  "admin",