fix(github): Fix issue with users not getting picked up in GitHub config (#428)

* fix

* changelog
This commit is contained in:
Brendan Kellam 2025-08-04 17:39:28 -07:00 committed by GitHub
parent 65d3cd9dc6
commit 01dee161b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 22 deletions

View file

@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Fixed
- Fixed issue where `users` specified in a GitHub config were not getting picked up when a `token` is also specified. [#428](https://github.com/sourcebot-dev/sourcebot/pull/428)
### Added ### Added
- [ask sb] Added OpenAI Compatible Language Provider. [#424](https://github.com/sourcebot-dev/sourcebot/pull/424) - [ask sb] Added OpenAI Compatible Language Provider. [#424](https://github.com/sourcebot-dev/sourcebot/pull/424)

View file

@ -106,8 +106,7 @@ export const getGitHubReposFromConfig = async (config: GithubConnectionConfig, o
} }
if (config.users) { if (config.users) {
const isAuthenticated = config.token !== undefined; const { validRepos, notFoundUsers } = await getReposOwnedByUsers(config.users, octokit, signal);
const { validRepos, notFoundUsers } = await getReposOwnedByUsers(config.users, isAuthenticated, octokit, signal);
allRepos = allRepos.concat(validRepos); allRepos = allRepos.concat(validRepos);
notFound.users = notFoundUsers; notFound.users = notFoundUsers;
} }
@ -219,32 +218,27 @@ export const shouldExcludeRepo = ({
return false; return false;
} }
const getReposOwnedByUsers = async (users: string[], isAuthenticated: boolean, octokit: Octokit, signal: AbortSignal) => { const getReposOwnedByUsers = async (users: string[], octokit: Octokit, signal: AbortSignal) => {
const results = await Promise.allSettled(users.map(async (user) => { const results = await Promise.allSettled(users.map(async (user) => {
try { try {
logger.debug(`Fetching repository info for user ${user}...`); logger.debug(`Fetching repository info for user ${user}...`);
const { durationMs, data } = await measure(async () => { const { durationMs, data } = await measure(async () => {
const fetchFn = async () => { const fetchFn = async () => {
if (isAuthenticated) { // @note: We need to use GitHub's search API here since it is the only way
return octokit.paginate(octokit.repos.listForAuthenticatedUser, { // to get all repositories (private and public) owned by a user that supports
username: user, // the username as a parameter.
visibility: 'all', // @see: https://github.com/orgs/community/discussions/24382#discussioncomment-3243958
affiliation: 'owner', // @see: https://api.github.com/search/repositories?q=user:USERNAME
per_page: 100, const searchResults = await octokit.paginate(octokit.rest.search.repos, {
request: { q: `user:${user}`,
signal, per_page: 100,
}, request: {
}); signal,
} else { },
return octokit.paginate(octokit.repos.listForUser, { });
username: user,
per_page: 100, return searchResults as OctokitRepository[];
request: {
signal,
},
});
}
}; };
return fetchWithRetry(fetchFn, `user ${user}`, logger); return fetchWithRetry(fetchFn, `user ${user}`, logger);