diff options
author | Robert Speicher <robert@gitlab.com> | 2017-02-15 22:42:19 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-02-15 22:42:19 +0000 |
commit | a6e5b9a17821dab311e71fa83d2a973cb5361edb (patch) | |
tree | 04e97e944380fbe114d410f084c7fa4cc05e89bb /lib/gitlab_net.rb | |
parent | f61bdfe39c6b0618144f369d5cf4df1099be9948 (diff) | |
parent | 09e4814483863b3cb570a98746c684a2709eece8 (diff) | |
download | gitlab-shell-a6e5b9a17821dab311e71fa83d2a973cb5361edb.tar.gz |
Merge branch 'gitaly-post-receive-2' into 'master'
Add gitaly notification on post-receive hook
See merge request !119
Diffstat (limited to 'lib/gitlab_net.rb')
-rw-r--r-- | lib/gitlab_net.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb index e06557c..438c626 100644 --- a/lib/gitlab_net.rb +++ b/lib/gitlab_net.rb @@ -32,7 +32,7 @@ class GitlabNet params.merge!(user_id: actor.gsub("user-", "")) end - url = "#{host}/allowed" + url = "#{host_v3}/allowed" resp = post(url, params) if resp.code == '200' @@ -44,7 +44,7 @@ class GitlabNet def discover(key) key_id = key.gsub("key-", "") - resp = get("#{host}/discover?key_id=#{key_id}") + resp = get("#{host_v3}/discover?key_id=#{key_id}") JSON.parse(resp.body) rescue nil end @@ -54,7 +54,7 @@ class GitlabNet key_id: key.gsub('key-', '') } - resp = post("#{host}/lfs_authenticate", params) + resp = post("#{host_v3}/lfs_authenticate", params) if resp.code == '200' GitlabLfsAuthentication.build_from_json(resp.body) @@ -62,23 +62,23 @@ class GitlabNet end def broadcast_message - resp = get("#{host}/broadcast_message") + resp = get("#{host_v3}/broadcast_message") JSON.parse(resp.body) rescue {} end def merge_request_urls(repo_path, changes) changes = changes.join("\n") unless changes.kind_of?(String) changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '') - resp = get("#{host}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}") + resp = get("#{host_v3}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}") JSON.parse(resp.body) rescue [] end def check - get("#{host}/check", read_timeout: CHECK_TIMEOUT) + get("#{host_v3}/check", read_timeout: CHECK_TIMEOUT) end def authorized_key(key) - resp = get("#{host}/authorized_keys?key=#{URI.escape(key, '+/=')}") + resp = get("#{host_v3}/authorized_keys?key=#{URI.escape(key, '+/=')}") JSON.parse(resp.body) if resp.code == "200" rescue nil @@ -86,13 +86,21 @@ class GitlabNet def two_factor_recovery_codes(key) key_id = key.gsub('key-', '') - resp = post("#{host}/two_factor_recovery_codes", key_id: key_id) + resp = post("#{host_v3}/two_factor_recovery_codes", key_id: key_id) JSON.parse(resp.body) if resp.code == '200' rescue {} end + def notify_post_receive(repo_path) + resp = post("#{host}/notify_post_receive", repo_path: repo_path) + + resp.code == '200' + rescue + false + end + def redis_client redis_config = config.redis database = redis_config['database'] || 0 @@ -127,10 +135,14 @@ class GitlabNet @config ||= GitlabConfig.new end - def host + def host_v3 "#{config.gitlab_url}/api/v3/internal" end + def host + "#{config.gitlab_url}/api/v4/internal" + end + def http_client_for(uri, options={}) if uri.is_a?(URI::HTTPUNIX) http = Net::HTTPUNIX.new(uri.hostname) |