initial: gitea-bot — mochi 全站 issue/PR 自动处理

systemd --user unit, polls famzheng.me/gitea every 60s, dispatches
`claude --dangerously-skip-permissions -p ...` per new activity.
sqlite state, log to ~/.local/state/gitea-bot/bot.log.
This commit is contained in:
Fam Zheng
2026-05-05 10:14:03 +01:00
commit f83ebf5854
5 changed files with 456 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
.PHONY: install uninstall restart status logs test-once
UNIT_DIR := $(HOME)/.config/systemd/user
STATE_DIR := $(HOME)/.local/state/gitea-bot
install:
@test -f $(HOME)/.gitea-mochi-token || (echo "missing $(HOME)/.gitea-mochi-token"; exit 1)
@test -x /home/fam/.local/bin/claude || (echo "missing claude bin"; exit 1)
mkdir -p $(UNIT_DIR) $(STATE_DIR)
install -m 644 gitea-bot.service $(UNIT_DIR)/gitea-bot.service
systemctl --user daemon-reload
systemctl --user enable --now gitea-bot
@sleep 1
systemctl --user status gitea-bot --no-pager -l | head -25
uninstall:
-systemctl --user disable --now gitea-bot
rm -f $(UNIT_DIR)/gitea-bot.service
systemctl --user daemon-reload
restart:
systemctl --user restart gitea-bot
systemctl --user status gitea-bot --no-pager -l | head -10
status:
systemctl --user status gitea-bot --no-pager -l | head -25
logs:
tail -n 200 -f $(STATE_DIR)/bot.log
test-once:
@# 单次轮询:reset state.db 让所有未处理 issue 都被 dispatch(慎用)
MOCHI_TOKEN=$$(cat $(HOME)/.gitea-mochi-token) python3 -c \
"import bot; bot.poll_once(bot.init_state(bot.CONFIG['state_dir']/'state.db'), open('$(HOME)/.gitea-mochi-token').read().strip())"