From 4a3ddec68c1dabc15301addc0ee488cbdf523802 Mon Sep 17 00:00:00 2001 From: latte Date: Sun, 28 Dec 2025 19:27:15 +0000 Subject: [PATCH] fix: Resolve workflow syntax error in ai-comment-reply.yml - Replace inline toJSON() with environment variables - Use Python to parse JSON and dispatch events properly - Avoid bash syntax errors with parentheses in JSON - Maintain same functionality for PR vs issue comment handling Fixes: /var/run/act/workflow/4: line 25: syntax error near unexpected token --- .gitea/workflows/ai-comment-reply.yml | 45 ++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) 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