summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-01-08 10:56:39 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-01-08 10:56:39 +0000
commit08213ed4f5d35b582f0345d6a825737ced98fd05 (patch)
treef553aced5c87acce551781a1023d04a04d5a054c
parent26a54ec34d9bb11656fb2a7a36d1a666218fc61d (diff)
parent8386edafd13c8cca1c6ed45abbbc554351300e9d (diff)
downloadgitlab-ce-08213ed4f5d35b582f0345d6a825737ced98fd05.tar.gz
Merge branch 'accept-2xx-status-codes-for-webhooks' into 'master'
Accept 2xx status codes for successful Web hook triggers Closes https://github.com/gitlabhq/gitlabhq/issues/9956 See merge request !2332
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/hooks/web_hook.rb2
-rw-r--r--spec/models/hooks/web_hook_spec.rb12
3 files changed, 14 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index d1500ab7d3a..b3b8b1c5ba4 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
Please view this file on the master branch, on stable branches it's out of date.
v 8.4.0 (unreleased)
+ - Accept 2xx status codes for successful Web hook triggers (Stan Hu)
- Fix missing date of month in network graph when commits span a month (Stan Hu)
- Expire view caches when application settings change (e.g. Gravatar disabled) (Stan Hu)
- Don't notify users twice if they are both project watchers and subscribers (Stan Hu)
diff --git a/app/models/hooks/web_hook.rb b/app/models/hooks/web_hook.rb
index 7164c0e1e90..d0aadfc330a 100644
--- a/app/models/hooks/web_hook.rb
+++ b/app/models/hooks/web_hook.rb
@@ -61,7 +61,7 @@ class WebHook < ActiveRecord::Base
basic_auth: auth)
end
- [response.code == 200, ActionView::Base.full_sanitizer.sanitize(response.to_s)]
+ [(response.code >= 200 && response.code < 300), ActionView::Base.full_sanitizer.sanitize(response.to_s)]
rescue SocketError, OpenSSL::SSL::SSLError, Errno::ECONNRESET, Errno::ECONNREFUSED, Net::OpenTimeout => e
logger.error("WebHook Error => #{e}")
[false, e.to_s]
diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb
index 2d90b0793cc..7070aa4ac62 100644
--- a/spec/models/hooks/web_hook_spec.rb
+++ b/spec/models/hooks/web_hook_spec.rb
@@ -77,5 +77,17 @@ describe ProjectHook, models: true do
expect(@project_hook.execute(@data, 'push_hooks')).to eq([false, 'SSL error'])
end
+
+ it "handles 200 status code" do
+ WebMock.stub_request(:post, @project_hook.url).to_return(status: 200, body: "Success")
+
+ expect(@project_hook.execute(@data, 'push_hooks')).to eq([true, 'Success'])
+ end
+
+ it "handles 2xx status codes" do
+ WebMock.stub_request(:post, @project_hook.url).to_return(status: 201, body: "Success")
+
+ expect(@project_hook.execute(@data, 'push_hooks')).to eq([true, 'Success'])
+ end
end
end