(
octokit: Octokit,
owner: string,
url: string | undefined,
context: string
)
| 120 | * otherwise falls back to the provided octokit instance. |
| 121 | */ |
| 122 | const getOctokitWithGithubApp = async ( |
| 123 | octokit: Octokit, |
| 124 | owner: string, |
| 125 | url: string | undefined, |
| 126 | context: string |
| 127 | ): Promise<Octokit> => { |
| 128 | if (!await hasEntitlement('github-app') || !GithubAppManager.getInstance().appsConfigured()) { |
| 129 | return octokit; |
| 130 | } |
| 131 | |
| 132 | try { |
| 133 | const hostname = url ? new URL(url).hostname : GITHUB_CLOUD_HOSTNAME; |
| 134 | const token = await GithubAppManager.getInstance().getInstallationToken(owner, hostname); |
| 135 | const { octokit: octokitFromToken, isAuthenticated } = await createOctokitFromToken({ |
| 136 | token, |
| 137 | url, |
| 138 | }); |
| 139 | |
| 140 | if (isAuthenticated) { |
| 141 | return octokitFromToken; |
| 142 | } else { |
| 143 | logger.error(`Failed to authenticate with GitHub App for ${context}. Falling back to legacy token resolution.`); |
| 144 | return octokit; |
| 145 | } |
| 146 | } catch (error) { |
| 147 | logger.error(`Error getting GitHub App token for ${context}. Falling back to legacy token resolution.`, error); |
| 148 | return octokit; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | export const getGitHubReposFromConfig = async (config: GithubConnectionConfig, signal: AbortSignal): Promise<{ repos: OctokitRepository[], warnings: string[] }> => { |
| 153 | const hostname = config.url ? |
no test coverage detected