-
Notifications
You must be signed in to change notification settings - Fork 100
Add support for webhooks api #1169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds webhook management to the Meilisearch Python client: new webhook Pydantic models, client CRUD methods and config path, code-samples entries, tests, and an autouse fixture that clears webhooks around each test. Changes
Sequence Diagram(s)sequenceDiagram
participant Test
participant Client
participant API as Meilisearch API
Note over Test,Client: List webhooks
Test->>Client: get_webhooks()
Client->>API: GET /webhooks
API-->>Client: WebhooksResults
Client-->>Test: WebhooksResults
Note over Test,Client: Create webhook
Test->>Client: create_webhook({url, headers})
Client->>API: POST /webhooks
API-->>Client: Webhook (uuid)
Client-->>Test: Webhook
Note over Test,Client: Read / Update / Delete
Test->>Client: get_webhook(uuid)
Client->>API: GET /webhooks/{uuid}
API-->>Client: Webhook
Client-->>Test: Webhook
Test->>Client: update_webhook(uuid, {url})
Client->>API: PATCH /webhooks/{uuid}
API-->>Client: Webhook
Client-->>Test: Webhook
Test->>Client: delete_webhook(uuid)
Client->>API: DELETE /webhooks/{uuid}
API-->>Client: 204
Client-->>Test: 204 / status
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
meilisearch/client.py (1)
510-532: Clarify required fields in docstring.The docstring says options "Can include" url and headers but doesn't specify what's required. Based on the test coverage (test_create_webhook_missing_required_fields), the
urlfield appears to be required. Consider updating the docstring to be more explicit, similar to howcreate_key(lines 392-417) clearly states mandatory fields.Example improvement:
options: - The webhook configuration. Can include: - - url: The URL to send the webhook to - - headers: Dictionary of HTTP headers to include in webhook requests + The webhook configuration: + - url (required): The URL to send the webhook to + - headers (optional): Dictionary of HTTP headers to include in webhook requestsmeilisearch/models/webhook.py (1)
7-16: Consider adding field validation.The model correctly uses CamelBase for automatic case conversion and defines all necessary fields. As an optional enhancement, you could add Pydantic validators for the
urlfield (e.g.,HttpUrltype) anduuidfield (e.g., UUID format validation) to catch invalid data early.Example (optional):
from pydantic import HttpUrl, field_validator from uuid import UUID class Webhook(CamelBase): """Model for a Meilisearch webhook.""" model_config = ConfigDict(arbitrary_types_allowed=True) uuid: str # Could be UUID type url: str # Could be HttpUrl type headers: Optional[Dict[str, Any]] = None isEditable: bool @field_validator('uuid') def validate_uuid(cls, v): # Validate UUID format if desired return vtests/client/test_client_webhooks_meilisearch.py (1)
16-31: Consider verifying all headers in the assertion.The test creates a webhook with two headers (
AuthorizationandX-Custom-Header) but only verifiesX-Custom-Headerin the assertion (line 30). Consider verifying both headers or the complete headers dict to ensure the API correctly stores all provided headers.Optional enhancement:
assert webhook.uuid is not None assert webhook.url == webhook_data["url"] - assert webhook.headers["X-Custom-Header"] == webhook_data["headers"]["X-Custom-Header"] + assert webhook.headers == webhook_data["headers"]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.code-samples.meilisearch.yaml(1 hunks)meilisearch/client.py(2 hunks)meilisearch/config.py(1 hunks)meilisearch/models/webhook.py(1 hunks)tests/client/test_client_webhooks_meilisearch.py(1 hunks)tests/conftest.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
tests/client/test_client_webhooks_meilisearch.py (3)
meilisearch/errors.py (1)
MeilisearchApiError(28-51)tests/conftest.py (1)
client(15-16)meilisearch/client.py (5)
get_webhooks(471-486)create_webhook(510-532)get_webhook(488-508)update_webhook(534-558)delete_webhook(560-580)
meilisearch/client.py (3)
meilisearch/models/webhook.py (2)
Webhook(7-15)WebhooksResults(18-22)meilisearch/_httprequests.py (4)
get(95-96)post(98-108)patch(110-118)delete(142-147)meilisearch/index.py (1)
delete(88-105)
tests/conftest.py (1)
meilisearch/client.py (2)
get_webhooks(471-486)delete_webhook(560-580)
🔇 Additional comments (16)
.code-samples.meilisearch.yaml (1)
770-785: LGTM!The webhook code samples follow the existing patterns in this file and provide clear examples for all CRUD operations.
meilisearch/config.py (1)
50-50: LGTM!The webhook path constant follows the established pattern for other API paths.
meilisearch/client.py (5)
35-35: LGTM!The import statement follows the established pattern for other model imports in this file.
471-486: LGTM!The
get_webhooksimplementation follows the established pattern fromget_keys(lines 367-390). Consider adding optional pagination parameters in the future if the webhook API supports them, similar to howget_keysaccepts parameters.
488-508: LGTM!The
get_webhookmethod follows the established pattern fromget_key(lines 344-365) and correctly handles webhook retrieval by UUID.
534-558: LGTM!The
update_webhookmethod follows the established pattern fromupdate_key(lines 419-444) and correctly handles partial updates.
560-580: LGTM!The
delete_webhookmethod follows the established pattern fromdelete_key(lines 446-467) and correctly returns the status code.meilisearch/models/webhook.py (2)
1-4: LGTM!The imports are appropriate for Pydantic models that need camelCase conversion.
18-22: LGTM!The
WebhooksResultsmodel is simple and appropriate for wrapping the webhook list response. Note that unlike some other result models in the SDK, this doesn't include pagination fields (offset, limit, total). This should match the actual API response structure.tests/client/test_client_webhooks_meilisearch.py (7)
8-13: LGTM!This test correctly verifies the empty state when no webhooks exist.
33-47: LGTM!This test correctly verifies webhook retrieval by creating a webhook and then fetching it back.
49-52: LGTM!This negative test correctly verifies that fetching a non-existent webhook raises the appropriate error.
55-73: LGTM!This test correctly verifies webhook updates, ensuring the UUID persists while the URL is updated.
75-92: LGTM!This test provides comprehensive coverage of webhook deletion, verifying both the status code and confirming the webhook is actually deleted by attempting to retrieve it.
94-97: LGTM!This negative test correctly verifies that deleting a non-existent webhook raises the appropriate error.
100-110: LGTM!This validation test correctly verifies that the API enforces required fields when creating a webhook.
Strift
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jawad-khan and thanks for this contribution 🙌
Pull Request
This PR adds support for the Meilisearch Webhooks API to the Python SDK.
It introduces a new client methods to create, list, fetch, update, and delete webhooks.
The implementation follows the existing SDK structure and uses the same HTTP layer already in place. Basic tests are included to cover webhook creation, listing, fetching, delivery listing, and deletion.
Related issue
Fixes #1132
What does this PR do?
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!
Summary by CodeRabbit
New Features
Documentation
Tests