Iterate all user repos
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 23s

This commit is contained in:
Jon Michael Aanes 2025-04-13 23:19:36 +02:00
parent b4cbeb4691
commit 273144b509
3 changed files with 36 additions and 44 deletions

View File

@ -10,7 +10,14 @@ When such an issue is found, it:
3. Runs tests and code quality checks. 3. Runs tests and code quality checks.
4. Creates a pull request with the solution. 4. Creates a pull request with the solution.
## Example Usage ## Usage
An application token must be supplied for the `gitea_token` secret. This must
have the following permissions:
- `read:issue`: To be able to read issues on the specified repository.
- `write:repository`: To be able to create pull requests.
- `read:user`: Needed to iterate all user's repositories.
### Command Line ### Command Line
@ -67,7 +74,6 @@ import sys
import tempfile import tempfile
from pathlib import Path from pathlib import Path
from . import secrets
from ._version import __version__ # noqa: F401 from ._version import __version__ # noqa: F401
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -153,12 +159,11 @@ def push_changes(
branch_name: str, branch_name: str,
issue_number: str, issue_number: str,
issue_title: str, issue_title: str,
issue_description: str,
base_branch: str, base_branch: str,
) -> bool: ) -> bool:
# Check if there are any commits on the branch before pushing # Check if there are any commits on the branch before pushing
if not has_commits_on_branch(cwd, base_branch, branch_name): if not has_commits_on_branch(cwd, base_branch, branch_name):
logger.info(f'No commits made on branch {branch_name}, skipping push') logger.info('No commits made on branch %s, skipping push', branch_name)
return False return False
cmd = [ cmd = [
'git', 'git',

View File

@ -55,43 +55,24 @@ def main():
seen_issues_db = SeenIssuesDB() seen_issues_db = SeenIssuesDB()
client = GiteaClient(args.gitea_url, secrets.gitea_token()) client = GiteaClient(args.gitea_url, secrets.gitea_token())
if args.daemon: if args.repo:
logger.info( repositories = [args.repo]
f'Starting daemon mode, checking for new issues every {args.interval} seconds',
)
try:
while True:
if args.repo:
logger.info('Checking for new issues...')
handle_issues(args, client, seen_issues_db)
logger.info(f'Sleeping for {args.interval} seconds...')
time.sleep(args.interval)
else:
repositories = client.get_user_repositories(args.owner)
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)
time.sleep(args.interval)
except KeyboardInterrupt:
logger.exception('Daemon stopped by user')
else: else:
# One-off run repositories = client.iter_user_repositories(args.owner, True)
if args.repo:
handle_issues(args, client, seen_issues_db)
else:
repositories = client.get_user_repositories(args.owner)
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)
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__': if __name__ == '__main__':
main() main()

View File

@ -1,5 +1,6 @@
import logging import logging
from typing import Iterator
import requests import requests
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -81,7 +82,7 @@ class GiteaClient:
response.raise_for_status() response.raise_for_status()
return True return True
def get_issues(self, owner: str, repo: str) -> list: 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.
@ -107,7 +108,7 @@ class GiteaClient:
] ]
return issues return issues
def get_user_repositories(self, owner: str) -> list: def iter_user_repositories(self, 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.
@ -117,8 +118,13 @@ class GiteaClient:
Returns: Returns:
list: A list of repository names. list: A list of repository names.
""" """
url = f'{self.gitea_url}/users/{owner}/repos' url = f'{self.gitea_url}/user/repos'
response = self.session.get(url) response = self.session.get(url)
response.raise_for_status() response.raise_for_status()
repos = response.json()
return [repo['name'] for repo in repos] for repo in response.json():
if only_those_with_issues and not repo['has_issues']:
continue
if repo['owner']['login'].lower() != owner.lower():
continue
yield repo['name']