master
1import { task } from '../../task.js'
2import { paginate } from '../../utils.js'
3import { ReposQuery } from './repos.graphql.js'
4
5export default task({
6 name: 'repos' as const,
7 run: async (
8 { octokit, data, batch },
9 { username, author }: { username: string; author: string },
10 ) => {
11 const repos = paginate(octokit, ReposQuery, { login: username, author })
12
13 data.repos = []
14
15 const batchCommits = batch('commits', 'commits-batch', 8)
16
17 for await (const resp of repos) {
18 if (!resp.user?.repositories.nodes) {
19 throw new Error('Failed to load repos')
20 }
21
22 for (const repo of resp.user.repositories.nodes) {
23 data.repos.push({ ...repo, commits: [] })
24
25 const commitCount =
26 repo.defaultBranchRef?.target?.history.totalCount ?? 0
27 if (commitCount >= 10_000) {
28 octokit.log.error(
29 `Too many commits for ${repo.owner.login}/${repo.name}: ${commitCount} commits; My-Badges will skip repos with more than 10k commits.`,
30 )
31 } else {
32 batchCommits(commitCount, repo.id)
33 }
34 }
35 octokit.log.info(
36 `| repos ${data.repos.length}/${resp.user.repositories.totalCount} (cost: ${resp.rateLimit?.cost}, remaining: ${resp.rateLimit?.remaining})`,
37 )
38 }
39 },
40})