Commit 9912770c6f0177f496112543064355f79badf94b

Authored by gitlab system
1 parent e8261313

make hooks respect http basic authentication

Showing 1 changed file with 10 additions and 1 deletions   Show diff stats
app/models/web_hook.rb
... ... @@ -11,7 +11,16 @@ class WebHook < ActiveRecord::Base
11 11 message: "should be a valid url" }
12 12  
13 13 def execute(data)
14   - WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" })
  14 + parsed_url = URI.parse(url)
  15 + if parsed_url.userinfo.blank?
  16 + WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" })
  17 + else
  18 + post_url = url.gsub(parsed_url.userinfo+"@", "")
  19 + WebHook.post(post_url,
  20 + body: data.to_json,
  21 + headers: { "Content-Type" => "application/json" },
  22 + basic_auth: {username: parsed_url.user, password: parsed_url.password})
  23 + end
15 24 end
16 25  
17 26 end
... ...