78 lines
3.3 KiB
YAML
78 lines
3.3 KiB
YAML
name: OpenCode Gitea Integration
|
|
|
|
on:
|
|
issue_comment:
|
|
types: [created]
|
|
dispatch:
|
|
types: [workflow_dispatch]
|
|
|
|
jobs:
|
|
opencode-gitea:
|
|
if: |
|
|
contains(github.event.comment.body, '/oc') ||
|
|
contains(github.event.comment.body, '/opencode')
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # Cambiato a 0 per permettere all'AI di vedere la cronologia dei branch se serve
|
|
|
|
- name: Install OpenCode CLI
|
|
run: |
|
|
curl -fsSL https://opencode.ai | bash
|
|
echo "$HOME/.opencode/bin" >> $GITHUB_PATH
|
|
|
|
- name: Execute OpenCode (Big Pickle)
|
|
env:
|
|
# OpenCode Zen Configuration
|
|
OPENCODE_ZEN_API_KEY: ${{ secrets.OPENCODE_ZEN_API_KEY }}
|
|
OPENCODE_API_BASE: https://opencode.ai
|
|
OPENCODE_MODEL: opencode/big-pickle
|
|
|
|
# Parametri Gitea passati in modo esplicito
|
|
GITEA_TOKEN: ${{ secrets.BOT_GITEA_TOKEN }}
|
|
GITEA_API_URL: "https://maribit.it"
|
|
|
|
# Contesto dell'evento estratti da Gitea
|
|
ISSUE_TITLE: ${{ github.event.issue.title }}
|
|
ISSUE_BODY: ${{ github.event.issue.body }}
|
|
COMMENT_BODY: ${{ github.event.comment.body }}
|
|
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
|
REPO_FULL_NAME: ${{ github.repository }}
|
|
run: |
|
|
# 1. Configurazione Git locale per permettere l'operatività sui branch
|
|
git config --global user.name "OpenCode Bot"
|
|
git config --global user.email "opencode-bot@maribit.it"
|
|
|
|
# 2. Creiamo un branch dedicato per la risoluzione della issue
|
|
BRANCH_NAME="opencode-fix-issue-$ISSUE_NUMBER"
|
|
git checkout -b "$BRANCH_NAME"
|
|
|
|
# 3. Puliamo il comando dal token di attivazione (/oc) per dare all'AI solo le istruzioni pulite
|
|
CLEAN_PROMPT=$(echo "$COMMENT_BODY" | sed 's|/oc||g' | sed 's|/opencode||g')
|
|
|
|
# 4. Eseguiamo l'agente OpenCode in modalità workspace locale sul codice scaricato
|
|
# L'AI analizzerà i file locali e applicherà i fix in base alla richiesta
|
|
opencode run \
|
|
--model "$OPENCODE_MODEL" \
|
|
--prompt "Risolvi il seguente problema nel codice. Contesto della Issue: $ISSUE_TITLE - $ISSUE_BODY. Richiesta specifica dell'utente: $CLEAN_PROMPT"
|
|
|
|
# 5. Se l'agente ha modificato dei file, facciamo il push e apriamo la PR su Gitea via API
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
git add .
|
|
git commit -m "Fix automatico OpenCode (Big Pickle) per issue #$ISSUE_NUMBER"
|
|
git push origin "$BRANCH_NAME"
|
|
|
|
# Chiamata API nativa a Gitea per creare la Pull Request
|
|
curl -X 'POST' \
|
|
"$GITEA_API_URL/repos/$REPO_FULL_NAME/pulls" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"base\":\"main\",\"head\":\"$BRANCH_NAME\",\"title\":\"PR Automatica OpenCode: Issue #$ISSUE_NUMBER\",\"body\":\"Risoluzione automatica generata dal modello big-pickle a fronte del commento: $CLEAN_PROMPT\"}"
|
|
else
|
|
echo "Nessuna modifica rilevata dall'agente OpenCode."
|
|
fi
|