Hướng dẫn: GitHub PR Review Agent
Vấn đề: Team của bạn mở PR nhanh hơn bạn có thể review. PR nằm đợi nhiều ngày. Dev junior merge bug vì không ai có thời gian kiểm tra.
Giải pháp: Một AI agent giám sát repos 24/7, review mọi PR mới về bugs, vấn đề bảo mật, và chất lượng code, sau đó gửi tóm tắt cho bạn.
Bạn sẽ xây dựng:
┌───────────────────────────────────────────────────────────────────┐
│ │
│ Cron Timer ──▶ Hermes Agent ──▶ GitHub API ──▶ Review │
│ (mỗi 2h) + gh CLI (PR diffs) delivery │
│ + skill (Telegram, │
│ + memory Discord, │
│ local) │
│ │
└───────────────────────────────────────────────────────────────────┘
Hướng dẫn này dùng cron jobs để poll PR theo lịch — không cần server hay public endpoint. Hoạt động sau NAT và firewall.
Nếu bạn có public endpoint, xem Review PR GitHub tự động qua Webhooks — GitHub đẩy events tới Hermes ngay khi PR được mở hoặc cập nhật.
Yêu cầu trước
- Hermes Agent đã cài — xem Hướng dẫn cài đặt
- Gateway đang chạy cho cron jobs:
hermes gateway install # Cài như service
# hoặc
hermes gateway # Chạy foreground - GitHub CLI (
gh) đã cài và xác thực:# Cài đặt
brew install gh # macOS
sudo apt install gh # Ubuntu/Debian
# Xác thực
gh auth login - Messaging đã cấu hình (tùy chọn) — Telegram hoặc Discord
Dùng deliver: "local" để lưu reviews vào ~/.hermes/cron/output/. Tốt cho test trước khi kết nối thông báo.
Bước 1: Kiểm tra thiết lập
Đảm bảo Hermes truy cập được GitHub:
hermes
Test với lệnh đơn giản:
Run: gh pr list --repo NousResearch/hermes-agent --state open --limit 3
Bạn sẽ thấy danh sách PR đang mở. Nếu hoạt động, bạn đã sẵn sàng.
Bước 2: Thử review thủ công
Trong phiên chat, yêu cầu Hermes review một PR thật:
Review this pull request. Read the diff, check for bugs, security issues,
and code quality. Be specific about line numbers and quote problematic code.
Run: gh pr diff 3888 --repo NousResearch/hermes-agent
Hermes sẽ:
- Thực thi
gh pr diffđể lấy code changes - Đọc toàn bộ diff
- Tạo review có cấu trúc với findings cụ thể
Bước 3: Tạo Review Skill
Skill giúp Hermes có hướng dẫn review nhất quán:
mkdir -p ~/.hermes/skills/code-review
Tạo ~/.hermes/skills/code-review/SKILL.md:
---
name: code-review
description: Review pull requests for bugs, security issues, and code quality
---
# Code Review Guidelines
When reviewing a pull request:
## What to Check
1. **Bugs** — Logic errors, off-by-one, null/undefined handling
2. **Security** — Injection, auth bypass, secrets in code, SSRF
3. **Performance** — N+1 queries, unbounded loops, memory leaks
4. **Style** — Naming conventions, dead code, missing error handling
5. **Tests** — Are changes tested? Do tests cover edge cases?
## Output Format
For each finding:
- **File:Line** — exact location
- **Severity** — Critical / Warning / Suggestion
- **What's wrong** — one sentence
- **Fix** — how to fix it
## Rules
- Be specific. Quote the problematic code.
- Don't flag style nitpicks unless they affect readability.
- If the PR looks good, say so. Don't invent problems.
- End with: APPROVE / REQUEST_CHANGES / COMMENT
Bước 4: Dạy Hermes quy ước của team
Bắt đầu session và dạy Hermes tiêu chuẩn team:
Remember: In our backend repo, we use Python with FastAPI.
All endpoints must have type annotations and Pydantic models.
We don't allow raw SQL — only SQLAlchemy ORM.
Test files go in tests/ and must use pytest fixtures.
Những memories này tồn tại vĩnh viễn — reviewer sẽ tuân thủ quy ước mà không cần nhắc lại.
Bước 5: Tạo Cron Job tự động
hermes cron create "0 */2 * * *" \
"Check for new open PRs and review them.
Repos to monitor:
- myorg/backend-api
- myorg/frontend-app
Steps:
1. Run: gh pr list --repo REPO --state open --limit 5 --json number,title,author,createdAt
2. For each PR created or updated in the last 4 hours:
- Run: gh pr diff NUMBER --repo REPO
- Review the diff using the code-review guidelines
3. Format output as:
## PR Reviews — today
### [repo] #[number]: [title]
**Author:** [name] | **Verdict:** APPROVE/REQUEST_CHANGES/COMMENT
[findings]
If no new PRs found, say: No new PRs to review." \
--name "pr-review" \
--deliver telegram \
--skill code-review
Kiểm tra đã lên lịch:
hermes cron list
| Lịch | Khi nào |
|---|---|
0 */2 * * * | Mỗi 2 giờ |
0 9,13,17 * * 1-5 | 3 lần/ngày, chỉ ngày làm việc |
0 9 * * 1 | Tổng hợp sáng thứ Hai hàng tuần |
30m | Mỗi 30 phút (repos nhiều traffic) |
Không muốn đợi? Kích hoạt thủ công:
hermes cron run pr-review
Đăng review trực tiếp lên GitHub
Thêm vào prompt cron:
After reviewing, post your review:
- For issues: gh pr review NUMBER --repo REPO --comment --body "YOUR_REVIEW"
- For critical issues: gh pr review NUMBER --repo REPO --request-changes --body "YOUR_REVIEW"
- For clean PRs: gh pr review NUMBER --repo REPO --approve --body "Looks good"
Đảm bảo gh có token với scope repo. Reviews được đăng bằng tài khoản gh đã xác thực.
Xử lý sự cố
"gh: command not found" — Gateway chạy trong môi trường tối thiểu. Đảm bảo gh trong system PATH và restart gateway.
Reviews quá chung chung — Thêm skill code-review (Bước 3), dạy Hermes quy ước qua memory (Bước 4).
Cron job không chạy — hermes gateway status (gateway đang chạy?), hermes cron list (job đã bật?).
Rate limits — GitHub cho phép 5.000 API requests/giờ. Mỗi PR review dùng ~3-5 requests.
Xem thêm
- Review PR qua Webhook — review tức thì khi PR mở (cần public endpoint)
- Daily Briefing Bot — kết hợp PR review với tin tức buổi sáng
- Xây dựng Plugin — đóng gói logic review thành plugin chia sẻ
- Profiles — chạy profile reviewer riêng biệt
- Fallback Providers — đảm bảo review chạy khi provider gặp sự cố