2023-07-06 00:21:08 +03:00
|
|
|
from os.path import abspath, dirname, join
|
2023-07-24 12:49:57 +02:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import Optional
|
2023-07-06 00:21:08 +03:00
|
|
|
|
|
|
|
from dynaconf import Dynaconf
|
|
|
|
|
2023-07-24 12:49:57 +02:00
|
|
|
PR_AGENT_TOML_KEY = 'pr-agent'
|
|
|
|
|
2023-07-06 00:21:08 +03:00
|
|
|
current_dir = dirname(abspath(__file__))
|
|
|
|
settings = Dynaconf(
|
|
|
|
envvar_prefix=False,
|
2023-07-08 08:52:11 +03:00
|
|
|
merge_enabled=True,
|
2023-07-06 00:21:08 +03:00
|
|
|
settings_files=[join(current_dir, f) for f in [
|
|
|
|
"settings/.secrets.toml",
|
|
|
|
"settings/configuration.toml",
|
2023-07-20 15:37:42 +02:00
|
|
|
"settings/language_extensions.toml",
|
2023-07-06 00:21:08 +03:00
|
|
|
"settings/pr_reviewer_prompts.toml",
|
2023-07-06 17:46:43 +03:00
|
|
|
"settings/pr_questions_prompts.toml",
|
2023-07-13 17:24:56 +03:00
|
|
|
"settings/pr_description_prompts.toml",
|
2023-07-15 09:30:50 +03:00
|
|
|
"settings/pr_code_suggestions_prompts.toml",
|
2023-07-16 19:36:20 +03:00
|
|
|
"settings/pr_information_from_user_prompts.toml",
|
2023-07-06 17:46:43 +03:00
|
|
|
"settings_prod/.secrets.toml"
|
2023-07-06 00:21:08 +03:00
|
|
|
]]
|
|
|
|
)
|
2023-07-24 12:49:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Add local configuration from pyproject.toml of the project being reviewed
|
|
|
|
def _find_repository_root() -> Path:
|
|
|
|
"""
|
|
|
|
Identify project root directory by recursively searching for the .git directory in the parent directories.
|
|
|
|
"""
|
|
|
|
cwd = Path.cwd().resolve()
|
|
|
|
no_way_up = False
|
|
|
|
while not no_way_up:
|
|
|
|
no_way_up = cwd == cwd.parent
|
|
|
|
if (cwd / ".git").is_dir():
|
|
|
|
return cwd
|
|
|
|
cwd = cwd.parent
|
2023-07-25 16:36:58 +03:00
|
|
|
return None
|
2023-07-24 12:49:57 +02:00
|
|
|
|
|
|
|
def _find_pyproject() -> Optional[Path]:
|
|
|
|
"""
|
|
|
|
Search for file pyproject.toml in the repository root.
|
|
|
|
"""
|
2023-07-25 16:41:29 +03:00
|
|
|
repo_root = _find_repository_root()
|
|
|
|
if repo_root:
|
|
|
|
pyproject = _find_repository_root() / "pyproject.toml"
|
|
|
|
return pyproject if pyproject.is_file() else None
|
|
|
|
return None
|
2023-07-24 12:49:57 +02:00
|
|
|
|
|
|
|
pyproject_path = _find_pyproject()
|
|
|
|
if pyproject_path is not None:
|
|
|
|
settings.load_file(pyproject_path, env=f'tool.{PR_AGENT_TOML_KEY}')
|