* 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)
| 149 | * @returns {string|undefined} |
| 150 | */ |
| 151 | function 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 |
no test coverage detected