Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

Adds GitHub webhook platform support to receive and process repository events (issue created, issue comment, PR created) within AstrBot's messaging system.

Modifications / 改动点

New Platform Adapter (astrbot/core/platform/sources/github_webhook/)

  • github_webhook_adapter.py: Platform adapter implementing webhook callback handling
    • Processes issues (opened), issue_comment (created), pull_request (opened) events
    • HMAC signature verification (SHA256/SHA1) with timing-safe comparison
    • Formats events as structured messages with repo, author, title, content preview
  • github_webhook_event.py: Event wrapper storing GitHub event metadata

Platform Registration

  • manager.py: Added github_webhook to platform loader

Security

  • Optional webhook secret for request authentication
  • Rejects invalid signatures with HTTP 401
  • Supports both X-Hub-Signature-256 and legacy X-Hub-Signature headers

Integration

  • Uses unified webhook mode via dashboard endpoint /api/platform/webhook/{uuid}
  • Gracefully handles unsupported events and actions

Tests (tests/test_github_webhook.py)

  • 9 test cases: initialization, event handling, signature verification, error cases
  • All passing

Example webhook configuration:

{
    "type": "github_webhook",
    "enable": true,
    "id": "my_github_webhook",
    "unified_webhook_mode": true,
    "webhook_uuid": "unique-uuid-here",
    "webhook_secret": "optional-secret"  # For signature verification
}
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

tests/test_github_webhook.py::TestGitHubWebhookAdapter::test_adapter_initialization PASSED [ 11%]
tests/test_github_webhook.py::TestGitHubWebhookAdapter::test_ping_event PASSED [ 22%]
tests/test_github_webhook.py::TestGitHubWebhookAdapter::test_issue_created_event PASSED [ 33%]
tests/test_github_webhook.py::TestGitHubWebhookAdapter::test_issue_comment_event PASSED [ 44%]
tests/test_github_webhook.py::TestGitHubWebhookAdapter::test_pull_request_event PASSED [ 55%]
tests/test_github_webhook.py::TestGitHubWebhookAdapter::test_unsupported_event PASSED [ 66%]
tests/test_github_webhook.py::TestGitHubWebhookAdapter::test_issue_closed_ignored PASSED [ 77%]
tests/test_github_webhook.py::TestGitHubWebhookAdapter::test_signature_verification PASSED [ 88%]
tests/test_github_webhook.py::TestGitHubWebhookAdapter::test_invalid_signature PASSED [100%]

9 passed, 1 warning in 2.99s

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.soulter.top
    • Triggering command: /home/REDACTED/work/AstrBot/AstrBot/.venv/bin/pytest pytest tests/ -v -k not test_main --tb=short (dns block)
  • example.com
    • Triggering command: /home/REDACTED/work/AstrBot/AstrBot/.venv/bin/pytest pytest tests/ -v -k not test_main --tb=short (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

add GitHub WebHook platform. Supports event: issue created, comment, pr created.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add GitHub WebHook platform for issue and PR events Add GitHub webhook platform adapter Dec 12, 2025
Copilot AI requested a review from Soulter December 12, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants