diff --git a/.gitea/workflows/ai-comment-reply.yml b/.gitea/workflows/ai-comment-reply.yml index 43186ca..773c7e3 100644 --- a/.gitea/workflows/ai-comment-reply.yml +++ b/.gitea/workflows/ai-comment-reply.yml @@ -35,16 +35,51 @@ jobs: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} OLLAMA_HOST: ${{ secrets.OLLAMA_HOST }} + EVENT_ISSUE_JSON: ${{ toJSON(gitea.event.issue) }} + EVENT_COMMENT_JSON: ${{ toJSON(gitea.event.comment) }} + IS_PR: ${{ gitea.event.issue.pull_request != null }} + ISSUE_NUMBER: ${{ gitea.event.issue.number }} + COMMENT_BODY: ${{ gitea.event.comment.body }} run: | cd .ai-review/tools/ai-review # Check if this is a PR or an issue - if [ "${{ gitea.event.issue.pull_request }}" != "" ]; then + if [ "$IS_PR" = "true" ]; then # This is a PR comment - dispatch as issue_comment event - python main.py dispatch ${{ gitea.repository }} issue_comment \ - '{"action":"created","issue":${{ toJSON(gitea.event.issue) }},"comment":${{ toJSON(gitea.event.comment) }}}' + # Create JSON payload using environment variables + python -c " + import os + import json + import sys + + issue = json.loads(os.environ['EVENT_ISSUE_JSON']) + comment = json.loads(os.environ['EVENT_COMMENT_JSON']) + event_data = { + 'action': 'created', + 'issue': issue, + 'comment': comment + } + + # Import and run dispatcher + sys.path.insert(0, '.') + from dispatcher import get_dispatcher + from agents.pr_agent import PRAgent + from agents.issue_agent import IssueAgent + + dispatcher = get_dispatcher() + dispatcher.register_agent(PRAgent()) + dispatcher.register_agent(IssueAgent()) + + repo = os.environ['AI_REVIEW_REPO'] + owner, repo_name = repo.split('/') + + result = dispatcher.dispatch('issue_comment', event_data, owner, repo_name) + + if result.errors: + print(f'Errors: {result.errors}') + sys.exit(1) + " else # This is an issue comment - use the comment command - python main.py comment ${{ gitea.repository }} ${{ gitea.event.issue.number }} \ - "${{ gitea.event.comment.body }}" + python main.py comment "$AI_REVIEW_REPO" "$ISSUE_NUMBER" "$COMMENT_BODY" fi