-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.ts
36 lines (31 loc) · 912 Bytes
/
github.ts
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
import config from "./xotodo.config.json" assert { type: "json" }
export async function getGithubIssues() {
const issues = []
let isLastPage = false
let page = 1
while (!isLastPage) {
const cmd = ["curl",
"-H", "Accept: application/vnd.github+json",
"-H", `Authorization: Bearer ${config.githubPersonalAccessToken}`,
`https://api.github.com/issues?page=${page}`
]
const p = Deno.run({ cmd, stdout: "piped", stderr: "piped" })
try {
const res = new TextDecoder().decode(await p.output())
const data = JSON.parse(res)
if (!Array.isArray(data)) {
console.warn(data)
throw new Error("data is not an array")
}
issues.push(...data)
page++
// 30 = default page size
if (data.length < 30) {
isLastPage = true
return issues
}
} catch (error) {
throw new Error(error)
}
}
}