MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / getOctokitWithGithubApp

Function getOctokitWithGithubApp

packages/backend/src/github.ts:122–150  ·  view source on GitHub ↗
(
    octokit: Octokit,
    owner: string,
    url: string | undefined,
    context: string
)

Source from the content-addressed store, hash-verified

120 * otherwise falls back to the provided octokit instance.
121 */
122const 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
152export const getGitHubReposFromConfig = async (config: GithubConnectionConfig, signal: AbortSignal): Promise<{ repos: OctokitRepository[], warnings: string[] }> => {
153 const hostname = config.url ?

Callers 3

getReposOwnedByUsersFunction · 0.85
getReposForOrgsFunction · 0.85
getReposFunction · 0.85

Calls 5

createOctokitFromTokenFunction · 0.85
appsConfiguredMethod · 0.80
getInstanceMethod · 0.80
getInstallationTokenMethod · 0.80
hasEntitlementFunction · 0.70

Tested by

no test coverage detected