@@ -106,8 +106,7 @@ export const getGitHubReposFromConfig = async (config: GithubConnectionConfig, o
106
106
}
107
107
108
108
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 ) ;
111
110
allRepos = allRepos . concat ( validRepos ) ;
112
111
notFound . users = notFoundUsers ;
113
112
}
@@ -219,32 +218,27 @@ export const shouldExcludeRepo = ({
219
218
return false ;
220
219
}
221
220
222
- const getReposOwnedByUsers = async ( users : string [ ] , isAuthenticated : boolean , octokit : Octokit , signal : AbortSignal ) => {
221
+ const getReposOwnedByUsers = async ( users : string [ ] , octokit : Octokit , signal : AbortSignal ) => {
223
222
const results = await Promise . allSettled ( users . map ( async ( user ) => {
224
223
try {
225
224
logger . debug ( `Fetching repository info for user ${ user } ...` ) ;
226
225
227
226
const { durationMs, data } = await measure ( async ( ) => {
228
227
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 [ ] ;
248
242
} ;
249
243
250
244
return fetchWithRetry ( fetchFn , `user ${ user } ` , logger ) ;
0 commit comments