在配置基于 Github Discussions 的博客评论系统时(例如 giscus),往往需要获取 repo 的 repoId
、categoryId
等属性,因此这里介绍一种获取这些信息的方法。
开启仓库的 Discussions
首先我们需要开启目标仓库的 Discussions 功能,方法很简单,在仓库的设置中勾选 Discussions 即可:
获取 Repo ID 等信息
然后打开 Github Docs 官网:Github Docs Explorer,授权 Github 账户登录,并输入以下内容:
1
2
3
4
5
6
7
8
9
10
11
| {
repository(owner: "userName", name: "repoName") {
id
discussionCategories (first: 5) {
nodes {
name
id
}
}
}
}
|
- 将
userName
换成具体的 Github 用户名; - 将
repoName
换成保存评论数据的 Repo 名称。
示意图如下:
便可得到如下结果:
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
| {
"data": {
"repository": {
"id": "R_kgDOKjFfn1",
"discussionCategories": {
"nodes": [
{
"name": "Announcements",
"id": "DIC_kwdOJPFfnc4CU9A2"
},
{
"name": "General",
"id": "DIC_kwdOJPFfnc4CU9A3"
},
{
"name": "Ideas",
"id": "DIC_kwdOJPFfnc4CU9A5"
},
{
"name": "Polls",
"id": "DIC_kwdOJPFfnc4CU9A7"
},
{
"name": "Q&A",
"id": "DIC_kwdOJPFfnc4CU9A4"
}
]
}
}
}
}
|
上述 JSON 的 "id": "R_kgDOKjFfn1"
和 DIC_kwdOJPFfnc4CU9...
就是我们需要的 repoId
和 categoryId
。