master
1import { task } from '../../task.js'
2import { paginate, query } from '../../utils.js'
3import { ReactionsBatchQuery, ReactionsQuery } from './reactions.graphql.js'
4
5export default task({
6 name: 'reactions-batch' as const,
7 run: async ({ octokit, data }, { ids }: { ids: string[] }) => {
8 const { nodes, rateLimit } = await query(octokit, ReactionsBatchQuery, {
9 ids,
10 })
11
12 octokit.log.info(
13 `| reactions batch ${nodes.length} (cost: ${rateLimit?.cost}, remaining: ${rateLimit?.remaining})`,
14 )
15 for (const node of nodes) {
16 if (node.__typename === 'Issue') {
17 const issue = data.issues.find((x) => x.id === node.id)
18 if (issue) {
19 issue.reactions = node.reactions.nodes ?? undefined
20 }
21 }
22 if (node.__typename === 'PullRequest') {
23 const pull = data.pulls.find((x) => x.id === node.id)
24 if (pull) {
25 pull.reactions = node.reactions.nodes ?? undefined
26 }
27 }
28 if (node.__typename === 'DiscussionComment') {
29 const discussionComment = data.discussionComments.find(
30 (x) => x.id === node.id,
31 )
32 if (discussionComment) {
33 discussionComment.reactions = node.reactions.nodes ?? undefined
34 }
35 }
36 if (node.__typename === 'IssueComment') {
37 const issueComment = data.issueComments.find((x) => x.id === node.id)
38 if (issueComment) {
39 issueComment.reactions = node.reactions.nodes ?? undefined
40 }
41 }
42 }
43 },
44})