From 0db5ea72148441c303ded6c0a7a2bc525382f976 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 15 Apr 2025 23:39:46 +0200 Subject: [PATCH 1/3] Initial ruff pass --- aider_gitea/__init__.py | 6 ++++-- test/test_solve_issue_in_repository.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index c7c6852..2ba421e 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -283,8 +283,10 @@ def run_cmd(cmd: list[str], cwd: Path | None = None, check=True) -> bool: result = subprocess.run(cmd, check=check, cwd=cwd) return result.returncode == 0 + SKIP_AIDER = False + def solve_issue_in_repository( args, tmpdirname: Path, @@ -294,7 +296,7 @@ def solve_issue_in_repository( issue_number: str, gitea_client=None, ) -> bool: - logger.info("### %s #####", issue_title) + logger.info('### %s #####', issue_title) repo_url = f'{args.gitea_url}:{args.owner}/{args.repo}.git'.replace( 'https://', @@ -331,7 +333,7 @@ def solve_issue_in_repository( check=False, ) else: - logger.warning("Skipping aider command (for testing)") + logger.warning('Skipping aider command (for testing)') succeeded = True if not succeeded: logger.error('Aider invocation failed for issue #%s', issue_number) diff --git a/test/test_solve_issue_in_repository.py b/test/test_solve_issue_in_repository.py index 0377094..76d1ab2 100644 --- a/test/test_solve_issue_in_repository.py +++ b/test/test_solve_issue_in_repository.py @@ -24,7 +24,11 @@ class TestSolveIssueInRepository: @patch('aider_gitea.push_changes') @patch('subprocess.run') def test_solve_issue_with_aider_changes( - self, mock_subprocess_run, mock_push_changes, mock_run_cmd, mock_llm_api_key, + self, + mock_subprocess_run, + mock_push_changes, + mock_run_cmd, + mock_llm_api_key, ): # Setup mocks mock_run_cmd.return_value = True @@ -34,7 +38,8 @@ class TestSolveIssueInRepository: mock_subprocess_run.side_effect = [ MagicMock(stdout='abc123\n', returncode=0), # First git rev-parse MagicMock( - stdout='file1.py\nfile2.py\n', returncode=0, + stdout='file1.py\nfile2.py\n', + returncode=0, ), # git diff with changes ] @@ -59,7 +64,11 @@ class TestSolveIssueInRepository: @patch('aider_gitea.push_changes') @patch('subprocess.run') def test_solve_issue_without_aider_changes( - self, mock_subprocess_run, mock_push_changes, mock_run_cmd, mock_llm_api_key, + self, + mock_subprocess_run, + mock_push_changes, + mock_run_cmd, + mock_llm_api_key, ): # Setup mocks mock_run_cmd.return_value = True -- 2.45.1 From 44104215a2ba672c462a88a5a952560b86875b65 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Tue, 15 Apr 2025 23:41:18 +0200 Subject: [PATCH 2/3] feat: Add support for assigning reviewers and assignees to pull requests --- aider_gitea/__init__.py | 2 ++ aider_gitea/__main__.py | 18 +++++++++++++++++ test/test_main_args.py | 43 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 test/test_main_args.py diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index 2ba421e..1eb9d98 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -411,6 +411,8 @@ def handle_issues(args, client, seen_issues_db): issue_description, issue_number, client, + reviewers=args.reviewers, + assignees=args.assignees, ) if solved: diff --git a/aider_gitea/__main__.py b/aider_gitea/__main__.py index df028f5..e83abc3 100644 --- a/aider_gitea/__main__.py +++ b/aider_gitea/__main__.py @@ -22,6 +22,8 @@ class AiderArgs: owner: str repo: str base_branch: str + reviewers: list[str] = None + assignees: list[str] = None def parse_args(): @@ -54,6 +56,16 @@ def parse_args(): default=300, help='Interval in seconds between checks in daemon mode (default: 300)', ) + parser.add_argument( + '--reviewers', + type=str, + help='Comma-separated list of usernames to assign as reviewers for pull requests', + ) + parser.add_argument( + '--assignees', + type=str, + help='Comma-separated list of usernames to assign as assignees for pull requests', + ) return parser.parse_args() @@ -72,11 +84,17 @@ def main(): while True: logger.info('Checking for new issues...') for repo in repositories: + # Parse reviewers and assignees from comma-separated strings to lists + reviewers = args.reviewers.split(',') if args.reviewers else None + assignees = args.assignees.split(',') if args.assignees else None + aider_args = AiderArgs( gitea_url=args.gitea_url, owner=args.owner, repo=repo, base_branch=args.base_branch, + reviewers=reviewers, + assignees=assignees, ) handle_issues(aider_args, client, seen_issues_db) del repo diff --git a/test/test_main_args.py b/test/test_main_args.py new file mode 100644 index 0000000..7e5558d --- /dev/null +++ b/test/test_main_args.py @@ -0,0 +1,43 @@ +import pytest +from unittest.mock import patch, MagicMock +import argparse + +from aider_gitea.__main__ import parse_args + + +def test_parse_args_with_reviewers_and_assignees(): + """Test that reviewers and assignees arguments are correctly parsed.""" + test_args = [ + '--gitea-url', 'https://gitea.example.com', + '--owner', 'test-owner', + '--repo', 'test-repo', + '--reviewers', 'user1,user2', + '--assignees', 'user3,user4' + ] + + with patch('sys.argv', ['aider_gitea'] + test_args): + args = parse_args() + + assert args.gitea_url == 'https://gitea.example.com' + assert args.owner == 'test-owner' + assert args.repo == 'test-repo' + assert args.reviewers == 'user1,user2' + assert args.assignees == 'user3,user4' + + +def test_parse_args_without_reviewers_and_assignees(): + """Test that the parser works without reviewers and assignees.""" + test_args = [ + '--gitea-url', 'https://gitea.example.com', + '--owner', 'test-owner', + '--repo', 'test-repo' + ] + + with patch('sys.argv', ['aider_gitea'] + test_args): + args = parse_args() + + assert args.gitea_url == 'https://gitea.example.com' + assert args.owner == 'test-owner' + assert args.repo == 'test-repo' + assert args.reviewers is None + assert args.assignees is None -- 2.45.1 From 1371343ff494a233df05bf799643b7bd525ecc11 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 15 Apr 2025 23:41:22 +0200 Subject: [PATCH 3/3] Ruff after aider --- aider_gitea/__main__.py | 2 +- test/test_main_args.py | 36 +++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/aider_gitea/__main__.py b/aider_gitea/__main__.py index e83abc3..c8ee53b 100644 --- a/aider_gitea/__main__.py +++ b/aider_gitea/__main__.py @@ -87,7 +87,7 @@ def main(): # Parse reviewers and assignees from comma-separated strings to lists reviewers = args.reviewers.split(',') if args.reviewers else None assignees = args.assignees.split(',') if args.assignees else None - + aider_args = AiderArgs( gitea_url=args.gitea_url, owner=args.owner, diff --git a/test/test_main_args.py b/test/test_main_args.py index 7e5558d..ac57a51 100644 --- a/test/test_main_args.py +++ b/test/test_main_args.py @@ -1,6 +1,4 @@ -import pytest -from unittest.mock import patch, MagicMock -import argparse +from unittest.mock import patch from aider_gitea.__main__ import parse_args @@ -8,16 +6,21 @@ from aider_gitea.__main__ import parse_args def test_parse_args_with_reviewers_and_assignees(): """Test that reviewers and assignees arguments are correctly parsed.""" test_args = [ - '--gitea-url', 'https://gitea.example.com', - '--owner', 'test-owner', - '--repo', 'test-repo', - '--reviewers', 'user1,user2', - '--assignees', 'user3,user4' + '--gitea-url', + 'https://gitea.example.com', + '--owner', + 'test-owner', + '--repo', + 'test-repo', + '--reviewers', + 'user1,user2', + '--assignees', + 'user3,user4', ] - + with patch('sys.argv', ['aider_gitea'] + test_args): args = parse_args() - + assert args.gitea_url == 'https://gitea.example.com' assert args.owner == 'test-owner' assert args.repo == 'test-repo' @@ -28,14 +31,17 @@ def test_parse_args_with_reviewers_and_assignees(): def test_parse_args_without_reviewers_and_assignees(): """Test that the parser works without reviewers and assignees.""" test_args = [ - '--gitea-url', 'https://gitea.example.com', - '--owner', 'test-owner', - '--repo', 'test-repo' + '--gitea-url', + 'https://gitea.example.com', + '--owner', + 'test-owner', + '--repo', + 'test-repo', ] - + with patch('sys.argv', ['aider_gitea'] + test_args): args = parse_args() - + assert args.gitea_url == 'https://gitea.example.com' assert args.owner == 'test-owner' assert args.repo == 'test-repo' -- 2.45.1