Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22e42b2858 | ||
|
|
b4717eba19 | ||
|
|
7a86e6500f | ||
|
|
800b359f60 | ||
|
|
6b7ecffebb | ||
|
|
6ce001482a | ||
|
|
e141c32c37 |
@@ -1,6 +1,8 @@
|
||||
name: OpenCode Gitea Integration
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [opened]
|
||||
issue_comment:
|
||||
types: [created]
|
||||
pull_request_review_comment:
|
||||
@@ -15,8 +17,10 @@ jobs:
|
||||
opencode-gitea:
|
||||
if: |
|
||||
github.event_name == 'workflow_dispatch' ||
|
||||
contains(github.event.comment.body, '/oc') ||
|
||||
contains(github.event.comment.body, '/opencode')
|
||||
(github.event_name == 'issues' &&
|
||||
(contains(github.event.issue.body, '/oc') || contains(github.event.issue.body, '/opencode'))) ||
|
||||
(github.event_name != 'issues' &&
|
||||
(contains(github.event.comment.body, '/oc') || contains(github.event.comment.body, '/opencode')))
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
|
||||
@@ -24,22 +28,23 @@ jobs:
|
||||
GITEA_API_URL: "https://gitea.maribit.it"
|
||||
GITEA_TOKEN: ${{ secrets.BOT_GITEA_TOKEN }}
|
||||
REPO_FULL_NAME: ${{ github.repository }}
|
||||
COMMENT_BODY: ${{ github.event.comment.body || github.event.inputs.prompt }}
|
||||
COMMENT_AUTHOR: ${{ github.event.comment.user.login }}
|
||||
COMMENT_BODY: ${{ github.event.comment.body || github.event.issue.body || github.event.inputs.prompt }}
|
||||
COMMENT_AUTHOR: ${{ github.event.comment.user.login || github.event.issue.user.login || github.actor }}
|
||||
COMMENT_ID: ${{ github.event.comment.id }}
|
||||
IS_PR_EVENT: ${{ github.event_name == 'pull_request_review_comment' }}
|
||||
IS_MANUAL: ${{ github.event_name == 'workflow_dispatch' }}
|
||||
PR_NUMBER_FROM_EVENT: ${{ github.event.pull_request.number }}
|
||||
PR_HEAD_REF_FROM_EVENT: ${{ github.event.pull_request.head.ref }}
|
||||
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
||||
ISSUE_TITLE: ${{ github.event.issue.title }}
|
||||
ISSUE_BODY: ${{ github.event.issue.body }}
|
||||
RUN_NUMBER: ${{ github.run_number }}
|
||||
|
||||
steps:
|
||||
- name: Verifica autorizzazione utente
|
||||
run: |
|
||||
# Whitelist esplicita: nessuna esecuzione automatica per utenti non fidati.
|
||||
#ALLOWED_USERS="nicola-brecciaroli tuo-secondo-maintainer"
|
||||
ALLOWED_USERS="maria nicola"
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
if [ "$IS_MANUAL" = "true" ]; then
|
||||
exit 0
|
||||
fi
|
||||
if ! echo " $ALLOWED_USERS " | grep -q " $COMMENT_AUTHOR "; then
|
||||
@@ -47,6 +52,27 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Feedback immediato: 👀 sul commento (o sulla issue) che ha invocato l'agente.
|
||||
# Le reazioni NON generano eventi issue_comment -> nessun doppio run.
|
||||
- name: Reagisci al comando (👀)
|
||||
id: react
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
if [ -n "$COMMENT_ID" ]; then
|
||||
RPATH="issues/comments/$COMMENT_ID/reactions"
|
||||
elif [ -n "$ISSUE_NUMBER" ]; then
|
||||
RPATH="issues/$ISSUE_NUMBER/reactions"
|
||||
else
|
||||
RPATH=""
|
||||
fi
|
||||
echo "path=$RPATH" >> "$GITHUB_OUTPUT"
|
||||
if [ -n "$RPATH" ]; then
|
||||
curl -s -X POST "$API/$RPATH" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"content":"eyes"}' >/dev/null || true
|
||||
fi
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
@@ -57,7 +83,7 @@ jobs:
|
||||
curl -fsSL https://opencode.ai/install | bash
|
||||
echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Determina contesto (issue vs PR esistente) e branch di lavoro
|
||||
- name: Determina contesto (issue / PR / manuale) e branch di lavoro
|
||||
id: ctx
|
||||
run: |
|
||||
set -e
|
||||
@@ -66,15 +92,18 @@ jobs:
|
||||
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
|
||||
if [ "$IS_PR_EVENT" = "true" ]; then
|
||||
# Commento inline su una review: la PR e il suo branch sono già noti dal payload.
|
||||
if [ "$IS_MANUAL" = "true" ]; then
|
||||
IS_PR=false
|
||||
PR_NUMBER=""
|
||||
BRANCH_NAME="opencode-manual-$RUN_NUMBER"
|
||||
elif [ "$IS_PR_EVENT" = "true" ]; then
|
||||
IS_PR=true
|
||||
PR_NUMBER="$PR_NUMBER_FROM_EVENT"
|
||||
BRANCH_NAME="$PR_HEAD_REF_FROM_EVENT"
|
||||
IS_PR=true
|
||||
else
|
||||
# issue_comment: può essere una issue "pura" o un commento generale su una PR.
|
||||
# issue / issue_comment: la chiave "pull_request" c'è sempre ma vale null per le issue.
|
||||
ISSUE_JSON=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$API/issues/$ISSUE_NUMBER")
|
||||
if echo "$ISSUE_JSON" | grep -q '"pull_request"'; then
|
||||
if [ "$(echo "$ISSUE_JSON" | jq -r '.pull_request // empty')" != "" ]; then
|
||||
IS_PR=true
|
||||
PR_NUMBER="$ISSUE_NUMBER"
|
||||
PR_JSON=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$API/pulls/$PR_NUMBER")
|
||||
@@ -86,24 +115,26 @@ jobs:
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "null" ]; then
|
||||
echo "BRANCH_NAME non valido ('$BRANCH_NAME'). Interrompo."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "is_pr=$IS_PR" >> "$GITHUB_OUTPUT"
|
||||
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
|
||||
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
|
||||
|
||||
if [ "$IS_PR" = "true" ]; then
|
||||
# Continua a lavorare sullo STESSO branch della PR esistente (loop di review).
|
||||
git fetch origin "$BRANCH_NAME"
|
||||
git checkout -B "$BRANCH_NAME" "origin/$BRANCH_NAME"
|
||||
elif git ls-remote --exit-code --heads origin "$BRANCH_NAME" >/dev/null 2>&1; then
|
||||
# Un run precedente ha già creato questo branch per la stessa issue: riprendilo.
|
||||
git fetch origin "$BRANCH_NAME"
|
||||
git checkout -B "$BRANCH_NAME" "origin/$BRANCH_NAME"
|
||||
else
|
||||
git checkout -b "$BRANCH_NAME"
|
||||
fi
|
||||
|
||||
- name: Raccogli contesto aggiuntivo (diff + commenti di review, se PR)
|
||||
id: extra
|
||||
- name: Raccogli contesto aggiuntivo (diff + commenti, se PR)
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
: > /tmp/context.txt
|
||||
@@ -111,29 +142,24 @@ jobs:
|
||||
PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
|
||||
echo "== Diff della PR ==" >> /tmp/context.txt
|
||||
curl -s -H "Authorization: token $GITEA_TOKEN" "$API/pulls/$PR_NUMBER.diff" >> /tmp/context.txt
|
||||
echo "== Commenti di review recenti ==" >> /tmp/context.txt
|
||||
echo "== Commenti recenti ==" >> /tmp/context.txt
|
||||
curl -s -H "Authorization: token $GITEA_TOKEN" "$API/issues/$PR_NUMBER/comments" \
|
||||
| jq -r '.[] | "- (\(.user.login)): \(.body)"' >> /tmp/context.txt
|
||||
| jq -r '.[] | "- (\(.user.login)): \(.body)"' >> /tmp/context.txt || true
|
||||
fi
|
||||
|
||||
- name: Pulisci il comando dal trigger
|
||||
id: prompt
|
||||
run: |
|
||||
CLEAN_PROMPT=$(echo "$COMMENT_BODY" | sed -e 's|/oc||g' -e 's|/opencode||g')
|
||||
{
|
||||
echo "clean<<'EOF'"
|
||||
echo "$CLEAN_PROMPT"
|
||||
echo "EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
CLEAN_PROMPT=$(printf '%s' "$COMMENT_BODY" | sed -e 's|/opencode||g' -e 's|/oc||g')
|
||||
printf '%s' "$CLEAN_PROMPT" > /tmp/clean_prompt.txt
|
||||
|
||||
- name: Esegui OpenCode
|
||||
env:
|
||||
OPENCODE_ZEN_API_KEY: ${{ secrets.OPENCODE_ZEN_API_KEY }}
|
||||
OPENCODE_API_BASE: https://opencode.ai
|
||||
OPENCODE_MODEL: opencode/big-pickle
|
||||
CLEAN_PROMPT: ${{ steps.prompt.outputs.clean }}
|
||||
run: |
|
||||
CONTEXT=$(cat /tmp/context.txt)
|
||||
CLEAN_PROMPT=$(cat /tmp/clean_prompt.txt)
|
||||
CONTEXT=$(cat /tmp/context.txt 2>/dev/null || true)
|
||||
opencode run \
|
||||
--model "$OPENCODE_MODEL" \
|
||||
"Contesto della Issue/PR: $ISSUE_TITLE - $ISSUE_BODY
|
||||
@@ -155,22 +181,33 @@ jobs:
|
||||
fi
|
||||
|
||||
git add .
|
||||
git commit -m "OpenCode (big-pickle): risposta a feedback su #${ISSUE_NUMBER:-${{ steps.ctx.outputs.pr_number }}}"
|
||||
git commit -m "OpenCode (big-pickle): $BRANCH_NAME"
|
||||
git push origin "$BRANCH_NAME"
|
||||
|
||||
if [ "${{ steps.ctx.outputs.is_pr }}" != "true" ]; then
|
||||
curl -s -X POST "$API/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 da big-pickle a fronte del commento di @$COMMENT_AUTHOR.\"}"
|
||||
-d "{\"base\":\"main\",\"head\":\"$BRANCH_NAME\",\"title\":\"PR Automatica OpenCode: $BRANCH_NAME\",\"body\":\"Generata da big-pickle su richiesta di @$COMMENT_AUTHOR.\"}"
|
||||
fi
|
||||
|
||||
- name: Commenta l'esito
|
||||
if: always()
|
||||
# Stato finale via reazione (niente commenti -> niente self-trigger).
|
||||
- name: Reazione finale 🚀
|
||||
if: success() && steps.react.outputs.path != ''
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
TARGET="${{ steps.ctx.outputs.pr_number || env.ISSUE_NUMBER }}"
|
||||
curl -s -X POST "$API/issues/$TARGET/comments" \
|
||||
curl -s -X POST "$API/${{ steps.react.outputs.path }}" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"body\":\"🤖 OpenCode ha completato l'elaborazione della richiesta di @$COMMENT_AUTHOR.\"}"
|
||||
-d '{"content":"rocket"}' >/dev/null || true
|
||||
|
||||
- name: Reazione finale 😕 (fallimento)
|
||||
if: failure() && steps.react.outputs.path != ''
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
curl -s -X POST "$API/${{ steps.react.outputs.path }}" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"content":"confused"}' >/dev/null || true
|
||||
@@ -1,3 +1,47 @@
|
||||
### PROVA
|
||||
# Test di Actions e Automazione Agentica su Gitea
|
||||
|
||||
- repo di prova
|
||||
Questo repository è un test per verificare il funzionamento delle **Actions** e dell'**automazione agentica** collegata a eventi su Gitea.
|
||||
|
||||
Lo scopo è sperimentare l'esecuzione automatica di workflow in risposta a eventi come push, pull request e altri trigger, utilizzando agenti AI per operazioni di review, merge e gestione del repository.
|
||||
|
||||
## Workflow: `Gitea Actions Demo` (`.gitea/workflows/demo.yml`)
|
||||
|
||||
Workflow dimostrativo che si attiva ad ogni **push** su qualsiasi branch. Esegue su un container `node:20-alpine` e stampa una serie di messaggi informativi via `echo` per illustrare il funzionamento base di Gitea Actions:
|
||||
- Mostra l'evento che ha scatenato il workflow (`gitea.event_name`)
|
||||
- Mostra il runner OS e il branch/repository coinvolto
|
||||
- Fa il checkout del codice tramite `actions/checkout@v4`
|
||||
- Elenca i file nella workspace
|
||||
- Comunica lo stato finale del job (`job.status`)
|
||||
|
||||
Non esegue operazioni di modifica o deploy: è puramente a scopo educativo/dimostrativo.
|
||||
|
||||
## Workflow: `OpenCode Gitea Integration` (`.gitea/workflows/opencode.yml`)
|
||||
|
||||
Workflow di automazione agentica che integra **OpenCode** (agente AI) con Gitea. Si attiva su quattro eventi:
|
||||
|
||||
| Evento | Descrizione |
|
||||
|---|---|
|
||||
| `issues: [opened]` | Apertura di una nuova issue |
|
||||
| `issue_comment: [created]` | Nuovo commento su una issue |
|
||||
| `pull_request_review_comment: [created]` | Nuovo commento su una PR (review) |
|
||||
| `workflow_dispatch` | Esecuzione manuale tramite UI / API |
|
||||
|
||||
Il workflow procede solo se il corpo della issue/commento contiene `/oc` o `/opencode` (oppure se è un'esecuzione manuale). L'autore deve essere tra gli utenti autorizzati (`maria`, `nicola`), altrimenti il job viene interrotto.
|
||||
|
||||
### Schema di esecuzione
|
||||
|
||||
1. **Autorizzazione** — Verifica che l'utente sia nella whitelist.
|
||||
2. **Reazione 👀** — Aggiunge una reazione "eyes" al commento/issue di trigger (feedback visivo immediato senza generare nuovi eventi).
|
||||
3. **Checkout** — Clona il repository con storia completa (`fetch-depth: 0`).
|
||||
4. **Installazione OpenCode** — Scarica e installa la CLI di OpenCode via `curl | bash`.
|
||||
5. **Determinazione contesto** — Capisce se si è in una issue, in una PR o in esecuzione manuale:
|
||||
- **PR**: fa il fetch e checkout del branch della PR.
|
||||
- **Issue**: crea un nuovo branch `opencode-issue-<N>` a partire da `main`.
|
||||
- **Manuale**: crea un branch `opencode-manual-<run_number>`.
|
||||
6. **Raccolta contesto** — Se si tratta di una PR, scarica il **diff** e i **commenti** recenti per fornire contesto all'agente.
|
||||
7. **Pulizia comando** — Rimuove `/oc` o `/opencode` dal prompt, lasciando solo le istruzioni utente.
|
||||
8. **Esecuzione OpenCode** — Lancia l'agente AI con modello `opencode/big-pickle`, passando il contesto raccolto e la richiesta dell'utente. L'agente può leggere, modificare e creare file nel repository.
|
||||
9. **Push e PR** — Se ci sono modifiche, le committa e le pusha sul branch. Se si sta lavorando su una issue (non PR), apre automaticamente una **Pull Request** verso `main`.
|
||||
10. **Reazione finale** — Aggiunge una reazione 🚀 in caso di successo o 😕 in caso di fallimento.
|
||||
|
||||
Il workflow è progettato per evitare auto-trigger: le reazioni alle issue/commenti non generano eventi `issue_comment`, e il workflow non scrive mai commenti (solo reazioni), prevenendo loop infiniti.
|
||||
+104
-2
@@ -4,9 +4,111 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Prova</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
backdrop-filter: blur(10px);
|
||||
border-radius: 24px;
|
||||
padding: 3rem 3.5rem;
|
||||
max-width: 480px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
box-shadow:
|
||||
0 20px 60px rgba(0, 0, 0, 0.15),
|
||||
0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow:
|
||||
0 30px 80px rgba(0, 0, 0, 0.2),
|
||||
0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
margin: 0 auto 1.5rem;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 700;
|
||||
color: #1a1a2e;
|
||||
margin-bottom: 0.75rem;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1rem;
|
||||
line-height: 1.6;
|
||||
color: #555;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.divider {
|
||||
width: 48px;
|
||||
height: 4px;
|
||||
margin: 0 auto 2rem;
|
||||
background: linear-gradient(90deg, #667eea, #764ba2);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 0.4rem 1.2rem;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: #fff;
|
||||
border-radius: 100px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.card {
|
||||
padding: 2rem 1.5rem;
|
||||
border-radius: 16px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Pagina di prova</h1>
|
||||
<p>Questa è una pagina HTML di test.</p>
|
||||
<div class="card">
|
||||
<div class="icon">✨</div>
|
||||
<div class="divider"></div>
|
||||
<h1>Pagina di prova</h1>
|
||||
<p>Questa è una pagina HTML di test realizzata con cura per un aspetto più elegante e moderno.</p>
|
||||
<span class="badge">HTML · CSS · Design</span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user