From 47adf6373b63eee450930cc81de6842509fa71d3 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Sun, 13 Apr 2025 16:54:59 +0200 Subject: [PATCH 1/4] feat: add SQLite handling for seen issues and update main processing logic --- aider_gitea/__main__.py | 9 ++++++++- aider_gitea/seen_issues_db.py | 28 ++++++++++++++++++++++++++++ test/test_seen_issues_db.py | 20 ++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 aider_gitea/seen_issues_db.py create mode 100644 test/test_seen_issues_db.py diff --git a/aider_gitea/__main__.py b/aider_gitea/__main__.py index 3d1b6ac..304f29c 100644 --- a/aider_gitea/__main__.py +++ b/aider_gitea/__main__.py @@ -15,8 +15,8 @@ import subprocess import os import re - from . import secrets +from .seen_issues_db import SeenIssuesDB def generate_branch_name(issue_number: str, issue_title: str) -> str: """ @@ -134,6 +134,7 @@ def main(): logging.basicConfig(level='INFO') args = parse_args() + seen_issues_db = SeenIssuesDB() client = GiteaClient(args.gitea_url, secrets.gitea_token()) try: @@ -150,7 +151,13 @@ def main(): issue_number = issue.get("number") issue_description = issue.get("body", "") title = issue.get("title", f"Issue {issue_number}") + issue_text = f"{title}\n{issue_description}" + if seen_issues_db.has_seen(issue_text): + logger.info(f"Skipping already processed issue #{issue_number}: {title}") + continue + branch_name = generate_branch_name(issue_number, title) + seen_issues_db.mark_as_seen(issue_text) try: with tempfile.TemporaryDirectory() as tmpdirname: process_issue(args, Path(tmpdirname), branch_name, title, issue_description, issue_number) diff --git a/aider_gitea/seen_issues_db.py b/aider_gitea/seen_issues_db.py new file mode 100644 index 0000000..7fb8ea7 --- /dev/null +++ b/aider_gitea/seen_issues_db.py @@ -0,0 +1,28 @@ +import sqlite3 +from hashlib import sha256 + +class SeenIssuesDB: + def __init__(self, db_path='seen_issues.db'): + self.conn = sqlite3.connect(db_path) + self._create_table() + + def _create_table(self): + with self.conn: + self.conn.execute(''' + CREATE TABLE IF NOT EXISTS seen_issues ( + issue_hash TEXT PRIMARY KEY + ) + ''') + + def mark_as_seen(self, issue_text: str): + issue_hash = self._compute_hash(issue_text) + with self.conn: + self.conn.execute('INSERT OR IGNORE INTO seen_issues (issue_hash) VALUES (?)', (issue_hash,)) + + def has_seen(self, issue_text: str) -> bool: + issue_hash = self._compute_hash(issue_text) + cursor = self.conn.execute('SELECT 1 FROM seen_issues WHERE issue_hash = ?', (issue_hash,)) + return cursor.fetchone() is not None + + def _compute_hash(self, text: str) -> str: + return sha256(text.encode('utf-8')).hexdigest() diff --git a/test/test_seen_issues_db.py b/test/test_seen_issues_db.py new file mode 100644 index 0000000..41a91f6 --- /dev/null +++ b/test/test_seen_issues_db.py @@ -0,0 +1,20 @@ +import unittest +from aider_gitea.seen_issues_db import SeenIssuesDB + +class TestSeenIssuesDB(unittest.TestCase): + + def setUp(self): + self.db = SeenIssuesDB(':memory:') + + def test_mark_and_check_seen_issue(self): + issue_text = "Test issue" + self.assertFalse(self.db.has_seen(issue_text)) + self.db.mark_as_seen(issue_text) + self.assertTrue(self.db.has_seen(issue_text)) + + def test_unseen_issue(self): + issue_text = "Unseen issue" + self.assertFalse(self.db.has_seen(issue_text)) + +if __name__ == '__main__': + unittest.main() -- 2.45.1 From a5b5263d4bb3d8b1761f519d2833d9c28a12752d Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Sun, 13 Apr 2025 16:55:03 +0200 Subject: [PATCH 2/4] fix: add module path to Python path in test_seen_issues_db.py --- test/test_seen_issues_db.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_seen_issues_db.py b/test/test_seen_issues_db.py index 41a91f6..7d13d4e 100644 --- a/test/test_seen_issues_db.py +++ b/test/test_seen_issues_db.py @@ -1,4 +1,9 @@ +import sys import unittest +from pathlib import Path + +# Add the aider_gitea module to the Python path +sys.path.append(str(Path(__file__).resolve().parent.parent)) from aider_gitea.seen_issues_db import SeenIssuesDB class TestSeenIssuesDB(unittest.TestCase): -- 2.45.1 From c9f99fbb0574d858398855090b549c209c065379 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Sun, 13 Apr 2025 16:55:06 +0200 Subject: [PATCH 3/4] fix: update Python path to include aider_gitea module for tests --- test/test_seen_issues_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_seen_issues_db.py b/test/test_seen_issues_db.py index 7d13d4e..ffb1b64 100644 --- a/test/test_seen_issues_db.py +++ b/test/test_seen_issues_db.py @@ -3,7 +3,7 @@ import unittest from pathlib import Path # Add the aider_gitea module to the Python path -sys.path.append(str(Path(__file__).resolve().parent.parent)) +sys.path.append(str(Path(__file__).resolve().parent.parent / "aider_gitea")) from aider_gitea.seen_issues_db import SeenIssuesDB class TestSeenIssuesDB(unittest.TestCase): -- 2.45.1 From 7853404308197e9ba1db7eb9d05d79eafc48f60b Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Sun, 13 Apr 2025 16:55:09 +0200 Subject: [PATCH 4/4] fix: update Python path in test to resolve ModuleNotFoundError --- test/test_seen_issues_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_seen_issues_db.py b/test/test_seen_issues_db.py index ffb1b64..7d13d4e 100644 --- a/test/test_seen_issues_db.py +++ b/test/test_seen_issues_db.py @@ -3,7 +3,7 @@ import unittest from pathlib import Path # Add the aider_gitea module to the Python path -sys.path.append(str(Path(__file__).resolve().parent.parent / "aider_gitea")) +sys.path.append(str(Path(__file__).resolve().parent.parent)) from aider_gitea.seen_issues_db import SeenIssuesDB class TestSeenIssuesDB(unittest.TestCase): -- 2.45.1