Webhook
Introduction to Webhook
Developers can configure URLs of third-party systems on the webhook page and subscribe to events such as branch push and tag push of CodeHub based on project requirements. When a subscription event occurs, you can use a webhook to send a POST request to the URL of a third-party system to trigger operations related to your system (third-party system), such as popping up a notification window, building or updating images, or performing deployment.
If you want to email repository change notifications, you can configure Notifications in General Settings.
Setting Webhooks
To configure the webhook, choose
on the repository details page.The settings take effect only for the repository configured.
Only repository administrators and owners can view this tab page and configure the function.
- A maximum of 20 webhooks can be created for a repository.
- You can configure a token when setting up a webhook. The token will be associated with the webhook URL and sent to you in the X-Devcloud-Token header of a POST request.
Events for Subscription
- You can select which events to listen to. CodeHub will send you POST requests only when subscribed events occur. You can also change the subscribed events on the Webhooks page.
- The following events can be selected:
- Push events
- Tag push events
- Merge request events
- Comment events
- Example: If you have subscribed to merge request events, CodeHub will send a POST request to the configured webhook URL when a merge request is created, closed, or reopened in the repository. You can then perform actions based on the received information.
POST Requests
A POST request sent by CodeHub includes the following information:headers: Content-Length: 2294 Connection: keep-alive Host: your.host.com X-Devcloud-Event: Push Hook Content-Type: application/json X-Devcloud-Token: xxxxxxx (if configured) body: (event details) { "object_kind": "push", "event_name": "push", // Event type: push event in this example. "before": "0101010101010101010101010101010101010101", // before and after fields record the commit IDs before and after the action respectively. "after": "0123456789012345678901234567890123456789", "ref": "refs/heads/master", // Triggered branch "checkout_sha": "0123456789012345678901234567890123456789", // Version that is checked out when an event is triggered. "message": "", "user_id": 1234, // Operator information "user_name": "example_user", "user_username": "example_user", "user_email": "example@huawei.com", "user_avatar": null, "user_id": 1234, // Project information of the triggered event "project": { "id": 123456, "name": "ExampleRepository", "description": "This is an example repository", "web_url": "https://codehub.devcloud.huaweicloud.com/ExampleNamespace/ExampleRepository", "avatar_url": null, "git_ssh_url": "git@codehub.devcloud.huaweicloud.com:ExampleNamespace/ExampleRepository.git", "git_http_url": "https://codehub.devcloud.huaweicloud.com/ExampleNamespace/ExampleRepository.git", "namespace": "ExampleNamespace", "visibility_level": 0, "path_with_namespace": "ExampleNamespace/ExampleRepository", "default_branch": "master", "ci_config_path": null, "homepage": "https://codehub.devcloud.huaweicloud.com/ExampleNamespace/ExampleRepository", "url": "git@codehub.devcloud.huaweicloud.com:ExampleNamespace/ExampleRepository.git", "ssh_url": "git@codehub.devcloud.huaweicloud.com:ExampleNamespace/ExampleRepository.git", "http_url": "https://codehub.devcloud.huaweicloud.com/ExampleNamespace/ExampleRepository.git" }, "commits": { // Commit information of the triggered event "id": "0123456789012345678901234567890123456789", "message": "This is an example message", "timestamp": "2019-05-30T08:50:37Z", "url": "https://codehub.devcloud.huaweicloud.com/ExampleNamespace/ExampleRepository/commit/0123456789012345678901234567890123456789", "author": { "name": "example_user", "email": "example@huawei.com" }"added": [ "src/main/java/HelloWorld.java" ], "modified": [], "removed": [] }, "total_commits_count": 1, "repository": { // Repository information "name": "ExampleRepository", "url": "git@codehub.devcloud.huaweicloud.com:ExampleNamespace/ExampleRepository.git", "description": "This is an example repository", "homepage": "https://codehub.devcloud.huaweicloud.com/ExampleNamespace/ExampleRepository", "git_http_url": "https://codehub.devcloud.huaweicloud.com/ExampleNamespace/ExampleRepository.git", "git_ssh_url": "git@codehub.devcloud.huaweicloud.com:ExampleNamespace/ExampleRepository.git", "visibility_level": 0 } }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot