forked from mastodon/joinmastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linear.mjs
114 lines (95 loc) · 2.2 KB
/
linear.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import * as dotenv from "dotenv"
import { LinearClient } from "@linear/sdk"
import fs from "fs"
dotenv.config({ path: ".env.local" })
const api = new LinearClient({
apiKey: process.env.LINEAR_API_KEY,
})
const fetchIssues = async (after) =>
api.issues({
filter: {
team: {
key: {
in: ["MAS", "IOS", "AND"],
},
},
labels: {
name: {
eqIgnoreCase: "Public roadmap",
},
},
state: {
type: {
in: ["backlog", "unstarted", "started", "completed"],
},
},
},
})
const processIssues = async (stateMap, issues) => {
for (const issue of issues.nodes) {
const state = await issue.state
const list = (stateMap[state.type] || { items: [] }).items
if (list.find((item) => item.id === issue.identifier)) {
continue
}
const parent = await issue.parent
list.push({
id: issue.identifier,
title: issue.title,
priority: issue.priority,
completedAt: issue.completedAt,
parent: parent
? {
id: parent.identifier,
title: parent.title,
}
: null,
})
stateMap[state.type] = {
type: state.type,
items: list,
}
}
}
const stateMap = {}
const roadmap = []
let issues = await fetchIssues()
await processIssues(stateMap, issues)
while (issues.pageInfo.hasNextPage) {
issues = await issues.fetchNext()
await processIssues(stateMap, issues)
}
Object.keys(stateMap).forEach((state) => {
if (state !== "completed") {
stateMap[state].items.sort((a, b) => a.priority - b.priority)
} else {
stateMap[state].items.sort(
(a, b) => new Date(b.completedAt) - new Date(a.completedAt)
)
}
roadmap.push(stateMap[state])
})
const stateTypeToValue = (type) => {
switch (type) {
case "backlog":
return 0
case "unstarted":
return 1
case "started":
return 2
case "completed":
return -1
}
}
roadmap.sort((a, b) => stateTypeToValue(b.type) - stateTypeToValue(a.type))
fs.writeFile(
"./data/linear.json",
JSON.stringify(roadmap, null, " "),
(err) => {
if (err) {
console.error(err)
return
}
console.log("File updated")
}
)