MCPcopy Create free account
hub / github.com/dmno-dev/bumpy / withPatToken

Function withPatToken

packages/bumpy/src/commands/ci.ts:37–55  ·  view source on GitHub ↗

* Temporarily override GH_TOKEN with BUMPY_GH_TOKEN for a gh CLI call. * * When BUMPY_GH_TOKEN is set (e.g. a dedicated bot PAT or GitHub App token), * it is used so that PRs created by bumpy can trigger CI workflows (the * default GITHUB_TOKEN cannot do this). If BUMPY_GH_TOKEN is not available

(fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

35 * (e.g. fork PRs where secrets are hidden), falls back to the default token.
36 */
37async function withPatToken<T>(fn: () => Promise<T>): Promise<T> {
38 const token = process.env.BUMPY_GH_TOKEN;
39 if (!token) return fn();
40 const originalGhToken = process.env.GH_TOKEN;
41 process.env.GH_TOKEN = token;
42 try {
43 return await fn();
44 } catch (err) {
45 // Redact token from error messages to prevent leakage in CI logs
46 const msg = err instanceof Error ? err.message : String(err);
47 throw new Error(msg.replaceAll(token, '***'));
48 } finally {
49 if (originalGhToken !== undefined) {
50 process.env.GH_TOKEN = originalGhToken;
51 } else {
52 delete process.env.GH_TOKEN;
53 }
54 }
55}
56
57// ---- Validation helpers ----
58

Callers 4

createVersionPrFunction · 0.85
createChannelReleasePrFunction · 0.85
enableAutoMergeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…