MCPcopy Create free account
hub / github.com/github/gh-aw / selectTokenForRepo

Function selectTokenForRepo

actions/setup/js/apply_samples.cjs:151–165  ·  view source on GitHub ↗

* Resolve the best token for a `owner/repo` API call. * * Multi-checkout workflows often need different tokens for different * repositories (e.g. a workflow runs in `owner/automation` but reaches into * `owner/product` via a separate `checkout:` entry that supplies its own * `github-token:` or

(owner, repo)

Source from the content-addressed store, hash-verified

149 * @returns {string|undefined}
150 */
151function selectTokenForRepo(owner, repo) {
152 const slug = `${owner}/${repo}`;
153 const raw = process.env.GH_AW_REPO_TOKENS;
154 if (raw && raw.trim()) {
155 try {
156 const map = JSON.parse(raw);
157 if (map && typeof map === "object" && typeof map[slug] === "string" && map[slug].trim()) {
158 return map[slug].trim();
159 }
160 } catch (err) {
161 core.warning(`apply_samples: GH_AW_REPO_TOKENS is not valid JSON, ignoring: ${getErrorMessage(err)}`);
162 }
163 }
164 return process.env.GITHUB_TOKEN || process.env.GH_TOKEN || undefined;
165}
166
167/**
168 * Fetch a pull request via the REST API and return its head ref. Uses the

Callers 2

fetchPullRequestHeadRefFunction · 0.85

Calls 2

getErrorMessageFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected