-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathget-scripts.ts
More file actions
75 lines (64 loc) · 1.58 KB
/
Copy pathget-scripts.ts
File metadata and controls
75 lines (64 loc) · 1.58 KB
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
import '@johnlindquist/kit'
import {gql, GraphQLClient} from 'graphql-request'
import slugify from 'slugify'
import {Discussion} from '../src/lib/get-discussions'
export enum Category {
Announcements = 'MDE4OkRpc2N1c3Npb25DYXRlZ29yeTMyODIwMDgw',
Docs = 'MDE4OkRpc2N1c3Npb25DYXRlZ29yeTMyODc5NjIx',
Share = 'MDE4OkRpc2N1c3Npb25DYXRlZ29yeTMyMDg0MTcw',
}
let endpoint = 'https://api.github.com/graphql'
let categoryId = await arg(
'Category',
Object.entries(Category).map(([name, value]) => {
return {
name,
value,
}
}),
)
let client = new GraphQLClient(endpoint, {
headers: {
'GraphQL-Features': 'discussions_api',
authorization: `Bearer ${await env('GITHUB_DISCUSSIONS_TOKEN')}`,
},
})
let query = gql`
query ($categoryId: ID) {
repository(owner: "johnlindquist", name: "kit") {
discussions(
first: 100
categoryId: $categoryId
orderBy: {field: CREATED_AT, direction: DESC}
) {
# type: DiscussionConnection
totalCount # Int!
nodes {
title
url
author {
login
avatarUrl
url
}
body
id
createdAt
}
}
}
}
`
let response = await client.request(query, {categoryId})
let discussions = response.repository.discussions.nodes.map((d: Discussion) => {
const slug = slugify(d.title, {
lower: true,
strict: true,
})
return {
...d,
slug,
}
})
// let scripts = await getAllScripts()
// await outputJson(path.resolve(cwd(), 'public', 'data', 'scripts.json'), scripts)