@@ -106,8 +106,7 @@ export const getGitHubReposFromConfig = async (config: GithubConnectionConfig, o
106106 }
107107
108108 if ( config . users ) {
109- const isAuthenticated = config . token !== undefined ;
110- const { validRepos, notFoundUsers } = await getReposOwnedByUsers ( config . users , isAuthenticated , octokit , signal ) ;
109+ const { validRepos, notFoundUsers } = await getReposOwnedByUsers ( config . users , octokit , signal ) ;
111110 allRepos = allRepos . concat ( validRepos ) ;
112111 notFound . users = notFoundUsers ;
113112 }
@@ -219,32 +218,27 @@ export const shouldExcludeRepo = ({
219218 return false ;
220219}
221220
222- const getReposOwnedByUsers = async ( users : string [ ] , isAuthenticated : boolean , octokit : Octokit , signal : AbortSignal ) => {
221+ const getReposOwnedByUsers = async ( users : string [ ] , octokit : Octokit , signal : AbortSignal ) => {
223222 const results = await Promise . allSettled ( users . map ( async ( user ) => {
224223 try {
225224 logger . debug ( `Fetching repository info for user ${ user } ...` ) ;
226225
227226 const { durationMs, data } = await measure ( async ( ) => {
228227 const fetchFn = async ( ) => {
229- if ( isAuthenticated ) {
230- return octokit . paginate ( octokit . repos . listForAuthenticatedUser , {
231- username : user ,
232- visibility : 'all' ,
233- affiliation : 'owner' ,
234- per_page : 100 ,
235- request : {
236- signal,
237- } ,
238- } ) ;
239- } else {
240- return octokit . paginate ( octokit . repos . listForUser , {
241- username : user ,
242- per_page : 100 ,
243- request : {
244- signal,
245- } ,
246- } ) ;
247- }
228+ // @note : We need to use GitHub's search API here since it is the only way
229+ // to get all repositories (private and public) owned by a user that supports
230+ // the username as a parameter.
231+ // @see : https://github.com/orgs/community/discussions/24382#discussioncomment-3243958
232+ // @see : https://api.github.com/search/repositories?q=user:USERNAME
233+ const searchResults = await octokit . paginate ( octokit . rest . search . repos , {
234+ q : `user:${ user } ` ,
235+ per_page : 100 ,
236+ request : {
237+ signal,
238+ } ,
239+ } ) ;
240+
241+ return searchResults as OctokitRepository [ ] ;
248242 } ;
249243
250244 return fetchWithRetry ( fetchFn , `user ${ user } ` , logger ) ;
0 commit comments