master
1import { task } from '../../task.js'
2import { paginate } from '../../utils.js'
3import { IssueTimelineQuery } from './issue-timeline.graphql.js'
4
5export default task({
6 name: 'issue-timeline' as const,
7 run: async ({ octokit, data, next }, { id }: { id: string }) => {
8 const timeline = paginate(octokit, IssueTimelineQuery, {
9 id,
10 })
11
12 const issue = data.issues.find((x) => x.id === id)
13 if (!issue) {
14 throw new Error(`Issue ${id} not found`)
15 }
16
17 for await (const resp of timeline) {
18 if (!resp.node?.timelineItems.nodes) {
19 throw new Error('Failed to load issue timeline')
20 }
21
22 octokit.log.info(
23 `| timeline ${resp.node.timelineItems.nodes.length}/${resp.node.timelineItems.totalCount} (cost: ${resp.rateLimit?.cost}, remaining: ${resp.rateLimit?.remaining})`,
24 )
25 for (const event of resp.node.timelineItems.nodes) {
26 if (event?.__typename == 'ClosedEvent') {
27 issue.closedBy = event.actor?.login
28 }
29 }
30 }
31 },
32})