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

80 lines
2.3 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 . import handle_issues, secrets
from .gitea_client import GiteaClient
from .seen_issues_db import SeenIssuesDB
logger = logging.getLogger(__name__)
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)',
)
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 = client.iter_user_repositories(args.owner, True)
while True:
logger.info('Checking for new issues...')
for repo in repositories:
args_copy = argparse.Namespace()
args_copy.gitea_url = args.gitea_url
args_copy.owner = args.owner
args_copy.repo = repo
args_copy.base_branch = args.base_branch
handle_issues(args_copy, client, seen_issues_db)
if not args.daemon:
break
logger.info('Sleeping for %d seconds...', args.interval)
time.sleep(args.interval)
if __name__ == '__main__':
main()