refactor #1

Open
roberto wants to merge 12 commits from feature/refactor-code into main
Showing only changes of commit 4c29732a8e - Show all commits

View File

@@ -7,42 +7,24 @@ on:
jobs: jobs:
review: review:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# Using an external Ollama server at 192.168.1.92:11434 container:
# Do NOT start a local Ollama service in the runner; the workflow will connect to the external host. image: python:3.11-bookworm
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11.x'
check-latest: true
- name: Show Python - name: Show Python
run: python --version run: python --version
- name: Ensure Python 3.11 present (fallback) - name: Install system deps (git + curl)
run: | run: |
set -e apt-get update
echo "Checking python version..." apt-get install -y --no-install-recommends git curl ca-certificates
if command -v python >/dev/null 2>&1; then git --version
python --version || true curl --version
fi
if python --version 2>&1 | grep -q "Python 3.11"; then
echo "Python 3.11 already installed"
else
echo "Attempting to install python3.11 via apt"
sudo apt-get update
sudo apt-get install -y python3.11 python3.11-venv python3.11-distutils python3-pip || true
if [ -x "/usr/bin/python3.11" ]; then
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 || true
fi
python --version || /usr/bin/python3.11 --version || true
fi
- name: Create venv and install - name: Create venv and install project
run: | run: |
python -m venv venv python -m venv venv
. venv/bin/activate . venv/bin/activate
@@ -51,24 +33,25 @@ jobs:
- name: Wait for Ollama - name: Wait for Ollama
run: | run: |
for i in $(seq 1 30); do for i in $(seq 1 60); do
if curl -sSf http://192.168.1.92:11434/ >/dev/null 2>&1; then if curl -sSf http://192.168.1.92:11434/api/tags >/dev/null 2>&1; then
echo "ollama ready" && break echo "ollama ready" && exit 0
fi fi
sleep 1 sleep 1
done done
echo "ollama not reachable" >&2
- name: (Optional) Pull model into Ollama exit 1
run: |
. venv/bin/activate
ollama pull qwen2.5-coder:7b || true
- name: Run ai-reviewer - name: Run ai-reviewer
env: env:
OLLAMA_HOST: http://192.168.1.92:11434 OLLAMA_HOST: http://192.168.1.92:11434
run: | run: |
. venv/bin/activate . venv/bin/activate
ai-reviewer review --repo . --base "${{ github.event.pull_request.base.ref }}" --head "${{ github.head_ref }}" --format json > review.json ai-reviewer review \
--repo . \
--base "${{ github.event.pull_request.base.ref }}" \
--head "${{ github.head_ref }}" \
--format json > review.json
- name: Post PR comment with findings - name: Post PR comment with findings
uses: actions/github-script@v6 uses: actions/github-script@v6
@@ -76,16 +59,21 @@ jobs:
script: | script: |
const fs = require('fs'); const fs = require('fs');
let body = '{}'; let body = '{}';
try { try { body = fs.readFileSync('review.json', 'utf8'); } catch (e) {
body = fs.readFileSync('review.json', 'utf8');
} catch (e) {
body = JSON.stringify({ error: 'missing-review', message: String(e) }); body = JSON.stringify({ error: 'missing-review', message: String(e) });
} }
let parsed = {}; let parsed = {};
try { parsed = JSON.parse(body); } catch (e) { parsed = { error: 'invalid-json', raw: body }; } try { parsed = JSON.parse(body); } catch (e) {
parsed = { error: 'invalid-json', raw: body };
}
const findings = parsed.findings || []; const findings = parsed.findings || [];
const summary = findings.length === 0 ? 'AI Reviewer: no findings.' : `AI Reviewer found ${findings.length} findings.`; const summary = findings.length === 0
const commentBody = `${summary}\n\n<details><summary>Full JSON</summary>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n` + '```json\n' + JSON.stringify(parsed, null, 2) + '\n```\n</details>'; ? 'AI Reviewer: no findings.'
: `AI Reviewer found ${findings.length} findings.`;
const commentBody =
`${summary}\n\n<details><summary>Full JSON</summary>\n\n` +
'```json\n' + JSON.stringify(parsed, null, 2) + '\n```\n' +
'</details>';
await github.rest.issues.createComment({ await github.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,