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