aider-gitea/aider_gitea/__main__.py
Jon Michael Aanes 1371343ff4
All checks were successful
Run Python tests (through Pytest) / Test (push) Successful in 25s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 22s
Ruff after aider
2025-04-15 23:41:22 +02:00

109 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""
This script downloads issues from a given Gitea repository and produces a pull request for each issue.
It assumes that the default branch (default "main") exists and that you have a valid API token if authentication is required.
"""
import argparse
import logging
import time
from dataclasses import dataclass
from . import handle_issues, secrets
from .gitea_client import GiteaClient
from .seen_issues_db import SeenIssuesDB
logger = logging.getLogger(__name__)
@dataclass
class AiderArgs:
gitea_url: str
owner: str
repo: str
base_branch: str
reviewers: list[str] = None
assignees: list[str] = None
def parse_args():
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')
parser.add_argument(
'--repo',
help='Repository name. If not specified, all repositories for the owner will be scanned.',
)
parser.add_argument(
'--base-branch',
default='main',
help='Base branch to use for new branches (default: main)',
)
parser.add_argument(
'--daemon',
action='store_true',
help='Run in daemon mode to continuously monitor for new issues',
)
parser.add_argument(
'--interval',
type=int,
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()
def main():
logging.basicConfig(level='INFO')
args = parse_args()
seen_issues_db = SeenIssuesDB()
client = GiteaClient(args.gitea_url, secrets.gitea_token())
if args.repo:
repositories = [args.repo]
else:
repositories = list(client.iter_user_repositories(args.owner, True))
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
if not args.daemon:
break
logger.info('Sleeping for %d seconds...', args.interval)
time.sleep(args.interval)
if __name__ == '__main__':
main()