codespector 0.2.0__tar.gz → 1.0.1__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.
Files changed (24) hide show
  1. {codespector-0.2.0 → codespector-1.0.1}/PKG-INFO +25 -17
  2. codespector-1.0.1/README.md +85 -0
  3. {codespector-0.2.0 → codespector-1.0.1}/cicd_examples/.gitlab-ci.yml +15 -6
  4. {codespector-0.2.0 → codespector-1.0.1}/codespector/codespector.py +5 -0
  5. {codespector-0.2.0 → codespector-1.0.1}/codespector/local.py +5 -2
  6. {codespector-0.2.0 → codespector-1.0.1}/codespector/main.py +8 -1
  7. {codespector-0.2.0 → codespector-1.0.1}/pyproject.toml +1 -1
  8. codespector-0.2.0/README.md +0 -77
  9. codespector-0.2.0/cicd_examples/.github-ci.yml +0 -64
  10. {codespector-0.2.0 → codespector-1.0.1}/.github/workflows/build-publish.yml +0 -0
  11. {codespector-0.2.0 → codespector-1.0.1}/.github/workflows/tests.yml +0 -0
  12. {codespector-0.2.0 → codespector-1.0.1}/.gitignore +0 -0
  13. {codespector-0.2.0 → codespector-1.0.1}/LICENSE +0 -0
  14. {codespector-0.2.0 → codespector-1.0.1}/Makefile +0 -0
  15. {codespector-0.2.0 → codespector-1.0.1}/codespector/__init__.py +0 -0
  16. {codespector-0.2.0 → codespector-1.0.1}/codespector/base.py +0 -0
  17. {codespector-0.2.0 → codespector-1.0.1}/codespector/errors.py +0 -0
  18. {codespector-0.2.0 → codespector-1.0.1}/codespector/reviewer.py +0 -0
  19. {codespector-0.2.0 → codespector-1.0.1}/codespector/types.py +0 -0
  20. {codespector-0.2.0 → codespector-1.0.1}/tests/__init__.py +0 -0
  21. {codespector-0.2.0 → codespector-1.0.1}/tests/conftest.py +0 -0
  22. {codespector-0.2.0 → codespector-1.0.1}/tests/unit/__init__.py +0 -0
  23. {codespector-0.2.0 → codespector-1.0.1}/tests/unit/test_codespector.py +0 -0
  24. {codespector-0.2.0 → codespector-1.0.1}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codespector
3
- Version: 0.2.0
3
+ Version: 1.0.1
4
4
  Summary: Assistant for reviewing your code
5
5
  Project-URL: Repository, https://github.com/Vladimir-Titov/codespector
6
6
  Project-URL: Issues, https://github.com/Vladimir-Titov/codespector/issues
@@ -50,18 +50,23 @@ You can use the `codespector` command to start a code review. Below are the avai
50
50
  Usage: codespector [OPTIONS]
51
51
 
52
52
  Options:
53
- --system-content TEXT Content which used in system field for agent
54
- [default: Ты код ревьювер. Отвечай на русском языке.]
55
- --output-dir TEXT Select the output directory [default: codespector]
56
- -b, --compare-branch TEXT Select the branch to compare the current one with
57
- [default: develop]
58
- --chat-agent [codestral|chatgpt]
59
- Choose the chat agent to use [default: codestral]
60
- --chat-model TEXT Choose the chat model to use
61
- --chat-token TEXT Chat agent token
62
- --mode [local] Choose the mode of the application [default: local]
63
- --version Show the version and exit.
64
- --help Show this message and exit.
53
+ --chat-token TEXT Chat agent token [env var: CODESPECTOR_CHAT_TOKEN]
54
+ --chat-model TEXT Choose the chat model to use [env var: CODESPECTOR_CHAT_MODEL]
55
+ --chat-agent TEXT Choose the chat agent to use (codestral, chatgpt, deepseek)
56
+ or set your own [env var: CODESPECTOR_CHAT_AGENT]
57
+ -b, --compare-branch TEXT Select the branch to compare the current one with
58
+ --output-dir TEXT Select the output directory [default: codespector]
59
+ [env var: CODESPECTOR_OUTPUT_DIR]
60
+ --system-content TEXT Content which used in system field for agent
61
+ [env var: CODESPECTOR_SYSTEM_CONTENT]
62
+ --prompt-content TEXT Prompt content which included to review prompt
63
+ [env var: CODESPECTOR_PROMPT_CONTENT]
64
+ --result-file TEXT Set file for saving the result
65
+ [env var: CODESPECTOR_RESULT_FILE]
66
+ --exclude-file-ext LIST Exclude file extensions from the review
67
+ [env var: CODESPECTOR_EXCLUDE_FILE_EXT]
68
+ --version Show the version and exit.
69
+ --help Show this message and exit.
65
70
  ```
66
71
 
67
72
  ### Example
@@ -69,7 +74,7 @@ Options:
69
74
  To run a code review, use the following command:
70
75
 
71
76
  ```sh
72
- codespector --chat-token YOUR_CHAT_TOKEN --chat-agent codestral --compare-branch develop
77
+ codespector --chat-token YOUR_CHAT_TOKEN --chat-agent codestral --compare-branch develop --result-file result.md --system-content "system content" --prompt-content "prompt content"
73
78
  ```
74
79
 
75
80
  ## Configuration
@@ -77,11 +82,14 @@ codespector --chat-token YOUR_CHAT_TOKEN --chat-agent codestral --compare-branch
77
82
  You can also configure CodeSpector using environment variables. Create a `.env` file in the root directory of your project with the following content:
78
83
 
79
84
  ```
80
- CODESPECTOR_SYSTEM_CONTENT=Ты код ревьювер. Отвечай на русском языке.
85
+ CODESPECTOR_CHAT_TOKEN=your_token
81
86
  CODESPECTOR_OUTPUT_DIR=codespector
87
+ CODESPECTOR_SYSTEM_CONTENT="Ты код ревьювер. Отвечай на русском"
88
+ CODESPECTOR_PROMPT_CONTENT="Оцени код на безопасноть, соблюдение лучших техник"
89
+ CODESPECTOR_RESULT_FILE="result.md"
82
90
  CODESPECTOR_CHAT_AGENT=codestral
83
- CODESPECTOR_CHAT_MODEL=codestral-latest
84
- CODESPECTOR_CHAT_TOKEN=YOUR_CHAT_TOKEN
91
+ CODESPECTOR_CHAT_MODEL=your_model
92
+ CODESPECTOR_EXCLUDE_FILE_EXT=.pyc,.pyo
85
93
  ```
86
94
 
87
95
  ## Makefile Commands
@@ -0,0 +1,85 @@
1
+ # CodeSpector
2
+
3
+ CodeSpector is a Python package designed to review code changes for quality and security issues using AI chat agents. It supports different chat agents like Codestral and ChatGPT.
4
+
5
+ ## Features
6
+
7
+ - Automated code review using AI chat agents.
8
+ - Supports multiple chat agents and models.
9
+ - Generates detailed review reports in markdown format.
10
+ - Configurable via environment variables and command-line options.
11
+
12
+ ## Installation
13
+
14
+ To install the package, use the following command:
15
+
16
+ ```sh
17
+ pip install codespector
18
+ ```
19
+
20
+ ```sh
21
+ uv add codespector
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Command-Line Interface
27
+
28
+ You can use the `codespector` command to start a code review. Below are the available options:
29
+
30
+ ```sh
31
+ Usage: codespector [OPTIONS]
32
+
33
+ Options:
34
+ --chat-token TEXT Chat agent token [env var: CODESPECTOR_CHAT_TOKEN]
35
+ --chat-model TEXT Choose the chat model to use [env var: CODESPECTOR_CHAT_MODEL]
36
+ --chat-agent TEXT Choose the chat agent to use (codestral, chatgpt, deepseek)
37
+ or set your own [env var: CODESPECTOR_CHAT_AGENT]
38
+ -b, --compare-branch TEXT Select the branch to compare the current one with
39
+ --output-dir TEXT Select the output directory [default: codespector]
40
+ [env var: CODESPECTOR_OUTPUT_DIR]
41
+ --system-content TEXT Content which used in system field for agent
42
+ [env var: CODESPECTOR_SYSTEM_CONTENT]
43
+ --prompt-content TEXT Prompt content which included to review prompt
44
+ [env var: CODESPECTOR_PROMPT_CONTENT]
45
+ --result-file TEXT Set file for saving the result
46
+ [env var: CODESPECTOR_RESULT_FILE]
47
+ --exclude-file-ext LIST Exclude file extensions from the review
48
+ [env var: CODESPECTOR_EXCLUDE_FILE_EXT]
49
+ --version Show the version and exit.
50
+ --help Show this message and exit.
51
+ ```
52
+
53
+ ### Example
54
+
55
+ To run a code review, use the following command:
56
+
57
+ ```sh
58
+ codespector --chat-token YOUR_CHAT_TOKEN --chat-agent codestral --compare-branch develop --result-file result.md --system-content "system content" --prompt-content "prompt content"
59
+ ```
60
+
61
+ ## Configuration
62
+
63
+ You can also configure CodeSpector using environment variables. Create a `.env` file in the root directory of your project with the following content:
64
+
65
+ ```
66
+ CODESPECTOR_CHAT_TOKEN=your_token
67
+ CODESPECTOR_OUTPUT_DIR=codespector
68
+ CODESPECTOR_SYSTEM_CONTENT="Ты код ревьювер. Отвечай на русском"
69
+ CODESPECTOR_PROMPT_CONTENT="Оцени код на безопасноть, соблюдение лучших техник"
70
+ CODESPECTOR_RESULT_FILE="result.md"
71
+ CODESPECTOR_CHAT_AGENT=codestral
72
+ CODESPECTOR_CHAT_MODEL=your_model
73
+ CODESPECTOR_EXCLUDE_FILE_EXT=.pyc,.pyo
74
+ ```
75
+
76
+ ## Makefile Commands
77
+
78
+ - `lint`: Run linting and formatting checks.
79
+ - `format`: Format the code.
80
+ - `fix`: Fix linting issues and format the code.
81
+ - `test`: Run the tests.
82
+
83
+ ## License
84
+
85
+ This project is licensed under the MIT License. See the `LICENSE` file for more details.
@@ -4,8 +4,9 @@ workflow:
4
4
 
5
5
  variables:
6
6
  GIT_DEPTH: 0
7
- CODESPECTOR_RESULT_FILE: "codespector/result.md"
8
- CODESPECTOR_COMBINED_FILE: "codespector/combined.json"
7
+ CODESPECTOR_RESULT_FILEPATH: "codespector/result.md"
8
+ CODESPECTOR_COMBINED_FILEPATH: "codespector/combined.json"
9
+
9
10
 
10
11
  stages:
11
12
  - codespector
@@ -17,9 +18,17 @@ codespector-job:
17
18
  - apt-get update && apt-get install -y jq
18
19
  - git fetch --no-tags origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
19
20
  - pip install codespector
20
- - codespector --chat-token $CODESPECTOR_CHAT_TOKEN --chat-agent codestral --compare-branch origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD
21
21
  - |
22
- COMMENT_CONTENT=$(cat ${CODESPECTOR_RESULT_FILE} | jq -Rs .)
22
+ codespector \
23
+ --chat-token "$CODESPECTOR_CHAT_TOKEN" \
24
+ --chat-agent "$CODESPECTOR_CHAT_AGENT" \
25
+ --compare-branch "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD" \
26
+ --result-file "$CODESPECTOR_RESULT_FILE" \
27
+ --system-content "$CODESCPECTOR_SYSTEM_CONTENT" \
28
+ --prompt-content "$CODESPECTOR_PROMPT_CONTENT"
29
+
30
+ - |
31
+ COMMENT_CONTENT=$(cat ${CODESPECTOR_RESULT_FILEPATH} | jq -Rs .)
23
32
  echo "Posting comment to MR..."
24
33
  curl -X POST \
25
34
  --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
@@ -28,6 +37,6 @@ codespector-job:
28
37
  "$CI_API_V4_URL/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes"
29
38
  artifacts:
30
39
  paths:
31
- - ${CODESPECTOR_RESULT_FILE}
32
- - ${CODESPECTOR_COMBINED_FILE}
40
+ - ${CODESPECTOR_RESULT_FILEPATH}
41
+ - ${CODESPECTOR_COMBINED_FILEPATH}
33
42
  expire_in: 10 minutes
@@ -18,6 +18,7 @@ class CodeSpector:
18
18
  result_file: str,
19
19
  output_dir: str,
20
20
  chat_model: str | None = None,
21
+ exclude_file_ext: list[str] | None = None,
21
22
  ):
22
23
  self.chat_token = chat_token
23
24
  self.chat_agent = chat_agent
@@ -30,6 +31,7 @@ class CodeSpector:
30
31
  self.pipeline = pipeline
31
32
  self.result_file = result_file
32
33
  self.chat_model = chat_model
34
+ self.exclude_file_exc: list[str] | None = (None,)
33
35
 
34
36
  @classmethod
35
37
  def create(
@@ -42,6 +44,7 @@ class CodeSpector:
42
44
  result_file: str,
43
45
  output_dir: str,
44
46
  chat_model: str | None = None,
47
+ exclude_file_ext: list[str] | None = None,
45
48
  ) -> 'CodeSpector':
46
49
  agent_info = AgentInfo.create(
47
50
  chat_agent=chat_agent,
@@ -51,6 +54,7 @@ class CodeSpector:
51
54
  data_preparer = CodeSpectorDataPreparer(
52
55
  output_dir=output_dir,
53
56
  compare_branch=compare_branch,
57
+ exclude_file_ext=exclude_file_ext,
54
58
  )
55
59
  reviewer = CodeSpectorReviewer(
56
60
  diff_file=data_preparer.combined_file,
@@ -77,6 +81,7 @@ class CodeSpector:
77
81
  pipeline=pipeline,
78
82
  output_dir=output_dir,
79
83
  result_file=result_file,
84
+ exclude_file_ext=exclude_file_ext,
80
85
  )
81
86
 
82
87
  def review(self):
@@ -10,9 +10,11 @@ class CodeSpectorDataPreparer(BasePipe):
10
10
  self,
11
11
  output_dir: str,
12
12
  compare_branch: str,
13
+ exclude_file_ext: list[str] | None = None,
13
14
  ):
14
15
  self.output_dir = output_dir
15
16
  self.compare_branch = compare_branch
17
+ self.exclude_file_ext = exclude_file_ext
16
18
 
17
19
  self.original_files_tmp = 'original_files_tmp.json'
18
20
  self.code_changes_only = 'code_changes_only.txt'
@@ -61,8 +63,9 @@ class CodeSpectorDataPreparer(BasePipe):
61
63
  result = {'original files': []}
62
64
 
63
65
  for file in changed_files:
64
- if not file.endswith('.py'):
65
- continue
66
+ if self.exclude_file_ext:
67
+ if file.endswith(tuple(self.exclude_file_ext)):
68
+ continue
66
69
 
67
70
  if os.path.isfile(file):
68
71
  with open(file, 'r', encoding='utf-8') as f:
@@ -11,6 +11,13 @@ env = Env()
11
11
  env.read_env(path=str(BASE_PATH / '.env'))
12
12
 
13
13
 
14
+ @click.option(
15
+ '--exclude-file-ext',
16
+ type=list,
17
+ envvar='CODESPECTOR_EXCLUDE_FILE_EXT',
18
+ help='Exclude file extensions from the review',
19
+ show_envvar=True,
20
+ )
14
21
  @click.option(
15
22
  '--result-file',
16
23
  type=str,
@@ -50,7 +57,7 @@ env.read_env(path=str(BASE_PATH / '.env'))
50
57
  '--chat-agent',
51
58
  envvar='CODESPECTOR_CHAT_AGENT',
52
59
  show_envvar=True,
53
- help='Choose the chat agent to use you can use one from [codestral, chatgpr, deepseek]. Or set yours chat agent',
60
+ help='Choose the chat agent to use you can use one from [codestral, chatgpt, deepseek]. Or set yours chat agent',
54
61
  )
55
62
  @click.option(
56
63
  '--chat-model',
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codespector"
3
- version = "0.2.0"
3
+ version = "1.0.1"
4
4
  authors = [
5
5
  { name = "vtitov", email = "v.v.titov94@gmail.com" }
6
6
  ]
@@ -1,77 +0,0 @@
1
- # CodeSpector
2
-
3
- CodeSpector is a Python package designed to review code changes for quality and security issues using AI chat agents. It supports different chat agents like Codestral and ChatGPT.
4
-
5
- ## Features
6
-
7
- - Automated code review using AI chat agents.
8
- - Supports multiple chat agents and models.
9
- - Generates detailed review reports in markdown format.
10
- - Configurable via environment variables and command-line options.
11
-
12
- ## Installation
13
-
14
- To install the package, use the following command:
15
-
16
- ```sh
17
- pip install codespector
18
- ```
19
-
20
- ```sh
21
- uv add codespector
22
- ```
23
-
24
- ## Usage
25
-
26
- ### Command-Line Interface
27
-
28
- You can use the `codespector` command to start a code review. Below are the available options:
29
-
30
- ```sh
31
- Usage: codespector [OPTIONS]
32
-
33
- Options:
34
- --system-content TEXT Content which used in system field for agent
35
- [default: Ты код ревьювер. Отвечай на русском языке.]
36
- --output-dir TEXT Select the output directory [default: codespector]
37
- -b, --compare-branch TEXT Select the branch to compare the current one with
38
- [default: develop]
39
- --chat-agent [codestral|chatgpt]
40
- Choose the chat agent to use [default: codestral]
41
- --chat-model TEXT Choose the chat model to use
42
- --chat-token TEXT Chat agent token
43
- --mode [local] Choose the mode of the application [default: local]
44
- --version Show the version and exit.
45
- --help Show this message and exit.
46
- ```
47
-
48
- ### Example
49
-
50
- To run a code review, use the following command:
51
-
52
- ```sh
53
- codespector --chat-token YOUR_CHAT_TOKEN --chat-agent codestral --compare-branch develop
54
- ```
55
-
56
- ## Configuration
57
-
58
- You can also configure CodeSpector using environment variables. Create a `.env` file in the root directory of your project with the following content:
59
-
60
- ```
61
- CODESPECTOR_SYSTEM_CONTENT=Ты код ревьювер. Отвечай на русском языке.
62
- CODESPECTOR_OUTPUT_DIR=codespector
63
- CODESPECTOR_CHAT_AGENT=codestral
64
- CODESPECTOR_CHAT_MODEL=codestral-latest
65
- CODESPECTOR_CHAT_TOKEN=YOUR_CHAT_TOKEN
66
- ```
67
-
68
- ## Makefile Commands
69
-
70
- - `lint`: Run linting and formatting checks.
71
- - `format`: Format the code.
72
- - `fix`: Fix linting issues and format the code.
73
- - `test`: Run the tests.
74
-
75
- ## License
76
-
77
- This project is licensed under the MIT License. See the `LICENSE` file for more details.
@@ -1,64 +0,0 @@
1
- name: Codespector Review
2
-
3
- on:
4
- pull_request:
5
- types: [opened, synchronize]
6
-
7
- env:
8
- CODESPECTOR_RESULT_FILE: "codespector/result.md"
9
- CODESPECTOR_COMBINED_FILE: "codespector/combined.json"
10
-
11
- jobs:
12
- codespector:
13
- runs-on: ubuntu-latest
14
-
15
- steps:
16
- - uses: actions/checkout@v4
17
- with:
18
- fetch-depth: 0
19
-
20
- - name: Set up Python
21
- uses: actions/setup-python@v5
22
- with:
23
- python-version: '3.12'
24
-
25
- - name: Install dependencies
26
- run: |
27
- sudo apt-get update
28
- sudo apt-get install -y jq
29
- pip install codespector
30
-
31
- - name: Fetch target branch
32
- run: git fetch origin ${{ github.base_ref }}
33
-
34
- - name: Run Codespector
35
- env:
36
- CODESPECTOR_CHAT_TOKEN: ${{ secrets.CODESPECTOR_CHAT_TOKEN }}
37
- CODESPECTOR_SYSTEM_CONTENT: ${{ secrets.CODESPECTOR_SYSTEM_CONTENT }}
38
- CODESPECTOR_PROMPT_CONTENT: ${{ secrets.CODESPECTOR_PROMPT_CONTENT }}
39
- CODESPECTOR_RESULT_FILE: ${{ secrets.CODESPECTOR_RESULT_FILE }}
40
- CODESPECTOR_CHAT_AGENT: ${{ secrets.CODESPECTOR_CHAT_AGENT }}
41
- run: |
42
- codespector \
43
- --chat-token $CODESPECTOR_CHAT_TOKEN \
44
- --chat-agent $CODESPECTOR_CHAT_AGENT \
45
- --compare-branch origin/${{ github.base_ref }}...HEAD
46
- --system-content $CODESPECTOR_SYSTEM_CONTENT
47
- --prompt-content $CODESPECTOR_PROMPT_CONTENT
48
- --result-file $CODESPECTOR_RESULT_FILE
49
-
50
- - name: Post review comment
51
- env:
52
- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53
- run: |
54
- COMMENT_CONTENT=$(cat ${CODESPECTOR_RESULT_FILE} | jq -Rs .)
55
- gh pr comment ${{ github.event.pull_request.number }} --body "${COMMENT_CONTENT}"
56
-
57
- - name: Upload artifacts
58
- uses: actions/upload-artifact@v4
59
- with:
60
- name: codespector-results
61
- path: |
62
- ${{ env.CODESPECTOR_RESULT_FILE }}
63
- ${{ env.CODESPECTOR_COMBINED_FILE }}
64
- retention-days: 1
File without changes
File without changes
File without changes
File without changes