Add file ignore functionality and update documentation for ignore patterns

This commit is contained in:
mrT23
2024-06-13 11:41:13 +03:00
parent a32a12a851
commit e367df352b
3 changed files with 16 additions and 5 deletions

View File

@ -10,12 +10,17 @@ To ignore files or directories, edit the **[ignore.toml](https://github.com/Codi
For example, to ignore Python files in a PR with online usage, comment on a PR:
`/review --ignore.glob=['*.py']`
To ignore Python files in all PRs, set in a configuration file:
To ignore Python files in all PRs using `glob` pattern, set in a configuration file:
```
[ignore]
glob = ['*.py']
```
And to ignore Python files in all PRs using `regex` pattern, set in a configuration file:
```
[regex]
regex = ['.*\.py$']
```
## Extra instructions
All PR-Agent tools have a parameter called `extra_instructions`, that enables to add free-text extra instructions. Example usage:

View File

@ -8,6 +8,7 @@ from github import AppAuthentication, Auth, Github, GithubException
from retry import retry
from starlette_context import context
from ..algo.file_filter import filter_ignored
from ..algo.language_handler import is_valid_file
from ..algo.utils import load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file
from ..config_loader import get_settings
@ -106,18 +107,21 @@ class GithubProvider(GitProvider):
git_files = context.get("git_files", None)
if git_files:
return git_files
self.git_files = self.pr.get_files()
self.git_files = list(self.pr.get_files()) # 'list' to hanlde pagination
context["git_files"] = self.git_files
return self.git_files
except Exception:
if not self.git_files:
self.git_files = self.pr.get_files()
self.git_files = list(self.pr.get_files())
return self.git_files
def get_num_of_files(self):
if self.git_files:
if hasattr(self.git_files, "totalCount"):
return self.git_files.totalCount
else:
try:
return len(self.git_files)
except Exception as e:
return -1
@retry(exceptions=RateLimitExceeded,
@ -143,6 +147,7 @@ class GithubProvider(GitProvider):
return self.diff_files
files = self.get_files()
files = filter_ignored(files)
diff_files = []
for file in files:

View File

@ -8,4 +8,5 @@ glob = [
regex = [
# Ignore files and directories matching these regex patterns.
# See https://learnbyexample.github.io/python-regex-cheatsheet/
# for example: regex = ['.*\.toml$']
]