Skip to content

Commit 24f477e

Browse files
committed
feat: add method fetchOrgReposListByLogin in GitHub provider
1 parent 362ba4a commit 24f477e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/providers/index.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,39 @@ const fetchOrgByLogin = async (login) => {
1212
return data
1313
}
1414

15+
const fetchOrgReposListByLogin = async (login) => {
16+
debug(`Fetching organization (${login}) repositories...`)
17+
ensureGithubToken()
18+
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN })
19+
let repoList = []
20+
21+
// IMPORTANT: Ignore private repositories as they might contain sensitive information
22+
const orgQuery = { org: login, type: 'public', per_page: 100 }
23+
24+
const { data: repos } = await octokit.rest.repos.listForOrg(orgQuery)
25+
debug(`Got ${repos.length} repos for org: ${login}`)
26+
repoList = repoList.concat(repos)
27+
28+
// IMPORTANT: If the org has 100 repos it might require pagination management
29+
if (repoList.length === 100) {
30+
let page = 2
31+
let hasMore = true
32+
while (hasMore) {
33+
debug(`Getting page ${page} for org: ${login}`)
34+
const { data: repos, headers } = await octokit.rest.repos.listForOrg({ ...orgQuery, page })
35+
debug(`Got ${repos.length} repos for org: ${login}`)
36+
repoList = repoList.concat(repos)
37+
hasMore = headers.link.includes('rel="next"')
38+
page += 1
39+
}
40+
}
41+
42+
return repoList
43+
}
44+
1545
const github = {
16-
fetchOrgByLogin
46+
fetchOrgByLogin,
47+
fetchOrgReposListByLogin,
1748
}
1849

1950
module.exports = {

0 commit comments

Comments
 (0)