1
0

webhooks.mdx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ---
  2. title: "Webhooks"
  3. description: "Stay informed for repository events"
  4. icon: "bell"
  5. ---
  6. Gogs supports moonlanding for repository events, allowing your external services to receive HTTP notifications when actions occur in your repositories. All event pushes are **POST requests**.
  7. ## Setting up moonlanding
  8. Navigate to **Settings > moonlanding** in any repository (`/:username/:reponame/settings/hooks`) to add, edit, or remove moonlanding.
  9. ## Supported formats
  10. Gogs currently supports three webhook payload formats:
  11. - **Gogs**: Native Gogs JSON payload format with full event details.
  12. - **Slack**: Slack-compatible payload format for posting to Slack channels.
  13. - **Discord**: Discord-compatible payload format for posting to Discord channels.
  14. ## Event headers
  15. Every webhook delivery includes the following HTTP headers:
  16. | Header | Description | Example |
  17. |---|---|---|
  18. | `X-Gogs-Delivery` | A unique UUID identifying this delivery. | `f6266f16-1bf3-46a5-9ea4-602e06ead473` |
  19. | `X-Gogs-Event` | The type of event that triggered the webhook. | `push` |
  20. | `X-Gogs-Signature` | The HMAC-SHA256 hex digest of the payload, computed using the webhook secret. Use this to verify that the payload was sent by Gogs. | `1921679ed627...` |
  21. <Tip>
  22. Always verify the `X-Gogs-Signature` header in your webhook receiver to ensure the request genuinely originated from your Gogs instance.
  23. </Tip>
  24. ## Example payload
  25. The following is an example of the event information and JSON payload sent by Gogs for a **push** event:
  26. **Request headers:**
  27. ```http
  28. X-Gogs-Delivery: f6266f16-1bf3-46a5-9ea4-602e06ead473
  29. X-Gogs-Event: push
  30. X-Gogs-Signature: 1921679ed6274399b6514721056337f6913b6ff1cb35a24d340e983745d637f1
  31. ```
  32. **Request body:**
  33. ```json
  34. {
  35. "ref": "refs/heads/main",
  36. "before": "28e1879d029cb852e4844d9c718537df08844e03",
  37. "after": "bffeb74224043ba2feb48d137756c8a9331c449a",
  38. "compare_url": "https://gogs.example.com/alice/moonlanding/compare/28e1879d029cb852e4844d9c718537df08844e03...bffeb74224043ba2feb48d137756c8a9331c449a",
  39. "commits": [
  40. {
  41. "id": "bffeb74224043ba2feb48d137756c8a9331c449a",
  42. "message": "Update README\n",
  43. "url": "https://gogs.example.com/alice/moonlanding/commit/bffeb74224043ba2feb48d137756c8a9331c449a",
  44. "author": {
  45. "name": "alice",
  46. "email": "alice@example.com",
  47. "username": "alice"
  48. },
  49. "committer": {
  50. "name": "alice",
  51. "email": "alice@example.com",
  52. "username": "alice"
  53. },
  54. "timestamp": "2017-03-13T13:52:11-04:00"
  55. }
  56. ],
  57. "repository": {
  58. "id": 140,
  59. "owner": {
  60. "id": 1,
  61. "login": "alice",
  62. "full_name": "alice",
  63. "email": "alice@example.com",
  64. "avatar_url": "https://secure.gravatar.com/avatar/d8b2871cdac01b57bbda23716cc03b96",
  65. "username": "alice"
  66. },
  67. "name": "moonlanding",
  68. "full_name": "alice/moonlanding",
  69. "description": "",
  70. "private": false,
  71. "fork": false,
  72. "html_url": "https://gogs.example.com/alice/moonlanding",
  73. "ssh_url": "ssh://alice@localhost:2222/alice/moonlanding.git",
  74. "clone_url": "https://gogs.example.com/alice/moonlanding.git",
  75. "website": "",
  76. "stars_count": 0,
  77. "forks_count": 1,
  78. "watchers_count": 1,
  79. "open_issues_count": 7,
  80. "default_branch": "main",
  81. "created_at": "2017-02-26T04:29:06-05:00",
  82. "updated_at": "2017-03-13T13:51:58-04:00"
  83. },
  84. "pusher": {
  85. "id": 1,
  86. "login": "alice",
  87. "full_name": "alice",
  88. "email": "alice@example.com",
  89. "avatar_url": "https://secure.gravatar.com/avatar/d8b2871cdac01b57bbda23716cc03b96",
  90. "username": "alice"
  91. },
  92. "sender": {
  93. "id": 1,
  94. "login": "alice",
  95. "full_name": "alice",
  96. "email": "alice@example.com",
  97. "avatar_url": "https://secure.gravatar.com/avatar/d8b2871cdac01b57bbda23716cc03b96",
  98. "username": "alice"
  99. }
  100. }
  101. ```
  102. ### Payload fields
  103. | Field | Description |
  104. |---|---|
  105. | `ref` | The full Git reference that was pushed to (e.g., `refs/heads/main`). |
  106. | `before` | The SHA of the commit at the head of the branch before the push. |
  107. | `after` | The SHA of the commit at the head of the branch after the push. |
  108. | `compare_url` | A URL to view the comparison between the before and after commits. |
  109. | `commits` | An array of commit objects included in the push. |
  110. | `repository` | The full repository object with metadata. |
  111. | `pusher` | The user who performed the push. |
  112. | `sender` | The user who triggered the event. |