From 4245afd0d9837fca5a446cb7233aa40a7ec0ac43 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Mon, 14 Apr 2025 23:43:49 +0200 Subject: [PATCH] fix: Correct multi-line docstring summaries to start on first line --- aider_gitea/__init__.py | 43 ++++++++++++++++++++++++++++++----- aider_gitea/gitea_client.py | 21 +++++++---------- aider_gitea/seen_issues_db.py | 21 ++++++----------- 3 files changed, 52 insertions(+), 33 deletions(-) diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index 3252a44..2510094 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -1,4 +1,4 @@ -"""# Aider Gitea. +"""Aider Gitea. A code automation tool that integrates Gitea with Aider to automatically solve issues. @@ -81,10 +81,17 @@ logger = logging.getLogger(__name__) def generate_branch_name(issue_number: str, issue_title: str) -> str: - """ - Create a branch name by sanitizing the issue title. + """Create a branch name by sanitizing the issue title. + Non-alphanumeric characters (except spaces) are removed, the text is lowercased, and spaces are replaced with dashes. + + Args: + issue_number: The issue number to include in the branch name. + issue_title: The issue title to sanitize and include in the branch name. + + Returns: + A sanitized branch name combining the issue number and title. """ sanitized = re.sub(r'[^0-9a-zA-Z ]+', '', issue_title) parts = ['issue', str(issue_number), *sanitized.lower().split()] @@ -187,7 +194,16 @@ def push_changes( def has_commits_on_branch(cwd: Path, base_branch: str, current_branch: str) -> bool: - """Check if there are any commits on the current branch that aren't in the base branch.""" + """Check if there are any commits on the current branch that aren't in the base branch. + + Args: + cwd: The current working directory (repository path). + base_branch: The name of the base branch to compare against. + current_branch: The name of the current branch to check for commits. + + Returns: + True if there are commits on the current branch not in the base branch, False otherwise. + """ try: result = subprocess.run( ['git', 'log', f'{base_branch}..{current_branch}', '--oneline'], @@ -203,7 +219,16 @@ def has_commits_on_branch(cwd: Path, base_branch: str, current_branch: str) -> b def run_cmd(cmd: list[str], cwd: Path | None = None, check=True) -> bool: - """Returns true if the command succeeded.""" + """Run a shell command and return its success status. + + Args: + cmd: The command to run as a list of strings. + cwd: The directory to run the command in. + check: Whether to raise an exception if the command fails. + + Returns: + True if the command succeeded, False otherwise. + """ result = subprocess.run(cmd, check=check, cwd=cwd) return result.returncode == 0 @@ -253,7 +278,13 @@ def solve_issue_in_repository( def handle_issues(args, client, seen_issues_db): - """Process all open issues with the 'aider' label.""" + """Process all open issues with the 'aider' label. + + Args: + args: Command line arguments. + client: The Gitea client instance. + seen_issues_db: Database of previously processed issues. + """ try: issues = client.get_issues(args.owner, args.repo) except Exception: diff --git a/aider_gitea/gitea_client.py b/aider_gitea/gitea_client.py index 4f1e95e..362bc71 100644 --- a/aider_gitea/gitea_client.py +++ b/aider_gitea/gitea_client.py @@ -7,8 +7,7 @@ logger = logging.getLogger(__name__) class GiteaClient: - """ - Client for interacting with the Gitea API. + """Client for interacting with the Gitea API. This class provides methods to interact with a Gitea instance's API, including retrieving repository information, creating branches, and fetching issues. @@ -19,8 +18,7 @@ class GiteaClient: """ def __init__(self, gitea_url: str, token: str) -> None: - """ - Initialize a new Gitea API client. + """Initialize a new Gitea API client. Args: gitea_url (str): Base URL for the Gitea instance (without '/api/v1'). @@ -37,8 +35,7 @@ class GiteaClient: self.session.headers['Authorization'] = f'token {token}' def get_default_branch_sha(self, owner: str, repo: str, branch: str) -> str: - """ - Retrieve the commit SHA of the specified branch. + """Retrieve the commit SHA of the specified branch. Args: owner (str): Owner of the repository. @@ -58,8 +55,7 @@ class GiteaClient: return data['commit']['sha'] def create_branch(self, owner: str, repo: str, new_branch: str, sha: str) -> bool: - """ - Create a new branch from the provided SHA. + """Create a new branch from the provided SHA. Args: owner (str): Owner of the repository. @@ -83,8 +79,7 @@ class GiteaClient: return True def get_issues(self, owner: str, repo: str) -> list[dict[str, str]]: - """ - Download issues from the specified repository and filter those with the 'aider' label. + """Download issues from the specified repository and filter those with the 'aider' label. Args: owner (str): Owner of the repository. @@ -113,14 +108,14 @@ class GiteaClient: owner: str, only_those_with_issues: bool = False, ) -> Iterator[str]: - """ - Get a list of repositories for a given user. + """Get a list of repositories for a given user. Args: owner (str): The owner of the repositories. + only_those_with_issues (bool): If True, only return repositories with issues enabled. Returns: - list: A list of repository names. + Iterator[str]: An iterator of repository names. """ url = f'{self.gitea_url}/user/repos' response = self.session.get(url) diff --git a/aider_gitea/seen_issues_db.py b/aider_gitea/seen_issues_db.py index 8dbcb23..85a4ae7 100644 --- a/aider_gitea/seen_issues_db.py +++ b/aider_gitea/seen_issues_db.py @@ -1,5 +1,4 @@ -""" -Database module for tracking previously processed issues. +"""Database module for tracking previously processed issues. This module provides functionality to track which issues have already been processed by the system to avoid duplicate processing. It uses a simple SQLite database to @@ -13,8 +12,7 @@ DEFAULT_DB_PATH = 'output/seen_issues.db' class SeenIssuesDB: - """ - Database handler for tracking processed issues. + """Database handler for tracking processed issues. This class manages a SQLite database that stores hashes of issues that have already been processed. It provides methods to mark issues as seen and check @@ -25,8 +23,7 @@ class SeenIssuesDB: """ def __init__(self, db_path=DEFAULT_DB_PATH): - """ - Initialize the database connection. + """Initialize the database connection. Args: db_path: Path to the SQLite database file. Defaults to 'output/seen_issues.db'. @@ -35,8 +32,7 @@ class SeenIssuesDB: self._create_table() def _create_table(self): - """ - Create the seen_issues table if it doesn't exist. + """Create the seen_issues table if it doesn't exist. Creates a table with a single column for storing issue hashes. """ @@ -48,8 +44,7 @@ class SeenIssuesDB: """) def mark_as_seen(self, issue_text: str): - """ - Mark an issue as seen in the database. + """Mark an issue as seen in the database. Computes a hash of the issue text and stores it in the database. If the issue has already been marked as seen, this operation has no effect. @@ -65,8 +60,7 @@ class SeenIssuesDB: ) def has_seen(self, issue_text: str) -> bool: - """ - Check if an issue has been seen before. + """Check if an issue has been seen before. Computes a hash of the issue text and checks if it exists in the database. @@ -84,8 +78,7 @@ class SeenIssuesDB: return cursor.fetchone() is not None def _compute_hash(self, text: str) -> str: - """ - Compute a SHA-256 hash of the given text. + """Compute a SHA-256 hash of the given text. Args: text: The text to hash.