master
1import { task } from '../../task.js'
2import { query } from '../../utils.js'
3import { IssueTimelineBatchQuery } from './issue-timeline.graphql.js'
4
5export default task({
6 name: 'issue-timeline-batch' as const,
7 run: async ({ octokit, data, next }, { ids }: { ids: string[] }) => {
8 const resp = await query(octokit, IssueTimelineBatchQuery, {
9 ids,
10 })
11
12 octokit.log.info(
13 `| issue timeline batch ${resp.nodes.length} (cost: ${resp.rateLimit?.cost}, remaining: ${resp.rateLimit?.remaining})`,
14 )
15 for (const node of resp.nodes) {
16 if (node && node.__typename === 'Issue') {
17 const issue = data.issues.find((x) => x.id === node.id)
18 if (issue) {
19 for (const event of node.timelineItems.nodes ?? []) {
20 if (event?.__typename == 'ClosedEvent') {
21 issue.closedAt = event.createdAt
22 }
23 }
24 }
25 }
26 }
27 },
28})