Skip to content

GhApi.get_repo_contents method #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

KeremTurgutlu
Copy link

@KeremTurgutlu KeremTurgutlu commented Apr 10, 2025

This PR adds couple of utility methods to get repo file contents, which can be useful for dynamically creating the LLM context. Tested these changes locally with my editable builld.

get_repo_files(self:GhApi, owner, repo, branch="main", inc=None, exc=None):

This method returns all the repo files recursively using git.get_tree as recommended in the official GH api docs and allows filtering by passing inc:included and exc:excluded Unix-style wildcards using fnmatch. If a file matches one of the patterns in both included and excluded lists, then * expression is prioritized, if both have * expression than the longer expression is prioritized. This is useful for some common filtering cases, for example "Exclude all .md files expect for README.md", or "Include all .py files except for tests".

image

get_file_content(self:GhApi, path, owner, repo, branch="main"):

Gets file content of given file and also decodes the file content.

image

get_repo_contents(self:GhApi, owner, repo, **kwargs):

This uses GhApi.get_repo_files + parallel GhApi.get_file_content to get all repo contents.

image

More examples and explanations can be found in the core nb.

@KeremTurgutlu KeremTurgutlu added the enhancement New feature or request label Apr 10, 2025
@KeremTurgutlu KeremTurgutlu requested a review from jph00 April 10, 2025 15:19
@jph00
Copy link
Contributor

jph00 commented Apr 25, 2025

@KeremTurgutlu sorry I forgot to look at this! It looks great :D My only request is that you cut back on the output so that the docs are more concise. We really like things to be concise! Having more stuff for the user to read is a burden that we should only require where the upside outweighs the downside. So have a look at each line of code and each line of output and think about whether reaches that bar. If it doesn't, cut it back until it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants