github - 获取文件上次从 Github 存储库更新的时间
问题描述
通过使用 GitHub v3 API,我可以获取文件内容(如果它是一个文件夹,我可以获取文件列表) 。 例子:
https://api.github.com/repos/[Owner]/[Repository]/contents/[Folder]
但是我怎么知道文件上次更新的时间呢?有那个API吗?
解决方案
如果您知道确切的文件路径,则可以在存储库 API 上使用 list commits指定path
仅包含具有此特定文件路径的提交,然后提取最近的提交(最近的是第一个):
使用 Rest API v3
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'
使用 GraphqQL API v4
{
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
}
}
}
}
}
}
}
}
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'
推荐阅读
- angular - Angular 6 - 在提交时恢复表单字段更改的值
- visual-studio-code - 如何配置 emmet bem 过滤器以使其在 tsx 中工作?
- powershell - 如果上一行不匹配,则删除一行?
- javascript - 为什么我不能在 React 中传递简单的道具..从父母到孩子
- flutter - 为什么父类接受孩子的颜色?
- android-studio - 更新后未显示 Android Studio 的触控栏图标
- google-cloud-firestore - 更新到 cloud_firestore 2.2.0 并且无法找出错误
- heroku - 有没有办法在heroku上查看应用程序流量统计?
- memory - CL 时序信息 DDR3 SDRAM
- delphi - 使用样式 Ownerdraw 时如何在 TCombobox 中显示 TextHint