一个用于接收 GitHub Webhook 并通过 OneBot 协议将推送通知转发到 QQ 群的服务。
2.0K
user/*、*/*-api、org/[abc]* 等)main、release-*、feature/* 等)GitHub API 轮询:
自定义模板系统:
更多事件支持:
统计与监控:
git clone https://github.com/AptS-1547/onebot-github-webhook
cd onebot-github-webhook
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# 或者 .venv\Scripts\activate # Windows
pip install -r requirements.txt
# 或者使用 Poetry
# poetry install
在程序第一次运行时会自动生成 config.yaml 文件,您可以根据需要修改其中的配置项。
或者复制示例配置文件:
cp config/config.example.yaml config.yaml
配置文件 config.yaml 的结构如下:
ENV: "production" # 环境变量,可选值为 "production" 或 "development"
ONEBOT_URL: "ws://localhost:8080/ws" # OneBot 连接地址
ONEBOT_TYPE: "ws" # OneBot 连接类型,可选值为 "ws" 或 "http"
ONEBOT_ACCESS_TOKEN: "your_token" # OneBot 访问令牌
GITHUB_WEBHOOK:
- NAME: "github" # webhook 名称
REPO: # 监听的仓库列表,支持通配符匹配
- "username/repo"
- "username/*"
- "*/*-api"
BRANCH: # 监听的分支列表,支持通配符匹配
- "main"
- "develop"
- "feature/*"
- "release-*"
SECRET: "your_secret" # GitHub Webhook 密钥
EVENTS: # 监听的事件类型
- "push"
- "pull_request"
- "issues"
- "issue_comment"
- "release"
ONEBOT: # 通知的 OneBot 目标列表
- type: "group" # 目标类型,可选值为 "group" 或 "private"
id: 123456789 # 目标 ID,群号或用户 ID
uvicorn main:app --host 0.0.0.0 --port 8000
或者直接执行:
python main.py
http://你的服务器地址:8000/github-webhookapplication/jsonSECRET 相同的值对于无法使用 webhook 的场景(如私有仓库或受限环境),我们计划实现基于 GitHub API 的轮询机制。
GITHUB_API_POLLING:
- NAME: "polling-example"
REPO:
- "username/repo"
BRANCH:
- "main"
INTERVAL: 300 # 轮询间隔(秒)
EVENTS:
- "push"
- "pull_request"
TOKEN: "github_personal_access_token" # GitHub 个人访问令牌
ONEBOT:
- type: "group"
id: 123456789
功能:
实现计划:
APScheduler 实现定时任务aiohttp 实现异步 HTTP 请求允许用户自定义各类事件的通知消息格式,提供更灵活的展示方式。
模板存储:
templates/ 目录下templates/push.txt、templates/issues.txt 等配置方式:
GITHUB_WEBHOOK:
- NAME: "github"
REPO:
- "username/repo"
BRANCH:
- "main"
SECRET: "your_secret"
EVENTS:
- "push"
- "issues"
TEMPLATES: # 为不同事件类型指定自定义模板
push: "custom_push.txt" # 使用自定义推送模板
issues: "default" # 使用默认 issues 模板
ONEBOT:
- type: "group"
id: 123456789
模板示例 (templates/push.txt):
📢 GitHub 推送通知
仓库:{{ repo_name }}
分支:{{ branch }}
推送者:{{ pusher }}
提交数量:{{ commit_count }}
{% for commit in commits %}
[{{ loop.index }}] {{ commit.id[:7] }} by {{ commit.author.name }}
{{ commit.message.split('\n')[0] }}
{% endfor %}
模板示例 (templates/issues.txt):
📋 Issue {{ action }}
仓库:{{ repo_name }}
标题:{{ issue.title }}
作者:{{ issue.user.login }}
链接:{{ issue.html_url }}
功能:
实现计划:
onebot-github-webhook/
│
├── app/ # 应用程序核心模块
│ ├── api/ # API 接口
| ├ └── github_webhook.py # GitHub Webhook 接口
│ ├── core/ # 核心功能
│ │ └── github.py # GitHub Webhook 处理逻辑
│ ├── models/ # 数据模型
│ │ └── config.py # 配置模型
| ├── onebot/ # OneBot 发送器
│ │ └── onebot.py # OneBot 消息发送客户端
│ └── utils/ # 工具函数
| ├── exceptions.py # 异常处理
│ └── matching.py # 匹配规则工具
│
├── config/ # 配置文件目录
│ ├── config.example.yaml # 示例配置文件
│ └── templates/ # 消息模板目录
│ ├── push/ # 推送事件模板
│ ├── issues/ # Issue 事件模板
│ └── pull_request/ # Pull Request 事件模板
│
├── docs/ # 文档目录
│ └── src/ # mdBook 文档源
│
├── tests/ # 测试目录
│ ├── test_matching.py # 匹配规则测试
│ ├── test_onebot_sender.py # OneBot 发送器测试
│ └── test_webhook_signature.py # Webhook 签名验证测试
│
├── docker/ # Docker 相关文件
│ └── docker-compose.yml # Docker Compose 配置文件
│
├── main.py # 应用程序入口点
├── Dockerfile # Docker 构建文件
├── pyproject.toml # Python 项目配置
├── poetry.lock # Poetry 依赖锁定文件
└── README.md # 项目说明文档
docker run -d \
--name onebot-github-webhook \
-p 8000:8000 \
-v $(pwd)/config.yaml:/app/config.yaml \
e1saps/onebot-github-webhook:latest
或使用 Docker Compose:
cd docker
docker-compose up -d
创建 /etc/systemd/system/onebot-github-webhook.service:
[Unit]
Description=OneBot GitHub Webhook Service
After=network.target
[Service]
User=www-data
WorkingDirectory=/opt/onebot-github-webhook
ExecStart=/opt/onebot-github-webhook/.venv/bin/python -m uvicorn main:app --host 0.0.0.0 --port 8000
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
启用服务:
sudo systemctl enable onebot-github-webhook
sudo systemctl start onebot-github-webhook
Q: Webhook 触发但 QQ 未收到消息怎么办?
A: 请检查以下几点:
Q: 如何支持多个 QQ 机器人?
A: 本程序暂时不支持推送到多个 QQ 机器人
欢迎提交 Pull Request 或 Issue 来帮助改进本项目!
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)本项目采用 Apache License 2.0 许可证。
Content type
Image
Digest
sha256:f11ce3239…
Size
26.5 MB
Last updated
over 1 year ago
docker pull e1saps/onebot-github-webhook