I'm able to get the file contents (and if it's a folder, I'm able to get the list of files) by using the GitHub v3 API. Example:
https://api.github.com/repos/[Owner]/[Repository]/contents/[Folder]
But how can I know when the file was last updated? Is there an API for that?
If we use git log -p -- b , we can see all the changes on b without knowing the commit hash. If you want to see only the last change, you can use git log -p -1 -- b .
When you start a new repository, you typically want to add all existing files so that your changes will all be tracked from that point forward. So, the first command you'll typically type is "git add ." (the "." means, this directory. So, it will add everything in this directory.) I'll type "git add ." and press Enter.
In Github, is there a way I can see the number of downloads for a repo? Clone counts are available to authorized users by scraping with a Github username/password as are counts of downloads of asset files within releases.
If you know the exact file path, you can use list commits on repository API specifying a path
which only includes commits with this specific file path and then extract the most recent commit (the most recent is the first one) :
https://api.github.com/repos/bertrandmartel/speed-test-lib/commits?path=jspeedtest%2Fbuild.gradle&page=1&per_page=1
Using curl & jq :
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'
{
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
}
}
}
}
}
}
}
}
Try it in the explorer
Using curl & jq :
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'
pip install 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)
Output:
population
5
2020-04-14 15:09:26
https://github.com/PyGithub/PyGithub
That would be surprising, considering git does not store file timestamps (and other metadata like permissions and ownership), for reasons I detailed here.
So that information is not present on the remote repository side (here GitHub) either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With