Commit 0e8d2557d83b14f9f550aa4d122351d2ce591172
Exists in
spb-stable
and in
2 other branches
Merge branch 'endpoint_example' into 'master'
Add an example webhook receiver
Showing
1 changed file
with
31 additions
and
0 deletions
Show diff stats
doc/web_hooks/web_hooks.md
| ... | ... | @@ -112,3 +112,34 @@ Triggered when a new merge request is created or an existing merge request was u |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | ``` |
| 115 | + | |
| 116 | +#### Example webhook receiver | |
| 117 | + | |
| 118 | +If you want to see GitLab's webhooks in action for testing purposes you can use | |
| 119 | +a simple echo script running in a console session. | |
| 120 | + | |
| 121 | +Save the following file as `print_http_body.rb`. | |
| 122 | + | |
| 123 | +```ruby | |
| 124 | +require 'webrick' | |
| 125 | + | |
| 126 | +server = WEBrick::HTTPServer.new(Port: ARGV.first) | |
| 127 | +server.mount_proc '/' do |req, res| | |
| 128 | + puts req.body | |
| 129 | +end | |
| 130 | + | |
| 131 | +trap 'INT' do server.shutdown end | |
| 132 | +server.start | |
| 133 | +``` | |
| 134 | + | |
| 135 | +Pick an unused port (e.g. 8000) and start the script: `ruby print_http_body.rb | |
| 136 | +8000`. Then add your server as a webhook receiver in GitLab as | |
| 137 | +`http://my.host:8000/`. | |
| 138 | + | |
| 139 | +When you press 'Test Hook' in GitLab, you should see something like this in the console. | |
| 140 | + | |
| 141 | +``` | |
| 142 | +{"before":"077a85dd266e6f3573ef7e9ef8ce3343ad659c4e","after":"95cd4a99e93bc4bbabacfa2cd10e6725b1403c60",<SNIP>} | |
| 143 | +localhost - - [14/May/2014:07:45:26 EDT] "POST / HTTP/1.1" 200 0 | |
| 144 | +- -> / | |
| 145 | +``` | ... | ... |