Skip to content

Commit 92960b1

Browse files
doodlaclaude
andcommitted
Update GitHub API URLs and add docstrings
- Update 51 deprecated GitHub API URLs from developer.github.com to docs.github.com with event-specific anchors - Add docstrings to decorators.py public API (@hook, handle_webhook) - Add docstrings to all event classes with descriptions - Add docstrings to key model classes and helper functions - Follow Google-style docstring format without Attributes sections 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d76e102 commit 92960b1

3 files changed

Lines changed: 352 additions & 94 deletions

File tree

octohook/decorators.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414

1515
class _WebhookDecorator:
16+
"""Internal class managing webhook handler registration and dispatch.
17+
18+
Maintains a three-level handler registry: event -> action -> repository.
19+
Handles debug mode where only debug handlers fire for an event.
20+
"""
21+
1622
def __init__(self):
1723
self.handlers = defaultdict( # event_name
1824
lambda: defaultdict(lambda: defaultdict(set)) # action # repo # handlers
@@ -25,6 +31,20 @@ def webhook(
2531
repositories: List[str] = None,
2632
debug=False,
2733
):
34+
"""Decorator to register a function as a webhook handler.
35+
36+
Args:
37+
event: The webhook event type to handle.
38+
actions: Optional list of actions to filter on. If None, handles all actions.
39+
repositories: Optional list of repository full names (owner/repo) to filter on.
40+
debug: If True, only this handler runs for the event (other handlers are skipped).
41+
42+
Example:
43+
@hook(WebhookEvent.PULL_REQUEST, actions=[WebhookEventAction.OPENED])
44+
def on_pr_opened(event: PullRequestEvent):
45+
print(f"PR opened: {event.pull_request.title}")
46+
"""
47+
2848
def real_decorator(fn):
2949
@wraps(fn)
3050
def wrapper(*, event_name, payload):
@@ -58,6 +78,18 @@ def wrapper(*, event_name, payload):
5878
return real_decorator
5979

6080
def handle_webhook(self, event_name: str, payload: dict):
81+
"""Dispatch a webhook payload to registered handlers.
82+
83+
Finds all matching handlers for the event/action/repository combination
84+
and executes them sequentially. Exceptions are logged but don't stop execution.
85+
86+
Args:
87+
event_name: The GitHub event name (e.g., "pull_request", "issues").
88+
payload: The raw webhook payload dictionary from GitHub.
89+
90+
Example:
91+
handle_webhook("pull_request", request.json)
92+
"""
6193
action_handlers = self.handlers[WebhookEvent(event_name)]
6294

6395
# These handlers are invoked all the time.

0 commit comments

Comments
 (0)