Some checks are pending
CI / test (push) Waiting to run
config.yaml previously mixed secrets with the phrase list, forcing private-only edits. Now config supports phrases_file, which is loaded and merged with any private phrases: entries, so the repo-tracked phrases.yaml can be extended via PR while per-deployment additions stay private. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
65 lines
3.2 KiB
Markdown
65 lines
3.2 KiB
Markdown
# yaju-is-always-watching-you (語録警察)
|
|
|
|
Forgejo用の言葉遣い是正bot。淫夢語録その他のネタ言葉遣いをissue/PRコメントやpushされたファイルから検知し、
|
|
|
|
- コメント/PRへの投稿 → 投稿者に `@mention` して警告リプライ
|
|
- push → 該当箇所を伏字にした修正ブランチを自動で切り、是正PRをオープン(原文の`git push`やコミット履歴は一切書き換えない)
|
|
|
|
を行う、クソ真面目にクソどうでもいい機能を実装したbotです。野獣はいつもお前を見ている。
|
|
|
|
## 仕組み
|
|
|
|
Forgejoのwebhook(`issue_comment` / `push`)を受け取るだけの単純なHTTPサーバーです。リポジトリごとに何かを仕込む必要はなく、Organization/インスタンス全体のwebhookとして1箇所に登録するだけで全リポジトリに効きます。
|
|
|
|
```
|
|
Forgejo --webhook--> yaju-keisatsu --Forgejo API--> コメント投稿 / 是正PR作成
|
|
```
|
|
|
|
## セットアップ
|
|
|
|
### 1. bot用アカウントとトークンを作る
|
|
|
|
Forgejo上にbot専用アカウント(例: `yaju-keisatsu-bot`)を作り、そのアカウントで Settings > Applications からAPIトークンを発行する。対象リポジトリへの読み書き・issue・pull request権限があれば十分。
|
|
|
|
### 2. 設定ファイルを用意
|
|
|
|
```bash
|
|
cp config.example.yaml config.yaml
|
|
```
|
|
|
|
`config.yaml` を編集し、`forgejo.base_url` / `forgejo.token` / `webhook_secret` / `bot.username` を埋める。
|
|
|
|
語録リストは [phrases.yaml](./phrases.yaml) にコミュニティ管理のものが同梱されており、`config.yaml` の `phrases_file: ./phrases.yaml` で読み込む(デフォルトで設定済み)。追加・削除の提案はPRで歓迎。自分の運用だけで使いたい追加語録があれば、それとは別に `config.yaml` の `phrases:` に書けば `phrases_file` の内容とマージされる。
|
|
|
|
`config.yaml` は秘密情報を含むため絶対にコミットしないこと(`.gitignore` 済み)。
|
|
|
|
### 3. 起動
|
|
|
|
```bash
|
|
go run ./cmd/yaju-is-always-watching-you -config config.yaml
|
|
```
|
|
|
|
または Docker で:
|
|
|
|
```bash
|
|
docker build -t yaju-keisatsu .
|
|
docker run -p 8080:8080 -v $(pwd)/config.yaml:/etc/yaju-keisatsu/config.yaml yaju-keisatsu
|
|
```
|
|
|
|
### 4. Forgejoにwebhookを登録
|
|
|
|
インスタンス管理画面(サイト全体)、または Organization / リポジトリ単位の Settings > Webhooks から新規Webhookを追加:
|
|
|
|
- Target URL: `https://<yaju-keisatsuを立てたホスト>/webhook`
|
|
- HTTP Method: `POST`
|
|
- Trigger On: `Issue Comment`, `Push`
|
|
- Secret: `config.yaml` の `webhook_secret` と同じ値
|
|
|
|
## 動作の安全設計
|
|
|
|
- **削除や強制pushは一切行わない。** コメントは削除せず警告リプライのみ、pushされたコミット履歴も書き換えず、常に新規ブランチ+PRという提案どまりの形にしている。
|
|
- **自己ループ防止。** `bot.username` に設定したアカウント自身のコメント/pushには反応しない。これがないとbotの警告リプライ自体に語録が含まれて無限に自己反応してしまう。
|
|
|
|
## ライセンス
|
|
|
|
MIT License。[LICENSE](./LICENSE) 参照。Issue・PR歓迎。
|