local repo = jarvis.memory.recall("github.repo") if not repo or repo == "" then return jarvis.cmd.not_found("Сначала укажите репозиторий: текущий репо owner/repo.") end -- get the most recent PR's number local list = jarvis.system.exec(string.format( 'gh pr list --repo "%s" --state open --json number --limit 1', repo )) if not list or not list.success then return jarvis.cmd.error("gh CLI не отвечает.") end local number = (list.stdout or ""):match('"number"%s*:%s*(%d+)') if not number then return jarvis.cmd.ok("Открытых пиаров нет.") end -- fetch title + body + diff stat local detail = jarvis.system.exec(string.format( 'gh pr view %s --repo "%s" --json title,body,additions,deletions,changedFiles,author', number, repo )) if not detail or not detail.success then return jarvis.cmd.error("Не получилось получить PR.") end local d = detail.stdout or "" local title = d:match('"title"%s*:%s*"([^"]*)"') or "(no title)" local body = d:match('"body"%s*:%s*"(.-)"') or "" body = body:gsub("\\n", "\n"):gsub("\\r", " "):gsub('\\"', '"'):gsub("\\\\", "\\") local additions = d:match('"additions"%s*:%s*(%d+)') or "?" local deletions = d:match('"deletions"%s*:%s*(%d+)') or "?" local files = d:match('"changedFiles"%s*:%s*(%d+)') or "?" local author = d:match('"login"%s*:%s*"([^"]*)"') or "(unknown)" -- Trim body for prompt if #body > 3000 then body = body:sub(1, 3000) .. "\n... [truncated]" end local user_prompt = string.format([[ Repo: %s PR #%s: %s Author: %s Changed files: %s (+%s, -%s) Description: %s Кратко (3-5 предложений) на русском объясни: что меняет этот PR, какие риски, стоит ли мёржить. ]], repo, number, title, author, files, additions, deletions, body) local review = jarvis.llm({ { role = "system", content = "Ты — старший разработчик, делаешь код-ревью. Отвечай по делу, без воды, без 'отличный PR' вступлений." }, { role = "user", content = user_prompt } }, { max_tokens = 400, temperature = 0.2 }) if not review or review == "" then return jarvis.cmd.error("Не получилось проанализировать.") end jarvis.system.notify(string.format("PR #%s — %s", number, title), review:sub(1, 250)) return jarvis.cmd.ok(string.format("Пиар номер %s: %s", number, review))