我可以使用GitHub v3 API获取文件内容(如果它是文件夹,我可以获取文件列表). 例:
https://api.github.com/repos/[Owner]/[Repository]/contents/[Folder]
Run Code Online (Sandbox Code Playgroud)
但是如何知道文件上次更新的时间?那有API吗?
小智 11
pip 安装 PyGithub
from github import Github
g = Github()
repo = g.get_repo("datasets/population")
print(repo.name)
commits = repo.get_commits(path='data/population.csv')
print(commits.totalCount)
if commits.totalCount:
print(commits[0].commit.committer.date)
Run Code Online (Sandbox Code Playgroud)
输出:
population
5
2020-04-14 15:09:26
Run Code Online (Sandbox Code Playgroud)
https://github.com/PyGithub/PyGithub
如果您知道确切的文件路径,则可以在存储库API上使用列表提交,指定一个path仅包含具有此特定文件路径的提交,然后提取最新的提交(最新的是第一个):
curl -s "https://api.github.com/repos/bertrandmartel/speed-test-lib/commits?path=jspeedtest%2Fbuild.gradle&page=1&per_page=1" | \
jq -r '.[0].commit.committer.date'
Run Code Online (Sandbox Code Playgroud)
{
repository(owner: "bertrandmartel", name: "speed-test-lib") {
ref(qualifiedName: "refs/heads/master") {
target {
... on Commit {
history(first: 1, path: "jspeedtest/build.gradle") {
edges {
node {
committedDate
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
curl -s -H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type:application/json" \
-d '{
"query": "{ repository(owner: \"bertrandmartel\", name: \"speed-test-lib\") { ref(qualifiedName: \"refs/heads/master\") { target { ... on Commit { history(first: 1, path: \"jspeedtest/build.gradle\") { edges { node { committedDate } } } } } } } }"
}' https://api.github.com/graphql | \
jq -r '.data.repository.ref.target.history.edges[0].node.committedDate'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1182 次 |
| 最近记录: |