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

Function getGitHubReposFromConfig

packages/backend/src/github.ts:152–219  ·  view source on GitHub ↗
(config: GithubConnectionConfig, signal: AbortSignal)

Source from the content-addressed store, hash-verified

150}
151
152export const getGitHubReposFromConfig = async (config: GithubConnectionConfig, signal: AbortSignal): Promise<{ repos: OctokitRepository[], warnings: string[] }> => {
153 const hostname = config.url ?
154 new URL(config.url).hostname :
155 GITHUB_CLOUD_HOSTNAME;
156
157 const token = config.token ?
158 await getTokenFromConfig(config.token) :
159 hostname === GITHUB_CLOUD_HOSTNAME ?
160 env.FALLBACK_GITHUB_CLOUD_TOKEN :
161 undefined;
162
163 const { octokit, isAuthenticated } = await createOctokitFromToken({
164 token,
165 url: config.url,
166 });
167
168
169 if (isAuthenticated) {
170 try {
171 await octokit.rest.users.getAuthenticated();
172 } catch (error) {
173 Sentry.captureException(error);
174 logger.error(`Failed to authenticate with GitHub`, error);
175 throw error;
176 }
177 }
178
179 let allRepos: OctokitRepository[] = [];
180 let allWarnings: string[] = [];
181
182 if (config.orgs) {
183 const { repos, warnings } = await getReposForOrgs(config.orgs, octokit, signal, config.url);
184 allRepos = allRepos.concat(repos);
185 allWarnings = allWarnings.concat(warnings);
186 }
187
188 if (config.repos) {
189 const { repos, warnings } = await getRepos(config.repos, octokit, signal, config.url);
190 allRepos = allRepos.concat(repos);
191 allWarnings = allWarnings.concat(warnings);
192 }
193
194 if (config.users) {
195 const { repos, warnings } = await getReposOwnedByUsers(config.users, octokit, signal, config.url);
196 allRepos = allRepos.concat(repos);
197 allWarnings = allWarnings.concat(warnings);
198 }
199
200 let repos = allRepos
201 .filter((repo) => {
202 const isExcluded = shouldExcludeRepo({
203 repo,
204 include: {
205 topics: config.topics,
206 },
207 exclude: config.exclude,
208 });
209

Callers 1

compileGithubConfigFunction · 0.85

Calls 6

getTokenFromConfigFunction · 0.90
createOctokitFromTokenFunction · 0.85
getReposForOrgsFunction · 0.70
getReposFunction · 0.70
getReposOwnedByUsersFunction · 0.70
shouldExcludeRepoFunction · 0.70

Tested by

no test coverage detected