koide f9239be35b
All checks were successful
Deploy Docusaurus Site / deploy (push) Successful in 26s
Update: gitea webhook article with latest process and merge duplicated process article
2026-02-27 03:40:07 +00:00

169 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
sidebar_position: 2
title: ローカルGitea × Webhook連携で、AIとの開発をもっと楽にしよう
description: GiteaのIssue/PR WebhookとOpenClawを連携し、壊れにくい自動レビュー開発フローを構築する実践ガイド
hide_table_of_contents: false
displayed_sidebar: null
---
# ローカルGitea × Webhook連携で、AIとの開発をもっと楽にしよう
## はじめに
Issueを作ったらAIがレビューして、PRが来たらAIが最終チェックして、最後はmainに安全に反映する。
この記事は、Gitea + OpenClaw 連携を **実運用で壊れにくく回すための最新版プロセス** をまとめたものです。
## できること
- Issue作成で AI レビュー/修正タスクを起動
- Pull Request 作成でも AI レビューを起動
- ブランチ運用・反映手順をテンプレ化して Git 不慣れでも回せる
- ブリッジを systemd 常駐して安定運用
## 最新アーキテクチャ
```
┌─────────┐ Webhook (issues / pull_request) ┌────────────────────┐
│ Gitea │ ────────────────────────────────────→ │ gitea-webhook-bridge │
└─────────┘ │ (bridge.py) │
└────────┬──────────┘
openclaw agent
code-review-loop
Issueコメント
```
## Webhook対象イベント
現在の推奨設定は以下です。
- `issues`:
- `opened`
- `pull_request`:
- `opened`
- `reopened`
- `synchronize`
`pull_request` 未対応だと、PRで `OK (ignored event)` になって自動レビューされません。
## bridge.py の要点
- `X-Gitea-Signature` で HMAC 検証
- `/webhook/gitea``issues` / `pull_request` を分岐処理
- `openclaw agent` を非同期で起動
- Webhookハンドラで例外が起きても **必ずHTTPレスポンスを返す**EOF対策
:::warning
`EOF` が出る場合、受信サーバーが例外落ちしてレスポンス返せていないケースが多いです。
`do_POST` 全体を `try/except` で保護し、`500` を返すようにしてください。
:::
## 運用で効いたルール
### 1) ブランチ命名を固定
- `fix/issue-<番号>-<要約>`
- `feat/issue-<番号>-<要約>`
- `docs/issue-<番号>-<要約>`
### 2) Issueコメントに毎回添える3点
- ブランチ切替コマンド
- 検証コマンド
- main へのマージコマンド
### 3) 機能を分離する
Webhook橋渡しを1つに詰め込みすぎると壊れます。
実運用では以下のように分離すると安全です。
- `gitea-webhook-bridge`Issue/PR連携専用
- `discord-notify-bridge`(通知専用)
サービスも別systemdに分離。
## systemd の基本
```ini title="/etc/systemd/system/gitea-webhook-bridge.service"
[Unit]
Description=Gitea Webhook Bridge for OpenClaw
After=network.target
[Service]
Type=simple
User=swallow
WorkingDirectory=/home/swallow/gitea-webhook-bridge
EnvironmentFile=/home/swallow/gitea-webhook-bridge/.env
ExecStart=/usr/bin/python3 /home/swallow/gitea-webhook-bridge/bridge.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
```
```bash
sudo systemctl daemon-reload
sudo systemctl enable --now gitea-webhook-bridge
sudo systemctl status gitea-webhook-bridge
```
## Gitea 側チェックポイント
### `ALLOWED_HOST_LIST`(必須)
```ini title="app.ini"
[webhook]
ALLOWED_HOST_LIST = private
```
### Webhook設定
- URL: `http://<bridge-host>:9876/webhook/gitea`
- Content-Type: `application/json`
- Secret: bridge側と一致
- トリガー: `issues`, `pull_request`
## Git弱者向けテンプレそのまま使える
### 作業ブランチへ切替
```bash
git fetch origin
git switch fix/issue-123-xxx
# 古いGit: git checkout fix/issue-123-xxx
```
### 検証
```bash
python3 -m py_compile src/*.py app/*.py
```
### mainへ反映
```bash
git switch main
git pull origin main
git merge --no-ff fix/issue-123-xxx
git push origin main
```
## まとめ
Gitea × OpenClaw 連携は、実装より運用設計が重要です。
- イベント対応Issue + PR
- 例外時のHTTP応答保証
- ブランチ/コメントテンプレの固定
- 機能分離(リポジトリ・サービス)
ここを押さえると、連携はかなり安定します。
---
*この記事は2026年2月時点の情報です。*