-
Notifications
You must be signed in to change notification settings - Fork 374
📝 Document webhooks #554
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
📝 Document webhooks #554
Changes from 23 commits
c0124e7
40ca212
b9dca40
0d7a9f2
868df3e
ccd7b17
66930b8
aedb144
f0da9c7
98e68d7
3913170
b756d57
22897e7
9cbb7eb
9d3daaa
01574e5
99e742c
7f284f8
af52533
efb995d
75ab75a
7c400b5
23f96c4
f2ce396
e824dc7
a4107d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| # Webhooks | ||
|
|
||
| Webhooks are a foundation for MLOps related features. You can use this to auto-convert models, build community bots, or build CI/CD for your models, datasets, and Spaces. | ||
|
|
||
coyotte508 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| They allow you to react when new changes happen on specific repos or repos belonging to specific users / organizations (not just your repos, but any repo!). | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| You can configure the webhooks in your [settings](https://huggingface.co/settings/webhooks): | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
|
|
||
| You can watch repo changes, discussions, and Pull requests and comments. You can even use a Space to react to webhooks! | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <!-- Todo: add a link to a guide with a real example --> | ||
|
|
||
| ## Webhook Payloads | ||
|
|
||
| After registering a webhook, you will be notified of events via an `HTTP POST` call on the specified URL. The payload is encoded in JSON. | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| You can check the last payloads sent in the activity tab of the webhook page, as well as replay webhooks: | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
|  | ||
|
|
||
| As an example, here is the full payload when a Pull request is opened: | ||
|
|
||
| ```json | ||
| { | ||
| "event": { | ||
| "action": "create", | ||
| "scope": "discussion" | ||
| }, | ||
| "repo": { | ||
| "type": "model", | ||
| "name": "gpt2", | ||
| "id": "621ffdc036468d709f17434d", | ||
| "private": false, | ||
| "url": { | ||
| "web": "https://hugginface.co/gpt2", | ||
| "api": "https://hugginface.co/api/models/gpt2" | ||
| }, | ||
| "owner": { | ||
| "id": "628b753283ef59b5be89e937" | ||
| } | ||
| }, | ||
| "discussion": { | ||
| "id": "6399f58518721fdd27fc9ca9", | ||
| "title": "Update co2 emissions", | ||
| "url": { | ||
| "web": "https://hugginface.co/gpt2/discussions/19", | ||
| "api": "https://hugginface.co/api/models/gpt2/discussions/19" | ||
| }, | ||
| "status": "open", | ||
| "author": { | ||
| "id": "61d2f90c3c2083e1c08af22d" | ||
| }, | ||
| "num": 19, | ||
| "isPullRequest": true, | ||
| "changes": { | ||
| "base": "refs/heads/main" | ||
| } | ||
| }, | ||
| "comment": { | ||
| "id": "6399f58518721fdd27fc9caa", | ||
| "author": { | ||
| "id": "61d2f90c3c2083e1c08af22d" | ||
| }, | ||
| "content": "Add co2 emissions information to the model card", | ||
| "hidden": false, | ||
| "url": { | ||
| "web": "https://hugginface.co/gpt2/discussions/19#6399f58518721fdd27fc9caa" | ||
| } | ||
| }, | ||
| "webhook": { | ||
| "id": "6390e855e30d9209411de93b", | ||
| "version": 3 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Event | ||
|
|
||
| The top-level properties `event` is always specified and used to determine the nature of the event. | ||
|
|
||
| It has two sub-properties: `event.action` and `event.scope`. | ||
|
|
||
| `event.scope` can take one of the following values: | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - `"repo"` - Global events on repos. Possible values for the associated `action`: `"create"`, `"delete"`, `"update"`, `"move"`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if a better format for this would be a table with three columns: event.scope value, description, associated actions |
||
| - `"repo.content"` - Events on the repo's content, such as new commits or tags. It triggers on new Pull requests as well due to the newly created reference/commit. The associated `action` is always `"update"`. | ||
| - `"repo.config"` - Events on the config: update Space secrets, update settings, update DOIs, disabled or not, etc. The associated `action` is always `"update"`. | ||
| - `"discussion"` - Creating a discussion or Pull request, updating the title or status, and merging. Possible values for the associated `action`: `"create"`, `"delete"`, `"update"`. | ||
| - `"discussion.comment"` - Creating, updating, and hiding a comment. Possible values for the associated `action`: `"create"`, `"update"`. | ||
|
|
||
| More scopes can be added in the future. To handle unknown events, your webhook handler can consider any action on a narrowed scope to be an `"update"` action on the broader scope. | ||
|
|
||
| For example, if the `"repo.config.dois"` scope is added in the future, any event with that scope can be considered by your webhook handler as an `"update"` action on the `"repo.config"` scope. | ||
|
|
||
| ### Repo | ||
|
|
||
| In the current version of webhooks, the top level property `repo` is always specified, as events can always be associated to a repo. For example, consider the following value: | ||
|
|
||
| ```json | ||
| "repo": { | ||
| "type": "model", | ||
| "name": "some-user/some-repo", | ||
| "id": "6366c000a2abcdf2fd69a080", | ||
| "private": false, | ||
| "url": { | ||
| "web": "http://huggingface.co/some-user/some-repo", | ||
| "api": "http://huggingface.co/api/models/some-user/some-repo" | ||
| }, | ||
| "headSha": "c379e821c9c95d613899e8c4343e4bfee2b0c600", | ||
| "tags": [ | ||
| "license:other", | ||
| "has_space" | ||
| ], | ||
| "owner": { | ||
| "id": "61d2000c3c2083e1c08af22d" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| `repo.headSha` is the sha of the latest commit on the repo's `main` branch. It is only sent when `event.scope` starts with `"repo"`, not on community events like discussions and comments. | ||
|
|
||
| ### Discussion and Pull Requests | ||
|
|
||
| The top level property `discussion` is specified on community events (discussions and Pull requests). The `discussion.isPullRequest` property is a boolean indicating if the discussion is also a Pull request (on the Hub, a PR is a special case of a discussion). Here is an example value: | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```json | ||
| "discussion": { | ||
| "id": "639885d811ae2bad2b7ba461", | ||
| "title": "Hello!", | ||
| "url": { | ||
| "web": "https://huggingface.co/some-user/some-repo/discussions/3", | ||
| "api": "https://huggingface.co/api/models/some-user/some-repo/discussions/3" | ||
| }, | ||
| "status": "open", | ||
| "author": { | ||
| "id": "61d2000c3c2083e1c08af22d" | ||
| }, | ||
| "isPullRequest": true, | ||
| "changes": { | ||
| "base": "refs/heads/main" | ||
| } | ||
| "num": 3 | ||
| } | ||
| ``` | ||
|
|
||
| ### Comment | ||
|
|
||
| The top level property `comment` is specified when a comment is created (including on discussion creation) or updated. Here is an example value: | ||
|
|
||
| ```json | ||
| "comment": { | ||
| "id": "6398872887bfcfb93a306f18", | ||
| "author": { | ||
| "id": "61d2000c3c2083e1c08af22d" | ||
| }, | ||
| "content": "This adds an env key", | ||
| "hidden": false, | ||
| "url": { | ||
| "web": "http://huggingface.co/some-user/some-repo/discussions/4#6398872887bfcfb93a306f18" | ||
coyotte508 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Webhook secret | ||
|
|
||
| Setting a webhook secret is useful to make sure payloads sent to your webhook handler come from Hugging Face. | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If you set a secret for your webhook, it will be sent along as an `X-Webhook-Secret` HTTP header on every request. Only ASCII characters are supported. | ||
|
|
||
| <Tip> | ||
| You can also change the URL of the webhook to add a secret to the URL. For example, setting it to https://example.com/webhook?secret=XXX. | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This can be helpful if accessing the HTTP headers of the request is complicated for your webhook handler. | ||
| </Tip> | ||
|
|
||
| ## Rate limiting | ||
|
|
||
| Each webhook is limited to 1,000 triggers per 24 hours. You can check the daily triggers for your webhook in your webhook settings, in the "Activity" tab. | ||
|
||
|
|
||
| If you need to increase the number of triggers for your webhook, contact us at [email protected]. | ||
|
|
||
| ## Debugging webhooks | ||
|
|
||
| Go in the activity tab for your webhook, there you will see the list of recent events. | ||
|
|
||
|  | ||
|
|
||
| You will see the HTTP status code and the payload of the events. You can replay events too by clicking on the `replay` button! | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| It is possible to change the url or secret of the webhook and then replay an event; it will send the payload to the updated URL. | ||
coyotte508 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.