Format files by pre-commit run -a

Signed-off-by: Yu Ishikawa <yu-iskw@users.noreply.github.com>
This commit is contained in:
Yu Ishikawa
2024-10-30 09:56:03 +09:00
parent a3d572fb69
commit 81dea65856
122 changed files with 428 additions and 396 deletions

View File

@ -32,4 +32,3 @@ def main():
if __name__ == '__main__':
main()
"""

View File

@ -5,16 +5,16 @@ import time
from datetime import datetime
import jwt
from atlassian.bitbucket import Cloud
import requests
from atlassian.bitbucket import Cloud
from requests.auth import HTTPBasicAuth
from pr_agent.config_loader import get_settings
from pr_agent.log import setup_logger, get_logger
from tests.e2e_tests.e2e_utils import NEW_FILE_CONTENT, FILE_PATH, PR_HEADER_START_WITH, REVIEW_START_WITH, \
IMPROVE_START_WITH_REGEX_PATTERN, NUM_MINUTES
from pr_agent.log import get_logger, setup_logger
from tests.e2e_tests.e2e_utils import (FILE_PATH,
IMPROVE_START_WITH_REGEX_PATTERN,
NEW_FILE_CONTENT, NUM_MINUTES,
PR_HEADER_START_WITH, REVIEW_START_WITH)
log_level = os.environ.get("LOG_LEVEL", "INFO")
setup_logger(log_level)

View File

@ -5,9 +5,11 @@ from datetime import datetime
from pr_agent.config_loader import get_settings
from pr_agent.git_providers import get_git_provider
from pr_agent.log import setup_logger, get_logger
from tests.e2e_tests.e2e_utils import NEW_FILE_CONTENT, FILE_PATH, PR_HEADER_START_WITH, REVIEW_START_WITH, \
IMPROVE_START_WITH_REGEX_PATTERN, NUM_MINUTES
from pr_agent.log import get_logger, setup_logger
from tests.e2e_tests.e2e_utils import (FILE_PATH,
IMPROVE_START_WITH_REGEX_PATTERN,
NEW_FILE_CONTENT, NUM_MINUTES,
PR_HEADER_START_WITH, REVIEW_START_WITH)
log_level = os.environ.get("LOG_LEVEL", "INFO")
setup_logger(log_level)

View File

@ -7,9 +7,11 @@ import gitlab
from pr_agent.config_loader import get_settings
from pr_agent.git_providers import get_git_provider
from pr_agent.log import setup_logger, get_logger
from tests.e2e_tests.e2e_utils import NEW_FILE_CONTENT, FILE_PATH, PR_HEADER_START_WITH, REVIEW_START_WITH, \
IMPROVE_START_WITH_REGEX_PATTERN, NUM_MINUTES
from pr_agent.log import get_logger, setup_logger
from tests.e2e_tests.e2e_utils import (FILE_PATH,
IMPROVE_START_WITH_REGEX_PATTERN,
NEW_FILE_CONTENT, NUM_MINUTES,
PR_HEADER_START_WITH, REVIEW_START_WITH)
log_level = os.environ.get("LOG_LEVEL", "INFO")
setup_logger(log_level)

View File

@ -12,4 +12,4 @@ class TestAzureDevOpsParsing():
pr_url = "https://organization.visualstudio.com/project/_git/repo/pullrequest/1"
# workspace_slug, repo_slug, pr_number
assert AzureDevopsProvider._parse_pr_url(pr_url) == ("project", "repo", 1)
assert AzureDevopsProvider._parse_pr_url(pr_url) == ("project", "repo", 1)

View File

@ -1,8 +1,10 @@
from unittest.mock import MagicMock
from atlassian.bitbucket import Bitbucket
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
from pr_agent.git_providers import BitbucketServerProvider
from pr_agent.git_providers.bitbucket_provider import BitbucketProvider
from unittest.mock import MagicMock
from atlassian.bitbucket import Bitbucket
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
class TestBitbucketProvider:
@ -121,7 +123,7 @@ class TestBitbucketServerProvider:
NOT between the HEAD of main and the HEAD of branch b
- o - o - o branch b
/ /
/ /
o - o -- o - o main
^ node c
'''
@ -183,7 +185,7 @@ class TestBitbucketServerProvider:
---- o - o branch c
/ /
---- o branch b
/ /
/ /
o - o - o main
^ node d
'''
@ -294,4 +296,4 @@ class TestBitbucketServerProvider:
actual = provider.get_diff_files()
assert actual == expected
assert actual == expected

View File

@ -1,4 +1,5 @@
from unittest.mock import MagicMock
from pr_agent.git_providers.codecommit_client import CodeCommitClient

View File

@ -1,9 +1,11 @@
import pytest
from unittest.mock import patch
from pr_agent.git_providers.codecommit_provider import CodeCommitFile
from pr_agent.git_providers.codecommit_provider import CodeCommitProvider
from pr_agent.git_providers.codecommit_provider import PullRequestCCMimic
import pytest
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
from pr_agent.git_providers.codecommit_provider import (CodeCommitFile,
CodeCommitProvider,
PullRequestCCMimic)
class TestCodeCommitFile:

View File

@ -6,8 +6,8 @@ from pr_agent.tools.pr_description import insert_br_after_x_chars
Code Analysis
Objective:
The objective of the 'convert_to_markdown' function is to convert a dictionary of data into a markdown-formatted text.
The function takes in a dictionary as input and recursively iterates through its keys and values to generate the
The objective of the 'convert_to_markdown' function is to convert a dictionary of data into a markdown-formatted text.
The function takes in a dictionary as input and recursively iterates through its keys and values to generate the
markdown text.
Inputs:
@ -18,17 +18,17 @@ Flow:
- Create a dictionary 'emojis' containing emojis for each key in the input dictionary.
- Iterate through the input dictionary:
- If the value is empty, continue to the next iteration.
- If the value is a dictionary, recursively call the 'convert_to_markdown' function with the value as input and
- If the value is a dictionary, recursively call the 'convert_to_markdown' function with the value as input and
append the returned markdown text to 'markdown_text'.
- If the value is a list:
- If the key is 'code suggestions', add an additional line break to 'markdown_text'.
- Get the corresponding emoji for the key from the 'emojis' dictionary. If no emoji is found, use a dash.
- Append the emoji and key to 'markdown_text'.
- Iterate through the items in the list:
- If the item is a dictionary and the key is 'code suggestions', call the 'parse_code_suggestion' function with
- If the item is a dictionary and the key is 'code suggestions', call the 'parse_code_suggestion' function with
the item as input and append the returned markdown text to 'markdown_text'.
- If the item is not empty, append it to 'markdown_text'.
- If the value is not 'n/a', get the corresponding emoji for the key from the 'emojis' dictionary. If no emoji is
- If the value is not 'n/a', get the corresponding emoji for the key from the 'emojis' dictionary. If no emoji is
found, use a dash. Append the emoji, key, and value to 'markdown_text'.
- Return 'markdown_text'.

View File

@ -6,7 +6,7 @@ from pr_agent.algo.git_patch_processing import omit_deletion_hunks
Code Analysis
Objective:
The objective of the "omit_deletion_hunks" function is to remove deletion hunks from a patch file and return only the
The objective of the "omit_deletion_hunks" function is to remove deletion hunks from a patch file and return only the
added lines.
Inputs:
@ -16,11 +16,11 @@ Flow:
- Initialize empty lists "temp_hunk" and "added_patched", and boolean variables "add_hunk" and "inside_hunk".
- Compile a regular expression pattern to match hunk headers.
- Iterate through each line in "patch_lines".
- If the line starts with "@@", match the line with the hunk header pattern, finish the previous hunk if necessary,
- If the line starts with "@@", match the line with the hunk header pattern, finish the previous hunk if necessary,
and append the line to "temp_hunk".
- If the line does not start with "@@", append the line to "temp_hunk", check if it is an added line, and set
- If the line does not start with "@@", append the line to "temp_hunk", check if it is an added line, and set
"add_hunk" to True if it is.
- If the function reaches the end of "patch_lines" and there is an unfinished hunk with added lines, append it to
- If the function reaches the end of "patch_lines" and there is an unfinished hunk with added lines, append it to
"added_patched".
- Join the lines in "added_patched" with newline characters and return the resulting string.

View File

@ -1,4 +1,5 @@
import pytest
from pr_agent.algo.git_patch_processing import extend_patch
from pr_agent.algo.pr_processing import pr_generate_extended_diff
from pr_agent.algo.token_handler import TokenHandler

View File

@ -1,7 +1,9 @@
import pytest
from pr_agent.algo.file_filter import filter_ignored
from pr_agent.config_loader import global_settings
class TestIgnoreFilter:
def test_no_ignores(self):
"""

View File

@ -1,9 +1,10 @@
# Generated by CodiumAI
import pytest
from pr_agent.algo.types import FilePatchInfo
from pr_agent.algo.utils import find_line_number_of_relevant_line_in_file
import pytest
class TestFindLineNumberOfRelevantLineInFile:
# Tests that the function returns the correct line number and absolute position when the relevant line is found in the patch
@ -64,4 +65,4 @@ class TestFindLineNumberOfRelevantLineInFile:
relevant_file = 'file1'
relevant_line_in_file = 'relevant_line'
expected = (-1, -1)
assert find_line_number_of_relevant_line_in_file(diff_files, relevant_file, relevant_line_in_file) == expected
assert find_line_number_of_relevant_line_in_file(diff_files, relevant_file, relevant_line_in_file) == expected

View File

@ -1,33 +1,35 @@
import os
import json
import os
from pr_agent.algo.utils import get_settings, github_action_output
class TestGitHubOutput:
def test_github_action_output_enabled(self, monkeypatch, tmp_path):
get_settings().set('GITHUB_ACTION_CONFIG.ENABLE_OUTPUT', True)
monkeypatch.setenv('GITHUB_OUTPUT', str(tmp_path / 'output'))
output_data = {'key1': {'value1': 1, 'value2': 2}}
key_name = 'key1'
github_action_output(output_data, key_name)
with open(str(tmp_path / 'output'), 'r') as f:
env_value = f.read()
actual_key = env_value.split('=')[0]
actual_data = json.loads(env_value.split('=')[1])
assert actual_key == key_name
assert actual_data == output_data[key_name]
def test_github_action_output_disabled(self, monkeypatch, tmp_path):
get_settings().set('GITHUB_ACTION_CONFIG.ENABLE_OUTPUT', False)
monkeypatch.setenv('GITHUB_OUTPUT', str(tmp_path / 'output'))
output_data = {'key1': {'value1': 1, 'value2': 2}}
key_name = 'key1'
github_action_output(output_data, key_name)
assert not os.path.exists(str(tmp_path / 'output'))
def test_github_action_output_notset(self, monkeypatch, tmp_path):
@ -35,16 +37,16 @@ class TestGitHubOutput:
monkeypatch.setenv('GITHUB_OUTPUT', str(tmp_path / 'output'))
output_data = {'key1': {'value1': 1, 'value2': 2}}
key_name = 'key1'
github_action_output(output_data, key_name)
assert not os.path.exists(str(tmp_path / 'output'))
def test_github_action_output_error_case(self, monkeypatch, tmp_path):
monkeypatch.setenv('GITHUB_OUTPUT', str(tmp_path / 'output'))
output_data = None # invalid data
key_name = 'key1'
github_action_output(output_data, key_name)
assert not os.path.exists(str(tmp_path / 'output'))
assert not os.path.exists(str(tmp_path / 'output'))

View File

@ -8,7 +8,7 @@ from pr_agent.config_loader import get_settings
Code Analysis
Objective:
The objective of the function is to handle entire file or deletion patches and return the patch after omitting the
The objective of the function is to handle entire file or deletion patches and return the patch after omitting the
deletion hunks.
Inputs:

View File

@ -7,8 +7,8 @@ from pr_agent.algo.language_handler import sort_files_by_main_languages
Code Analysis
Objective:
The objective of the function is to sort a list of files by their main language, putting the files that are in the main
language first and the rest of the files after. It takes in a dictionary of languages and their sizes, and a list of
The objective of the function is to sort a list of files by their main language, putting the files that are in the main
language first and the rest of the files after. It takes in a dictionary of languages and their sizes, and a list of
files.
Inputs:

View File

@ -47,7 +47,3 @@ PR Feedback:
expected_output = [{'relevant file': 'src/app.py:\n', 'suggestion content': 'The print statement is outside inside the if __name__ ==:'}]
assert load_yaml(yaml_str) == expected_output

View File

@ -6,8 +6,8 @@ from pr_agent.algo.utils import parse_code_suggestion
Code Analysis
Objective:
The objective of the function is to convert a dictionary into a markdown format. The function takes in a dictionary as
input and recursively converts it into a markdown format. The function is specifically designed to handle dictionaries
The objective of the function is to convert a dictionary into a markdown format. The function takes in a dictionary as
input and recursively converts it into a markdown format. The function is specifically designed to handle dictionaries
that contain code suggestions.
Inputs:

View File

@ -1,10 +1,10 @@
# Generated by CodiumAI
import pytest
from pr_agent.algo.utils import try_fix_yaml
import pytest
class TestTryFixYaml:
# The function successfully parses a valid YAML string.
@ -54,7 +54,7 @@ code_suggestions:
src/index.ts
label: |
best practice
- relevant_file: |
src/index2.ts
label: |
@ -87,4 +87,4 @@ code_suggestions:
We can further improve the code by using the `const` keyword instead of `var` in the `src/index.ts` file.
'''
expected_output = {'code_suggestions': [{'relevant_file': 'src/index.ts\n', 'label': 'best practice\n'}, {'relevant_file': 'src/index2.ts\n', 'label': 'enhancment'}]}
assert try_fix_yaml(review_text, first_key='code_suggestions', last_key='label') == expected_output
assert try_fix_yaml(review_text, first_key='code_suggestions', last_key='label') == expected_output