master
 1import { task } from '../../task.js'
 2import { paginate } from '../../utils.js'
 3import { PullsQuery } from './pulls.graphql.js'
 4
 5export default task({
 6  name: 'pulls' as const,
 7  run: async ({ octokit, data, batch }, { username }: { username: string }) => {
 8    const pulls = paginate(octokit, PullsQuery, {
 9      username,
10    })
11
12    data.pulls = []
13
14    const batchReactions = batch('reactions-pull', 'reactions-batch')
15
16    for await (const resp of pulls) {
17      if (!resp.user?.pullRequests.nodes) {
18        throw new Error('Failed to load pull requests')
19      }
20
21      octokit.log.info(
22        `| pull requests ${
23          data.pulls.length + resp.user.pullRequests.nodes.length
24        }/${resp.user.pullRequests.totalCount} (cost: ${
25          resp.rateLimit?.cost
26        }, remaining: ${resp.rateLimit?.remaining})`,
27      )
28      for (const pull of resp.user.pullRequests.nodes) {
29        if (pull.repository.isPrivate) continue
30        data.pulls.push(pull)
31        batchReactions(pull.reactionsTotal.totalCount, pull.id)
32      }
33    }
34  },
35})