feat: add SQLite helper functions and corresponding tests for issues
This commit is contained in:
parent
1f9252bcdb
commit
c88ec8372f
|
@ -120,7 +120,46 @@ class GiteaClient:
|
|||
]
|
||||
return issues
|
||||
|
||||
def parse_args():
|
||||
def save_issue_to_sqlite(issue_number: str, issue_title: str, issue_description: str, db_path: Path) -> None:
|
||||
"""
|
||||
Save issue details to an SQLite database.
|
||||
"""
|
||||
import sqlite3
|
||||
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS issues (
|
||||
number TEXT PRIMARY KEY,
|
||||
title TEXT,
|
||||
description TEXT
|
||||
)
|
||||
''')
|
||||
cursor.execute('''
|
||||
INSERT OR REPLACE INTO issues (number, title, description)
|
||||
VALUES (?, ?, ?)
|
||||
''', (issue_number, issue_title, issue_description))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def load_issue_from_sqlite(issue_number: str, db_path: Path) -> tuple[str, str]:
|
||||
"""
|
||||
Load issue details from an SQLite database.
|
||||
"""
|
||||
import sqlite3
|
||||
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
SELECT title, description FROM issues WHERE number = ?
|
||||
''', (issue_number,))
|
||||
result = cursor.fetchone()
|
||||
conn.close()
|
||||
|
||||
if result:
|
||||
return result
|
||||
else:
|
||||
raise ValueError(f"Issue {issue_number} not found in the database.")
|
||||
parser = argparse.ArgumentParser(description="Download issues and create pull requests for a Gitea repository.")
|
||||
parser.add_argument("--gitea-url", required=True, help="Base URL for the Gitea instance, e.g., https://gitfub.space/api/v1")
|
||||
parser.add_argument("--owner", required=True, help="Owner of the repository")
|
||||
|
@ -149,6 +188,13 @@ def run_cmd(cmd: list[str], cwd:Path|None=None) -> None:
|
|||
|
||||
|
||||
def process_issue(args, tmpdirname: Path, branch_name: str, issue_title: str, issue_description: str, issue_number: str):
|
||||
db_path = Path(tmpdirname) / "issues.db"
|
||||
save_issue_to_sqlite(issue_number, issue_title, issue_description, db_path)
|
||||
|
||||
# Example of loading issue from SQLite
|
||||
loaded_title, loaded_description = load_issue_from_sqlite(issue_number, db_path)
|
||||
logger.info(f"Loaded issue {issue_number} from SQLite: {loaded_title}")
|
||||
|
||||
repo_url = f"{args.gitea_url}:{args.owner}/{args.repo}.git".replace('https://', 'git@')
|
||||
run_cmd(["git", "clone", repo_url, tmpdirname])
|
||||
run_cmd(['bash', '-c', AIDER_TEST], tmpdirname)
|
||||
|
|
27
test/test_issue_sqlite.py
Normal file
27
test/test_issue_sqlite.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import sqlite3
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from aider_gitea.__main__ import save_issue_to_sqlite, load_issue_from_sqlite
|
||||
|
||||
def test_save_and_load_issue():
|
||||
issue_number = "123"
|
||||
issue_title = "Test Issue"
|
||||
issue_description = "This is a test issue."
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
db_path = Path(tmpdirname) / "issues.db"
|
||||
|
||||
# Save issue to SQLite
|
||||
save_issue_to_sqlite(issue_number, issue_title, issue_description, db_path)
|
||||
|
||||
# Load issue from SQLite
|
||||
loaded_title, loaded_description = load_issue_from_sqlite(issue_number, db_path)
|
||||
|
||||
assert loaded_title == issue_title
|
||||
assert loaded_description == issue_description
|
||||
|
||||
# Test loading a non-existent issue
|
||||
try:
|
||||
load_issue_from_sqlite("999", db_path)
|
||||
except ValueError as e:
|
||||
assert str(e) == "Issue 999 not found in the database."
|
Loading…
Reference in New Issue
Block a user