Skip to content

dorokuma/github-notify-bot

Repository files navigation

GitHub Fork & Star 通知机器人

GitHub Fork & Star Notification Bot

一个轻量级的 GitHub 仓库动态监控工具,检测并推送 fork 和 star 事件到 Telegram。

A lightweight GitHub repository activity monitoring tool that detects and pushes fork and star events to Telegram.


功能

  • 轮询模式:定时检查 GitHub 仓库状态变化
  • Fork 通知:有新用户 fork 仓库时立即推送
  • Star 通知:有新用户 star 仓库时立即推送(支持获取精确的 star 用户和时间)
  • Telegram 推送:实时推送到指定 Telegram 频道或对话
  • 多用户监控:支持同时监控多个 GitHub 用户
  • 状态持久化:记录上次检查位置,避免重复通知
  • Rate Limit 处理:自动处理 GitHub API 限速,必要时主动等待
  • 分页支持:自动遍历所有 stargazer,不会漏掉

环境要求

  • Python 3.8+
  • GitHub Personal Access Token(具有 repo 权限)
  • Telegram Bot Token

安装

快速部署

git clone https://github.com/dorokuma/github-notify-bot.git
cd github-notify-bot
pip install -r requirements.txt
cp .env.example .env
# 编辑 .env 填入 GITHUB_TOKEN、TELEGRAM_BOT_TOKEN、TELEGRAM_CHAT_ID
chmod 600 .env
sudo cp github-notify-bot.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now github-notify-bot
# 查看状态
sudo systemctl status github-notify-bot

分步说明

git clone https://github.com/dorokuma/github-notify-bot.git
cd github-notify-bot
pip install -r requirements.txt

配置

环境变量

变量名 说明
GITHUB_TOKEN GitHub Personal Access Token,必须设置
TELEGRAM_BOT_TOKEN Telegram Bot Token,必须设置
TELEGRAM_CHAT_ID Telegram Chat ID,必须设置
TARGET_USERS 要监控的 GitHub 用户名(逗号分隔),默认 dorokuma
POLL_INTERVAL 轮询间隔(秒),默认300,最小60

获取 GitHub Token

  1. 访问 GitHub Settings > Personal Access Tokens
  2. 点击 Generate new token (classic)
  3. 选择 repo 权限范围
  4. 生成并保存 Token

获取 Telegram Bot Token

  1. 在 Telegram 中搜索 @BotFather
  2. 发送 /newbot
  3. 按照指示创建 Bot
  4. 保存生成的 Token

获取 Telegram Chat ID

  1. 将 Bot 添加到你的 Telegram 频道或对话
  2. 访问 https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
  3. 从 JSON 响应中获取 chat.id

运行

直接运行

export GITHUB_TOKEN="ghp_xxxxxxxxxxxxx"
python main.py

使用 systemd 管理服务

# 1. 复制 service 文件到系统目录
sudo cp github-notify-bot.service /etc/systemd/system/

# 2. 基于模板创建环境变量文件
cp .env.example /root/github-notify-bot/.env
# 编辑填入真实值(GITHUB_TOKEN, TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID 必须设置)
sudo nano /root/github-notify-bot/.env
chmod 600 /root/github-notify-bot/.env

# 3. 重载 systemd 并启用服务
sudo systemctl daemon-reload
sudo systemctl enable github-notify-bot
sudo systemctl start github-notify-bot

# 查看运行状态
sudo systemctl status github-notify-bot

.env 文件格式说明:纯 KEY=value 格式,每行一个,不要加 export 前缀,值前后不要加引号。.env 已被 .gitignore 排除,不会提交到 Git。修改 .env 后需要 systemctl daemon-reload && systemctl restart github-notify-bot 才能生效。


通知示例

Fork 通知

🍴 新Fork通知

📦 仓库: dorokuma/civitai-monitor
👤 Fork者: someuser
🕐 时间: 2026-05-27 14:30:00

🔗 链接: https://github.com/dorokuma/civitai-monitor/network/members

Star 通知

⭐ 新Star通知

📦 仓库: dorokuma/vigil
👤 收藏者: anotheruser
🕐 时间: 2026-05-27 15:00:00

🔗 链接: https://github.com/dorokuma/vigil/stargazers

工作原理

主循环 (每5分钟)
    │
    ▼
遍历所有目标用户的仓库
    │
    ▼
GitHub API: 获取 fork 列表
    │
    ▼
与上次记录对比,找出新增的 fork
    │
    ▼
发现新事件 → 发送 Telegram 通知
    │
    ▼
更新 state.json 保存当前检查位置

注意事项

  • 首次运行时会自动初始化状态,不会发送历史 star/fork 通知,只会记录当前位置
  • 轮询间隔建议不要低于 60 秒,避免触发 GitHub API 限速(5000次/小时)
  • 部署后修改环境变量需要重启服务:systemctl restart github-notify-bot
  • Star 通知失败时会重试(下一轮 poll 会重新检测),Fork 通知失败不会重试(因为 Fork 不可逆,状态在检测后立即推进)
  • 请定期轮换 GitHub Personal Access Token,避免 Token 过期或泄露后影响服务

License

MIT License

About

GitHub Fork Star 通知机器人,轮询监控并推送 Telegram

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages