master
1import { task } from '../../task.js'
2import { paginate } from '../../utils.js'
3import { ReactionsQuery } from './reactions.graphql.js'
4
5export default task({
6 name: 'reactions-pull' as const,
7 run: async ({ octokit, data }, { id }: { id: string }) => {
8 const pullReactions = paginate(octokit, ReactionsQuery, {
9 id,
10 })
11
12 const pull = data.pulls.find((x) => x.id === id)
13 if (!pull) {
14 throw new Error(`Pull ${id} not found`)
15 }
16
17 pull.reactions = []
18
19 for await (const resp of pullReactions) {
20 if (!resp.node?.reactions.nodes) {
21 throw new Error('Failed to load pull reactions')
22 }
23
24 for (const reaction of resp.node.reactions.nodes) {
25 pull.reactions.push(reaction)
26 }
27
28 octokit.log.info(
29 `| pull reactions ${data.issueComments.length}/${resp.node.reactions.totalCount} (cost: ${resp.rateLimit?.cost}, remaining: ${resp.rateLimit?.remaining})`,
30 )
31 }
32 },
33})