codefox 0.4.1__tar.gz → 0.4.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codefox-0.4.1 → codefox-0.4.5}/.gitignore +9 -6
- {codefox-0.4.1 → codefox-0.4.5}/PKG-INFO +3 -2
- {codefox-0.4.1 → codefox-0.4.5}/WIKI.md +1 -0
- {codefox-0.4.1 → codefox-0.4.5}/action.yml +12 -2
- {codefox-0.4.1 → codefox-0.4.5}/codefox/api/base_api.py +6 -1
- codefox-0.4.5/codefox/bots/gitlab_bot.py +56 -0
- codefox-0.4.5/codefox/cli/index.py +22 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/cli/init.py +16 -3
- {codefox-0.4.1 → codefox-0.4.5}/codefox/cli/scan.py +9 -1
- {codefox-0.4.1 → codefox-0.4.5}/codefox/cli_manager.py +8 -1
- {codefox-0.4.1 → codefox-0.4.5}/codefox/main.py +25 -7
- {codefox-0.4.1 → codefox-0.4.5}/codefox/utils/helper.py +6 -2
- {codefox-0.4.1 → codefox-0.4.5}/codefox/utils/local_rag.py +30 -29
- codefox-0.4.5/codefox-template.yml +35 -0
- {codefox-0.4.1 → codefox-0.4.5}/pyproject.toml +2 -1
- {codefox-0.4.1 → codefox-0.4.5}/requirements.in +2 -1
- {codefox-0.4.1 → codefox-0.4.5}/requirements.txt +2 -1
- {codefox-0.4.1 → codefox-0.4.5}/setup.py +2 -1
- codefox-0.4.5/tests/test_gitlab_bot.py +65 -0
- codefox-0.4.5/tests/test_init.py +38 -0
- {codefox-0.4.1 → codefox-0.4.5}/uv.lock +28 -1
- {codefox-0.4.1 → codefox-0.4.5}/.github/ISSUE_TEMPLATE/bug-report.md +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/.github/workflows/ci.yml +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/.github/workflows/publish.yml +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/.python-version +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/CODE_OF_CONDUCT.md +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/CONTRIBUTING.md +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/LICENSE +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/README.md +1 -1
- {codefox-0.4.1 → codefox-0.4.5}/SECURITY.md +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/assets/logo.png +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/assets/work_review.gif +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/__init__.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/__main__.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/api/__init__.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/api/gemini.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/api/model_enum.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/api/ollama.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/api/openrouter.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/bots/__init__.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/bots/github_bot.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/cli/__init__.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/cli/base_cli.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/cli/clean.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/cli/list.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/prompts/__init__.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/prompts/audit/__init__.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/prompts/audit/audit_content.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/prompts/audit/audit_system.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/prompts/prompt_template.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/prompts/template.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/tools/__init__.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/tools/base_tool.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/tools/rag_tool.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/utils/__init__.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/codefox/utils/parser.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/requirements-dev.txt +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/tests/conftest.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/tests/test_base_api_config.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/tests/test_clean.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/tests/test_cli_manager.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/tests/test_helper.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/tests/test_local_rag.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/tests/test_model_enum.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/tests/test_prompt_template.py +0 -0
- {codefox-0.4.1 → codefox-0.4.5}/tests/test_scan.py +0 -0
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
.vscode/
|
|
2
2
|
.idea/
|
|
3
3
|
.venv/
|
|
4
|
+
.codefox/
|
|
4
5
|
.*_cache/
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
__pycache__/
|
|
8
|
+
build/
|
|
9
|
+
codefox.egg-info/
|
|
10
|
+
|
|
6
11
|
.codefoxenv
|
|
7
12
|
.codefoxignore
|
|
8
13
|
.codefox.yml
|
|
14
|
+
.env
|
|
9
15
|
|
|
10
16
|
venv*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*.pyc
|
|
14
|
-
.codefox/
|
|
15
|
-
codefox.egg-info/
|
|
17
|
+
|
|
18
|
+
*.pyc
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codefox
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.5
|
|
4
4
|
Summary: CodeFox CLI - code auditing and code review tool
|
|
5
5
|
Project-URL: Documentation, https://github.com/codefox-lab/CodeFox-CLI/wiki
|
|
6
6
|
Project-URL: Homepage, https://github.com/URLbug/CodeFox-CLI
|
|
@@ -36,6 +36,7 @@ Requires-Dist: psutil==7.2.2
|
|
|
36
36
|
Requires-Dist: pygithub==2.8.1
|
|
37
37
|
Requires-Dist: pygments==2.19.2
|
|
38
38
|
Requires-Dist: python-dotenv==1.2.1
|
|
39
|
+
Requires-Dist: python-gitlab==8.1.0
|
|
39
40
|
Requires-Dist: pyyaml==6.0.3
|
|
40
41
|
Requires-Dist: qdrant-client>=1.7.0
|
|
41
42
|
Requires-Dist: requests>=2.28.0
|
|
@@ -124,9 +125,9 @@ It is built for **diff review workflows**, terminal usage, and CI/CD automation.
|
|
|
124
125
|
|
|
125
126
|
Current:
|
|
126
127
|
- GitHub Actions
|
|
128
|
+
- GitLab
|
|
127
129
|
|
|
128
130
|
Planned:
|
|
129
|
-
- GitLab
|
|
130
131
|
- Bitbucket
|
|
131
132
|
|
|
132
133
|
---
|
|
@@ -195,6 +195,7 @@ The parameters in the `model` section control the loading of the embedding model
|
|
|
195
195
|
| --- | --- | --- | --- |
|
|
196
196
|
| `model.embedding` | `string` | `null` | see above | Identifier for the embedding model (fastembed). |
|
|
197
197
|
| `model.max_rag_chars` | `number` | `4096` | Maximum number of RAG context characters injected into the prompt. Increasing this provides more code in the context, but increases token consumption. |
|
|
198
|
+
| `model.max_rag_matching_chunks` | `number` | `12` | Maximum number of RAG context chunks to search in database.
|
|
198
199
|
| `model.max_diff_chars` | `number` | `500000` | Diff size truncation: if the diff is larger than this value, it is truncated and a truncation notice is appended at the end. |
|
|
199
200
|
| `model.rag_max_query_chars` | `number` | `2000` | Maximum length of the query to RAG (when searching for relevant chunks). An overly long query is truncated. |
|
|
200
201
|
| `model.rag_chunk_size` | `number` | `1000` | Chunk size in characters when splitting files. Code is split by function/class boundaries (tree-sitter) or by sentences. |
|
|
@@ -11,12 +11,12 @@ inputs:
|
|
|
11
11
|
required: true
|
|
12
12
|
|
|
13
13
|
codefox-branch:
|
|
14
|
-
description: 'Git branch of the CodeFox repository to install and run
|
|
14
|
+
description: 'Git branch of the CodeFox repository to install and run.'
|
|
15
15
|
default: 'main'
|
|
16
16
|
required: false
|
|
17
17
|
|
|
18
18
|
github-token:
|
|
19
|
-
description: 'GitHub token used to authenticate with the GitHub API
|
|
19
|
+
description: 'GitHub token used to authenticate with the GitHub API.'
|
|
20
20
|
default: ${{ github.token }}
|
|
21
21
|
required: false
|
|
22
22
|
|
|
@@ -28,6 +28,16 @@ runs:
|
|
|
28
28
|
with:
|
|
29
29
|
python-version: '3.12'
|
|
30
30
|
|
|
31
|
+
- name: Restore CodeFox cache
|
|
32
|
+
uses: actions/cache@v4
|
|
33
|
+
with:
|
|
34
|
+
path: ${{ pwd }}/.codefox/
|
|
35
|
+
key: ${{ runner.os }}-codefox-${{ github.repository }}-${{ github.base_ref }}-${{ inputs.codefox-branch }}
|
|
36
|
+
restore-keys: |
|
|
37
|
+
${{ runner.os }}-codefox-${{ github.repository }}-${{ github.base_ref }}-
|
|
38
|
+
${{ runner.os }}-codefox-${{ github.repository }}-
|
|
39
|
+
${{ runner.os }}-codefox-
|
|
40
|
+
|
|
31
41
|
- name: Install CodeFox
|
|
32
42
|
shell: bash
|
|
33
43
|
run: |
|
|
@@ -20,6 +20,7 @@ class Response:
|
|
|
20
20
|
class BaseAPI(abc.ABC):
|
|
21
21
|
default_embedding = "BAAI/bge-small-en-v1.5"
|
|
22
22
|
default_max_rag_chars = 4096
|
|
23
|
+
default_max_rag_matching_chunks = 12
|
|
23
24
|
default_max_diff_chars = 16_000
|
|
24
25
|
|
|
25
26
|
def __init__(self, config: dict[str, Any] | None = None) -> None:
|
|
@@ -53,6 +54,10 @@ class BaseAPI(abc.ABC):
|
|
|
53
54
|
self.model_config.get("max_rag_chars")
|
|
54
55
|
or self.default_max_rag_chars
|
|
55
56
|
)
|
|
57
|
+
self.max_rag_matching_chunks = (
|
|
58
|
+
self.model_config.get("max_rag_matching_chunks")
|
|
59
|
+
or self.default_max_rag_matching_chunks
|
|
60
|
+
)
|
|
56
61
|
self.max_diff_chars = (
|
|
57
62
|
self.model_config.get("max_diff_chars")
|
|
58
63
|
or self.default_max_diff_chars
|
|
@@ -142,7 +147,7 @@ class BaseAPI(abc.ABC):
|
|
|
142
147
|
rag_context = Parser.get_files_context(
|
|
143
148
|
self.rag,
|
|
144
149
|
diff_text,
|
|
145
|
-
k=
|
|
150
|
+
k=self.max_rag_matching_chunks,
|
|
146
151
|
max_rag_chars=self.max_rag_chars,
|
|
147
152
|
)
|
|
148
153
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from gitlab import Gitlab
|
|
4
|
+
from gitlab.exceptions import GitlabCreateError, GitlabGetError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GitLabBot:
|
|
8
|
+
def __init__(self) -> None:
|
|
9
|
+
self.gitlab_token = os.getenv("GITLAB_TOKEN")
|
|
10
|
+
self.gitlab_url = os.getenv("GITLAB_URL", "https://gitlab.com")
|
|
11
|
+
self.repository = os.getenv("GITLAB_REPOSITORY")
|
|
12
|
+
self.mr_iid = os.getenv("PR_NUMBER")
|
|
13
|
+
|
|
14
|
+
if not self.gitlab_token:
|
|
15
|
+
raise ValueError(
|
|
16
|
+
"GITLAB_TOKEN environment variable is not set. "
|
|
17
|
+
"This token is required to authenticate with the GitLab API."
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
if not self.repository or not self.repository.isdigit():
|
|
21
|
+
raise ValueError(f"Invalid GITLAB_REPOSITORY: {self.repository!r}")
|
|
22
|
+
|
|
23
|
+
if not self.mr_iid or not self.mr_iid.isdigit():
|
|
24
|
+
raise ValueError(
|
|
25
|
+
f"Invalid PR_NUMBER value: {self.mr_iid!r}. "
|
|
26
|
+
"Expected a numeric merge request IID."
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
self.gitlab = Gitlab(
|
|
30
|
+
url=self.gitlab_url,
|
|
31
|
+
private_token=self.gitlab_token,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def send(self, message: str) -> None:
|
|
35
|
+
if not message or not message.strip():
|
|
36
|
+
raise ValueError("Message must not be empty.")
|
|
37
|
+
|
|
38
|
+
repository = self.repository
|
|
39
|
+
mr_iid = self.mr_iid
|
|
40
|
+
|
|
41
|
+
if repository is None or mr_iid is None:
|
|
42
|
+
raise RuntimeError(
|
|
43
|
+
"GitLab project or merge request is not configured."
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
project = self.gitlab.projects.get(int(repository))
|
|
48
|
+
mr = project.mergerequests.get(int(mr_iid))
|
|
49
|
+
mr.notes.create({"body": message})
|
|
50
|
+
except GitlabGetError as exc:
|
|
51
|
+
raise RuntimeError(
|
|
52
|
+
f"Failed to find project '{repository}' "
|
|
53
|
+
f"or merge request IID {mr_iid}."
|
|
54
|
+
) from exc
|
|
55
|
+
except GitlabCreateError as exc:
|
|
56
|
+
raise RuntimeError("Failed to create merge request note.") from exc
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from rich import print
|
|
4
|
+
from rich.markup import escape
|
|
5
|
+
|
|
6
|
+
from codefox.api.base_api import BaseAPI
|
|
7
|
+
from codefox.cli.base_cli import BaseCLI
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Index(BaseCLI):
|
|
11
|
+
def __init__(self, model: type[BaseAPI]):
|
|
12
|
+
self.model = model()
|
|
13
|
+
|
|
14
|
+
def execute(self):
|
|
15
|
+
is_upload, error = self.model.upload_files(os.getcwd())
|
|
16
|
+
if not is_upload:
|
|
17
|
+
print(
|
|
18
|
+
"[red]Failed to index files: " + escape(str(error)) + "[/red]"
|
|
19
|
+
)
|
|
20
|
+
return
|
|
21
|
+
|
|
22
|
+
print("[green]Successful to index files[/green]")
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
+
from typing import Any
|
|
2
3
|
|
|
3
4
|
import yaml
|
|
4
5
|
from dotenv import load_dotenv, set_key
|
|
@@ -11,9 +12,18 @@ from codefox.cli.base_cli import BaseCLI
|
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class Init(BaseCLI):
|
|
14
|
-
def __init__(self,
|
|
15
|
-
|
|
15
|
+
def __init__(self, args: dict[str, Any] | None = None):
|
|
16
|
+
resolved_args = args if args is not None else {}
|
|
17
|
+
|
|
18
|
+
if not resolved_args.get("provider"):
|
|
19
|
+
self.model_enum = self._ask_model()
|
|
20
|
+
else:
|
|
21
|
+
self.model_enum = ModelEnum.by_name(resolved_args["provider"])
|
|
22
|
+
|
|
16
23
|
self.api_class: type[BaseAPI] = self.model_enum.api_class
|
|
24
|
+
|
|
25
|
+
self.args: dict[str, Any] = resolved_args
|
|
26
|
+
|
|
17
27
|
self.config_path = Path(".codefoxenv")
|
|
18
28
|
self.ignore_path = Path(".codefoxignore")
|
|
19
29
|
self.yaml_config_path = Path(".codefox.yml")
|
|
@@ -28,7 +38,10 @@ class Init(BaseCLI):
|
|
|
28
38
|
return ModelEnum.by_name(choice)
|
|
29
39
|
|
|
30
40
|
def execute(self) -> None:
|
|
31
|
-
|
|
41
|
+
if not self.args.get("token"):
|
|
42
|
+
api_key = self._ask_api_key() or ""
|
|
43
|
+
else:
|
|
44
|
+
api_key = self.args["token"]
|
|
32
45
|
|
|
33
46
|
if not self._write_config(api_key):
|
|
34
47
|
return
|
|
@@ -9,6 +9,7 @@ from rich.markup import escape
|
|
|
9
9
|
|
|
10
10
|
from codefox.api.base_api import BaseAPI
|
|
11
11
|
from codefox.bots.github_bot import GitHubBot
|
|
12
|
+
from codefox.bots.gitlab_bot import GitLabBot
|
|
12
13
|
from codefox.cli.base_cli import BaseCLI
|
|
13
14
|
from codefox.cli.list import List
|
|
14
15
|
from codefox.utils.helper import Helper
|
|
@@ -20,8 +21,11 @@ class Scan(BaseCLI):
|
|
|
20
21
|
self.args = args
|
|
21
22
|
|
|
22
23
|
self.github_bot = None
|
|
23
|
-
|
|
24
|
+
self.gitlab_bot = None
|
|
25
|
+
if self.args.get("ci", False) and os.getenv("GITHUB_BOT"):
|
|
24
26
|
self.github_bot = GitHubBot()
|
|
27
|
+
elif self.args.get("ci", False) and os.getenv("GITLAB_TOKEN"):
|
|
28
|
+
self.gitlab_bot = GitLabBot()
|
|
25
29
|
|
|
26
30
|
def execute(self) -> None:
|
|
27
31
|
source_branch, target_branch = self._get_branchs()
|
|
@@ -79,6 +83,10 @@ class Scan(BaseCLI):
|
|
|
79
83
|
response = self.model.execute(diff_text)
|
|
80
84
|
if self.github_bot is not None:
|
|
81
85
|
self.github_bot.send(response.text)
|
|
86
|
+
|
|
87
|
+
if self.gitlab_bot is not None:
|
|
88
|
+
self.gitlab_bot.send(response.text)
|
|
89
|
+
|
|
82
90
|
self.model.remove_files()
|
|
83
91
|
|
|
84
92
|
def _classic_response_answer(self, diff_text: str) -> None:
|
|
@@ -8,6 +8,7 @@ from rich import print
|
|
|
8
8
|
from codefox.api.base_api import BaseAPI
|
|
9
9
|
from codefox.api.model_enum import ModelEnum
|
|
10
10
|
from codefox.cli.clean import Clean
|
|
11
|
+
from codefox.cli.index import Index
|
|
11
12
|
from codefox.cli.init import Init
|
|
12
13
|
from codefox.cli.list import List
|
|
13
14
|
from codefox.cli.scan import Scan
|
|
@@ -35,6 +36,12 @@ class CLIManager:
|
|
|
35
36
|
print(f"[green]CodeFox CLI version {version}[/green]")
|
|
36
37
|
return
|
|
37
38
|
|
|
39
|
+
if self.command == "index":
|
|
40
|
+
api_class = self._get_api_class()
|
|
41
|
+
index = Index(api_class)
|
|
42
|
+
index.execute()
|
|
43
|
+
return
|
|
44
|
+
|
|
38
45
|
if self.command == "list":
|
|
39
46
|
api_class = self._get_api_class()
|
|
40
47
|
list_model = List(api_class, self.args)
|
|
@@ -54,7 +61,7 @@ class CLIManager:
|
|
|
54
61
|
return
|
|
55
62
|
|
|
56
63
|
if self.command == "init":
|
|
57
|
-
init = Init()
|
|
64
|
+
init = Init(self.args or {})
|
|
58
65
|
init.execute()
|
|
59
66
|
return
|
|
60
67
|
|
|
@@ -8,9 +8,9 @@ app = typer.Typer()
|
|
|
8
8
|
|
|
9
9
|
@app.command("scan")
|
|
10
10
|
def scan(
|
|
11
|
-
ci: bool = typer.Option(False, "--ci", help="CI mode"),
|
|
12
|
-
source_branch: str = typer.Option(None, help="Source branch"),
|
|
13
|
-
target_branch: str = typer.Option(None, help="Target branch"),
|
|
11
|
+
ci: bool = typer.Option(False, "--ci", help="CI mode."),
|
|
12
|
+
source_branch: str | None = typer.Option(None, help="Source branch."),
|
|
13
|
+
target_branch: str | None = typer.Option(None, help="Target branch."),
|
|
14
14
|
):
|
|
15
15
|
"""Run AI code review."""
|
|
16
16
|
manager = CLIManager(
|
|
@@ -24,14 +24,32 @@ def scan(
|
|
|
24
24
|
manager.run()
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
@app.command("index")
|
|
28
|
+
def index():
|
|
29
|
+
"""Index files"""
|
|
30
|
+
CLIManager(command="index", args={}).run()
|
|
31
|
+
|
|
32
|
+
|
|
27
33
|
@app.command("init")
|
|
28
|
-
def init(
|
|
34
|
+
def init(
|
|
35
|
+
provider: str | None = typer.Option(None, help="Provider."),
|
|
36
|
+
token: str | None = typer.Option(None, help="Token provider."),
|
|
37
|
+
):
|
|
29
38
|
"""Initialize CodeFox."""
|
|
30
|
-
|
|
39
|
+
manager = CLIManager(
|
|
40
|
+
command="init",
|
|
41
|
+
args={
|
|
42
|
+
"provider": provider,
|
|
43
|
+
"token": token,
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
manager.run()
|
|
31
47
|
|
|
32
48
|
|
|
33
49
|
@app.command("list")
|
|
34
|
-
def list_models(
|
|
50
|
+
def list_models(
|
|
51
|
+
type_model: str = typer.Argument("models", help="Model type."),
|
|
52
|
+
):
|
|
35
53
|
"""List available models."""
|
|
36
54
|
manager = CLIManager(
|
|
37
55
|
command="list",
|
|
@@ -43,7 +61,7 @@ def list_models(type_model: str = typer.Argument("models", help="Model type")):
|
|
|
43
61
|
|
|
44
62
|
|
|
45
63
|
@app.command("clean")
|
|
46
|
-
def clean(type_cache: str = typer.Argument("all", help="Cache type")):
|
|
64
|
+
def clean(type_cache: str = typer.Argument("all", help="Cache type.")):
|
|
47
65
|
"""Clean cache"""
|
|
48
66
|
manager = CLIManager(
|
|
49
67
|
command="clean",
|
|
@@ -65,7 +65,7 @@ class Helper:
|
|
|
65
65
|
source_branch: str | None = None, target_branch: str | None = None
|
|
66
66
|
) -> str | None:
|
|
67
67
|
try:
|
|
68
|
-
repo = git.Repo(".")
|
|
68
|
+
repo = git.Repo(".", search_parent_directories=True)
|
|
69
69
|
|
|
70
70
|
if source_branch and target_branch:
|
|
71
71
|
diff_text = repo.git.diff(
|
|
@@ -75,7 +75,11 @@ class Helper:
|
|
|
75
75
|
diff_text = repo.git.diff()
|
|
76
76
|
|
|
77
77
|
return cast(str | None, diff_text)
|
|
78
|
-
except
|
|
78
|
+
except (
|
|
79
|
+
git.exc.InvalidGitRepositoryError,
|
|
80
|
+
git.exc.NoSuchPathError,
|
|
81
|
+
git.exc.GitCommandError,
|
|
82
|
+
):
|
|
79
83
|
return None
|
|
80
84
|
|
|
81
85
|
# ------------------------------------------------------------------
|
|
@@ -191,39 +191,40 @@ class LocalRAG:
|
|
|
191
191
|
if self.client.collection_exists(self.collection_name):
|
|
192
192
|
self.client.delete_collection(self.collection_name)
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
self.console.print(
|
|
195
195
|
"[magenta]Building Qdrant vector index...[/magenta]"
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
dim: int | None = None
|
|
199
|
+
for i in track(
|
|
200
|
+
range(0, len(texts), batch_size),
|
|
201
|
+
total=(len(texts) + batch_size - 1) // batch_size,
|
|
202
|
+
description="[blue]Generating embeddings...[/blue]",
|
|
196
203
|
):
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
batch = texts[i : i + batch_size]
|
|
204
|
-
emb = np.array(list(self.model.embed(batch)), dtype="float32")
|
|
205
|
-
|
|
206
|
-
if dim is None:
|
|
207
|
-
dim = emb.shape[1]
|
|
208
|
-
self.client.create_collection(
|
|
209
|
-
collection_name=self.collection_name,
|
|
210
|
-
vectors_config=VectorParams(
|
|
211
|
-
size=dim, distance=Distance.COSINE
|
|
212
|
-
),
|
|
213
|
-
)
|
|
214
|
-
|
|
215
|
-
points = [
|
|
216
|
-
PointStruct(
|
|
217
|
-
id=j,
|
|
218
|
-
vector=vec.tolist(),
|
|
219
|
-
payload={"path": self.files[j]["path"]},
|
|
220
|
-
)
|
|
221
|
-
for j, vec in enumerate(emb, start=i)
|
|
222
|
-
]
|
|
223
|
-
self.client.upsert(
|
|
204
|
+
batch = texts[i : i + batch_size]
|
|
205
|
+
emb = np.array(list(self.model.embed(batch)), dtype="float32")
|
|
206
|
+
|
|
207
|
+
if dim is None:
|
|
208
|
+
dim = emb.shape[1]
|
|
209
|
+
self.client.create_collection(
|
|
224
210
|
collection_name=self.collection_name,
|
|
225
|
-
|
|
211
|
+
vectors_config=VectorParams(
|
|
212
|
+
size=dim, distance=Distance.COSINE
|
|
213
|
+
),
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
points = [
|
|
217
|
+
PointStruct(
|
|
218
|
+
id=j,
|
|
219
|
+
vector=vec.tolist(),
|
|
220
|
+
payload={"path": self.files[j]["path"]},
|
|
226
221
|
)
|
|
222
|
+
for j, vec in enumerate(emb, start=i)
|
|
223
|
+
]
|
|
224
|
+
self.client.upsert(
|
|
225
|
+
collection_name=self.collection_name,
|
|
226
|
+
points=points,
|
|
227
|
+
)
|
|
227
228
|
|
|
228
229
|
self.console.print("[green]✓[/green] Qdrant semantic index built.")
|
|
229
230
|
self.console.print(
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
codefox_review:
|
|
2
|
+
stage: review
|
|
3
|
+
image: python:3.12-slim
|
|
4
|
+
|
|
5
|
+
variables:
|
|
6
|
+
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
|
|
7
|
+
CODEFOX_BRANCH: "dev-docs"
|
|
8
|
+
|
|
9
|
+
cache:
|
|
10
|
+
key: codefox-$CI_PROJECT_ID
|
|
11
|
+
paths:
|
|
12
|
+
- ".codefox/"
|
|
13
|
+
- ".cache/pip/"
|
|
14
|
+
|
|
15
|
+
before_script:
|
|
16
|
+
- apt-get update && apt-get install -y --no-install-recommends git curl ca-certificates && rm -rf /var/lib/apt/lists/*
|
|
17
|
+
- python -m pip install --upgrade pip
|
|
18
|
+
- pip install "git+https://github.com/URLbug/CodeFox-CLI.git@${CODEFOX_BRANCH}"
|
|
19
|
+
- |
|
|
20
|
+
umask 077
|
|
21
|
+
{
|
|
22
|
+
echo "CODEFOX_API_KEY=$CODEFOX_API_KEY"
|
|
23
|
+
echo "GITLAB_TOKEN=${GITLAB_TOKEN}"
|
|
24
|
+
echo "GITLAB_URL=${CI_SERVER_URL}"
|
|
25
|
+
echo "GITLAB_REPOSITORY=${CI_PROJECT_ID}"
|
|
26
|
+
echo "PR_NUMBER=${CI_MERGE_REQUEST_IID}"
|
|
27
|
+
} > "$CI_PROJECT_DIR/.codefoxenv"
|
|
28
|
+
|
|
29
|
+
script:
|
|
30
|
+
- git fetch origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME":"$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" || true
|
|
31
|
+
- git fetch origin "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME":"$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" || true
|
|
32
|
+
- codefox scan --target-branch "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" --source-branch "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" --ci
|
|
33
|
+
|
|
34
|
+
rules:
|
|
35
|
+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "codefox"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.5"
|
|
4
4
|
description = "CodeFox CLI - code auditing and code review tool"
|
|
5
5
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
6
6
|
requires-python = ">=3.11"
|
|
@@ -50,6 +50,7 @@ dependencies = [
|
|
|
50
50
|
"psutil==7.2.2",
|
|
51
51
|
"PyGithub==2.8.1",
|
|
52
52
|
"pygments==2.19.2",
|
|
53
|
+
"python-gitlab==8.1.0",
|
|
53
54
|
]
|
|
54
55
|
|
|
55
56
|
[project.optional-dependencies]
|
|
@@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text(encoding="utf-8") if (HERE / "README.md"
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name="codefox",
|
|
10
|
-
version="0.4.
|
|
10
|
+
version="0.4.5",
|
|
11
11
|
description="CodeFox CLI - code auditing and code review tool",
|
|
12
12
|
long_description=README,
|
|
13
13
|
long_description_content_type="text/markdown",
|
|
@@ -50,6 +50,7 @@ setup(
|
|
|
50
50
|
"psutil==7.2.2",
|
|
51
51
|
"PyGithub==2.8.1",
|
|
52
52
|
"pygments==2.19.2",
|
|
53
|
+
"python-gitlab==8.1.0",
|
|
53
54
|
],
|
|
54
55
|
entry_points={
|
|
55
56
|
"console_scripts": [
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Tests for GitLab bot."""
|
|
2
|
+
|
|
3
|
+
from unittest.mock import MagicMock, patch
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from codefox.bots.gitlab_bot import GitLabBot
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_send_creates_merge_request_note(
|
|
11
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
12
|
+
) -> None:
|
|
13
|
+
monkeypatch.setenv("GITLAB_TOKEN", "token")
|
|
14
|
+
monkeypatch.setenv("GITLAB_REPOSITORY", "123")
|
|
15
|
+
monkeypatch.setenv("PR_NUMBER", "456")
|
|
16
|
+
|
|
17
|
+
with patch("codefox.bots.gitlab_bot.Gitlab") as mock_gitlab_class:
|
|
18
|
+
mock_project = MagicMock()
|
|
19
|
+
mock_mr = MagicMock()
|
|
20
|
+
mock_gitlab = mock_gitlab_class.return_value
|
|
21
|
+
mock_gitlab.projects.get.return_value = mock_project
|
|
22
|
+
mock_project.mergerequests.get.return_value = mock_mr
|
|
23
|
+
|
|
24
|
+
bot = GitLabBot()
|
|
25
|
+
bot.send("hello")
|
|
26
|
+
|
|
27
|
+
mock_gitlab_class.assert_called_once_with(
|
|
28
|
+
url="https://gitlab.com",
|
|
29
|
+
private_token="token",
|
|
30
|
+
)
|
|
31
|
+
mock_gitlab.projects.get.assert_called_once_with(123)
|
|
32
|
+
mock_project.mergerequests.get.assert_called_once_with(456)
|
|
33
|
+
mock_mr.notes.create.assert_called_once_with({"body": "hello"})
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_send_rejects_empty_message(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
37
|
+
monkeypatch.setenv("GITLAB_TOKEN", "token")
|
|
38
|
+
monkeypatch.setenv("GITLAB_REPOSITORY", "123")
|
|
39
|
+
monkeypatch.setenv("PR_NUMBER", "456")
|
|
40
|
+
|
|
41
|
+
with patch("codefox.bots.gitlab_bot.Gitlab"):
|
|
42
|
+
bot = GitLabBot()
|
|
43
|
+
|
|
44
|
+
with pytest.raises(ValueError, match="Message must not be empty"):
|
|
45
|
+
bot.send(" ")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_send_raises_when_identifiers_are_not_configured(
|
|
49
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
50
|
+
) -> None:
|
|
51
|
+
monkeypatch.setenv("GITLAB_TOKEN", "token")
|
|
52
|
+
monkeypatch.setenv("GITLAB_REPOSITORY", "123")
|
|
53
|
+
monkeypatch.setenv("PR_NUMBER", "456")
|
|
54
|
+
|
|
55
|
+
with patch("codefox.bots.gitlab_bot.Gitlab") as mock_gitlab_class:
|
|
56
|
+
bot = GitLabBot()
|
|
57
|
+
bot.repository = None
|
|
58
|
+
|
|
59
|
+
with pytest.raises(
|
|
60
|
+
RuntimeError,
|
|
61
|
+
match="GitLab project or merge request is not configured",
|
|
62
|
+
):
|
|
63
|
+
bot.send("hello")
|
|
64
|
+
|
|
65
|
+
mock_gitlab_class.return_value.projects.get.assert_not_called()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Tests for Init command."""
|
|
2
|
+
|
|
3
|
+
from unittest.mock import patch
|
|
4
|
+
|
|
5
|
+
from codefox.api.model_enum import ModelEnum
|
|
6
|
+
from codefox.cli.init import Init
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_init_normalizes_none_args() -> None:
|
|
10
|
+
with patch.object(Init, "_ask_model", return_value=ModelEnum.GEMINI):
|
|
11
|
+
init = Init()
|
|
12
|
+
|
|
13
|
+
assert init.model_enum is ModelEnum.GEMINI
|
|
14
|
+
assert init.api_class is ModelEnum.GEMINI.api_class
|
|
15
|
+
assert init.args == {}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_execute_uses_provider_and_token_from_args() -> None:
|
|
19
|
+
init = Init({"provider": "gemini", "token": "test-token"})
|
|
20
|
+
|
|
21
|
+
with (
|
|
22
|
+
patch.object(init, "_ask_api_key") as mock_ask_api_key,
|
|
23
|
+
patch.object(init, "_write_config", return_value=True) as mock_write,
|
|
24
|
+
patch.object(init, "_ensure_ignore_file") as mock_ignore,
|
|
25
|
+
patch.object(init, "_ensure_yaml_config") as mock_yaml,
|
|
26
|
+
patch.object(init, "_ensure_gitignore") as mock_gitignore,
|
|
27
|
+
patch.object(
|
|
28
|
+
init, "_check_connection", return_value=True
|
|
29
|
+
) as mock_check,
|
|
30
|
+
):
|
|
31
|
+
init.execute()
|
|
32
|
+
|
|
33
|
+
mock_ask_api_key.assert_not_called()
|
|
34
|
+
mock_write.assert_called_once_with("test-token")
|
|
35
|
+
mock_ignore.assert_called_once()
|
|
36
|
+
mock_yaml.assert_called_once()
|
|
37
|
+
mock_gitignore.assert_called_once()
|
|
38
|
+
mock_check.assert_called_once()
|
|
@@ -217,7 +217,7 @@ wheels = [
|
|
|
217
217
|
|
|
218
218
|
[[package]]
|
|
219
219
|
name = "codefox"
|
|
220
|
-
version = "0.4.
|
|
220
|
+
version = "0.4.1"
|
|
221
221
|
source = { editable = "." }
|
|
222
222
|
dependencies = [
|
|
223
223
|
{ name = "bm25s" },
|
|
@@ -232,6 +232,7 @@ dependencies = [
|
|
|
232
232
|
{ name = "pygithub" },
|
|
233
233
|
{ name = "pygments" },
|
|
234
234
|
{ name = "python-dotenv" },
|
|
235
|
+
{ name = "python-gitlab" },
|
|
235
236
|
{ name = "pyyaml" },
|
|
236
237
|
{ name = "qdrant-client" },
|
|
237
238
|
{ name = "requests" },
|
|
@@ -267,6 +268,7 @@ requires-dist = [
|
|
|
267
268
|
{ name = "pytest", marker = "extra == 'dev'", specifier = ">=8.0" },
|
|
268
269
|
{ name = "pytest-cov", marker = "extra == 'dev'", specifier = ">=4.0" },
|
|
269
270
|
{ name = "python-dotenv", specifier = "==1.2.1" },
|
|
271
|
+
{ name = "python-gitlab", specifier = "==8.1.0" },
|
|
270
272
|
{ name = "pyyaml", specifier = "==6.0.3" },
|
|
271
273
|
{ name = "qdrant-client", specifier = ">=1.7.0" },
|
|
272
274
|
{ name = "requests", specifier = ">=2.28.0" },
|
|
@@ -1742,6 +1744,19 @@ wheels = [
|
|
|
1742
1744
|
{ url = "https://files.pythonhosted.org/packages/14/1b/a298b06749107c305e1fe0f814c6c74aea7b2f1e10989cb30f544a1b3253/python_dotenv-1.2.1-py3-none-any.whl", hash = "sha256:b81ee9561e9ca4004139c6cbba3a238c32b03e4894671e181b671e8cb8425d61", size = 21230, upload-time = "2025-10-26T15:12:09.109Z" },
|
|
1743
1745
|
]
|
|
1744
1746
|
|
|
1747
|
+
[[package]]
|
|
1748
|
+
name = "python-gitlab"
|
|
1749
|
+
version = "8.1.0"
|
|
1750
|
+
source = { registry = "https://pypi.org/simple" }
|
|
1751
|
+
dependencies = [
|
|
1752
|
+
{ name = "requests" },
|
|
1753
|
+
{ name = "requests-toolbelt" },
|
|
1754
|
+
]
|
|
1755
|
+
sdist = { url = "https://files.pythonhosted.org/packages/20/1d/a62fea1f3312fd9e58af41466ae072796a09684dd0cd825cc042ba39488c/python_gitlab-8.1.0.tar.gz", hash = "sha256:660f15e3f889ec430797d260322bc61d90f8d90accfc10ba37593b11aed371bd", size = 401576, upload-time = "2026-02-28T01:26:32.757Z" }
|
|
1756
|
+
wheels = [
|
|
1757
|
+
{ url = "https://files.pythonhosted.org/packages/79/d4/9848be62ef23fcac203f4386faf43a2cc13a4888447b3f5fbf7346f31374/python_gitlab-8.1.0-py3-none-any.whl", hash = "sha256:b1a59e81e5e0363185b446a707dc92c27ee8bf1fc14ce75ed8eafa58cbdce63a", size = 144498, upload-time = "2026-02-28T01:26:31.14Z" },
|
|
1758
|
+
]
|
|
1759
|
+
|
|
1745
1760
|
[[package]]
|
|
1746
1761
|
name = "pywin32"
|
|
1747
1762
|
version = "311"
|
|
@@ -1953,6 +1968,18 @@ wheels = [
|
|
|
1953
1968
|
{ url = "https://files.pythonhosted.org/packages/1e/db/4254e3eabe8020b458f1a747140d32277ec7a271daf1d235b70dc0b4e6e3/requests-2.32.5-py3-none-any.whl", hash = "sha256:2462f94637a34fd532264295e186976db0f5d453d1cdd31473c85a6a161affb6", size = 64738, upload-time = "2025-08-18T20:46:00.542Z" },
|
|
1954
1969
|
]
|
|
1955
1970
|
|
|
1971
|
+
[[package]]
|
|
1972
|
+
name = "requests-toolbelt"
|
|
1973
|
+
version = "1.0.0"
|
|
1974
|
+
source = { registry = "https://pypi.org/simple" }
|
|
1975
|
+
dependencies = [
|
|
1976
|
+
{ name = "requests" },
|
|
1977
|
+
]
|
|
1978
|
+
sdist = { url = "https://files.pythonhosted.org/packages/f3/61/d7545dafb7ac2230c70d38d31cbfe4cc64f7144dc41f6e4e4b78ecd9f5bb/requests-toolbelt-1.0.0.tar.gz", hash = "sha256:7681a0a3d047012b5bdc0ee37d7f8f07ebe76ab08caeccfc3921ce23c88d5bc6", size = 206888, upload-time = "2023-05-01T04:11:33.229Z" }
|
|
1979
|
+
wheels = [
|
|
1980
|
+
{ url = "https://files.pythonhosted.org/packages/3f/51/d4db610ef29373b879047326cbf6fa98b6c1969d6f6dc423279de2b1be2c/requests_toolbelt-1.0.0-py2.py3-none-any.whl", hash = "sha256:cccfdd665f0a24fcf4726e690f65639d272bb0637b9b92dfd91a5568ccf6bd06", size = 54481, upload-time = "2023-05-01T04:11:28.427Z" },
|
|
1981
|
+
]
|
|
1982
|
+
|
|
1956
1983
|
[[package]]
|
|
1957
1984
|
name = "rich"
|
|
1958
1985
|
version = "14.3.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|