[x]
):I'm trying to fetch commit timestamps for a given file via the API. Using /repos​/{owner}​/{repo}​/contents​/{filepath}
(eg https://try.gitea.io/api/v1/repos/magnusja/libaums/contents/app%2Fbuild.gradle
) reports details for the file quite fine, but obviously lists a wrong sha: using the sha given there as {ref}
for ​/repos​/{owner}​/{repo}​/commits​/{ref}​/statuses
gives an empty result, for https://try.gitea.io/api/v1/repos/magnusja/libaums/commits?sha=049bdf7bbc8ff39411b618ff855a14ed3446dcc1&limit=1
it even results in a 503 server error. Trying the sha on ​/repos​/{owner}​/{repo}​/git​/trees​/{sha}
(where it explicitly says "sha") results in a "bad request: sha not found".
Reproducible for other repos/files on eg Codeberg.org – I could not find a single valid commit hash in the values given for sha
, and no way to get the correct commit hashes.
UPDATE: as pointed out by @mrsdizzie: "this is the file SHA and not a bug" – hence converting this from a "bug report" to a feature request: As currently there's no way to get the file's timestamp/commit-hash, please add it at this level (https://try.gitea.io/api/swagger#/repository/repoGetContents – as suggested by @mrsdizzie). Ideally both. More details on the commit itself could be obtained easily using ​/repos​/{owner}​/{repo}​/commits/{ref}​/statuses, for example, once the commit hash is known.
ok the issue is func GetTreeEntryByPath from modules/git use gogit witch look like it the internal sha of the file object is used as lastCommitSHA witch is wrong ...
but this will need time to dig into
@6543 thanks for digging that up! I'm no Go dev, but tried to figure myself in the hope to give a pointer. Ended up at the very same place, but was unsure if I might have misread it. Thanks for confirming!
Problem is, as there's no way to figure the correct SHA via the API, all methods requiring it will fail – unless there's a second source to get the SHA from. If someone has a work-around for getting the latest commit SHA for a given path (apart from checking out the entire repo), I'd welcome the hint!
I don't thinks your analysis is correct:
if I go to https://try.gitea.io/api/v1/repos/magnusja/libaums/contents/app%2Fbuild.gradle
I get "sha":"1c5ce3a124eb0acc1ddda0da47d108a89e99fbde"
I get the same sha when checking on the command line:
johan@x1:/tmp/libaums(develop)$ git ls-files -s app/build.gradle
100644 1c5ce3a124eb0acc1ddda0da47d108a89e99fbde 0 app/build.gradle
or also
johan@x1:/tmp/libaums(develop)$ git hash-object app/build.gradle
1c5ce3a124eb0acc1ddda0da47d108a89e99fbde
You are confusing the file
sha with the commit
sha
Note the behaviour of github is the same here:
https://api.github.com/repos/go-gitea/gitea/contents/LICENSE
"sha": "a8d4b49dd073a4a38a7e58385eeff7cc52568697"
johan@x1:~/git/gitea(master)$ git ls-files -s LICENSE
100644 a8d4b49dd073a4a38a7e58385eeff7cc52568697 0 LICENSE
FYI, it looks like the github api does support specifying a path
https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
Gitea does not, but that does not seem a bug but rather a feature request.
You are confusing the file sha with the commit sha
I only get one SHA reported. If you can tell me where to find the commit SHA, I'd immediately take that, of course!
Maybe I started with wrong assumptions having used the APIs of Github/GitLab before. But which approach would you suggest then if I want to get the timestamp for the last commit of a given file?
Comment above should be correct this is the file SHA and not a bug.
For the feature request itself I don't think we currently provide a way to get the last timestamp of a file by name via API -- Maybe it should just be added as a response field to https://try.gitea.io/api/swagger#/repository/repoGetContents
Or add last commit SHA there as well and be able to look it up with that
Maybe it should just be added as a response field to https://try.gitea.io/api/swagger#/repository/repoGetContents
Would be a good place indeed. Could be named commit
(or commit_hash
/ commit_sha
) to make a clear connection. As the result represents the file, having timestamp details available directly at this place would of course be welcome, too – even if it would just be the commit_timestamp
(unix time). More details on the commit itself could be obtained easily using ​/repos​/{owner}​/{repo}​/commits/{ref}​/statuses
, for example, once the commit hash is known.
@IzzySoft can you change issue title?
@6543 sure, done (hope that fits now). Shall I edit my original post as well (striking the wrong assumptions, adding a summary of "the real thing")?
thanks - if you like ...
Done as well. Makes it easier to see what's open without scanning the entire thread :wink:
Just a short heads-up (no pressure/whining/…): Any (at least vague) ETA on when this could be expected?
Most helpful comment
I don't thinks your analysis is correct:
if I go to https://try.gitea.io/api/v1/repos/magnusja/libaums/contents/app%2Fbuild.gradle
I get "sha":"1c5ce3a124eb0acc1ddda0da47d108a89e99fbde"
I get the same sha when checking on the command line:
or also
You are confusing the
file
sha with thecommit
sha