-
-
Save johndevs/8bfd1c5338be0e753e56a3794fb0cc3a to your computer and use it in GitHub Desktop.
| # Provide $query as a variable. | |
| # The query is the same as you would enter into the search field e.g. "org:johndevs in:name feedreader" | |
| query GetFilesQuery($branch: GitObjectID, $query: String!) { | |
| search(first: 1, type: REPOSITORY, query: $query) { | |
| edges { | |
| node { | |
| ... on Repository { | |
| object(expression: "master:", oid: $branch) { | |
| ... on Tree { | |
| entries { | |
| name | |
| object { | |
| ... on Blob { | |
| text | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Thank you for this gist.
The title is a little misleading though. This query only gets the root level files, you don't get files that are deeper inside directories.
To query files in a specific directory change "master:" with "master: folder/with/some/subfolders"
I can't find anything suitable like master: *.
But I did find a way to get an extra level down using nesting in my query.
object(expression: "master:") {
... on Tree {
entries {
name
object {
... on Tree {
entries {
name
}
}
}
Don't use master: but HEAD:
Not every repo has master: as the default branch
How would one grab the updated date or committedDate for each of these TreeEntries?
I tried using Commit instead of Blob and that didn't work. Got all empty objects. {}
object {
... on Commit {
committedDate
authoredDate
}
}
I couldn't figure it out either. Put a stackoverflow question on it:
https://stackoverflow.com/questions/71499519/getting-commit-data-on-file-list-github-graphql-api
Thanks! I needed something similar to get all the files in a repo and this was most useful.
I linked back here :) https://gist.github.com/MichaelCurrin/6777b91e6374cdb5662b64b8249070ea