88 lines
2.4 KiB
Python
88 lines
2.4 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
|
|
|
|
|
|
@dataclass
|
|
class AiderArgs:
|
|
gitea_url: str
|
|
owner: str
|
|
repo: str
|
|
base_branch: str
|
|
|
|
|
|
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:
|
|
aider_args = AiderArgs(
|
|
gitea_url=args.gitea_url,
|
|
owner=args.owner,
|
|
repo=repo,
|
|
base_branch=args.base_branch,
|
|
)
|
|
handle_issues(aider_args, 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()
|