https://api.github.com
分页查询参数 page 和 per_page
/search/repositories
参数:
(1) q: 要搜索的仓库名
/users/:userId/events
/users/:userId/repos
跟随者
/users/:userId/followers
跟随
/users/:userId/following
/users/:userId/starred
/repos/:userId/:repo/contents/:path
如:
GET https://api.github.com/repos/saber2pr/saber2pr.github.io/contents/blog
PUT /repos/:userId/:repo/contents/:path
发送 body 格式:
type Commit = {
message: string
content: string
sha?: string
}
其中 content 字段需要 base64 转码。commit 需要 JSON 序列化后作为 body 发送。
commit 中的 sha 可省略。若更新已有文件,则 sha 字段为必需。
注意是 body,不是参数
DELETE /repos/:userId/:repo/contents/:path
同样需要 body 发送,格式:
type Commit = {
message: string
sha: string
}
sha 字段为必须。
/repos/:userId/:repo/commits?path=:path
如:
GET https://api.github.com/repos/saber2pr/saber2pr.github.io/commits?path=/blog
通过 commit.committer.date 可得到提交时间
/repos/:userId/:repo/languages
返回值里不同语言有对应的字节数
export const getContentTree = async (
repo,
root = { path: "", type: "dir" }
) => {
if (root.type === "dir") {
const children = await request(
`https://api.github.com/repos/${username}/${repo}/contents/${root.path}`
)
root.children = await Promise.all(
children.map(node => getContentTree(repo, node))
)
}
return root
}