master
1import { task } from '../../task.js'
2import { paginate } from '../../utils.js'
3import { CommitsQuery } from './commits.graphql.js'
4
5export default task({
6 name: 'commits' as const,
7 run: async ({ octokit, data }, { id }: { id: string }) => {
8 const repo = data.repos.find((repo) => repo.id == id)
9 if (!repo) throw new Error(`Repo not found: ${id}`)
10
11 repo.commits = []
12 if (repo.isEmpty) return
13
14 const commits = paginate(octokit, CommitsQuery, {
15 id,
16 author: data.user.id,
17 })
18
19 for await (const resp of commits) {
20 if (!resp.node?.defaultBranchRef?.target?.history) {
21 throw new Error('Failed to load commits')
22 }
23
24 for (const commit of resp.node.defaultBranchRef.target.history.nodes ??
25 []) {
26 repo.commits.push(commit)
27 }
28
29 octokit.log.info(
30 `| commits ${repo?.owner.login}/${repo?.name} ${repo.commits.length}/${resp.node.defaultBranchRef.target.history.totalCount} (cost: ${resp.rateLimit?.cost}, remaining: ${resp.rateLimit?.remaining})`,
31 )
32 }
33 },
34})