summaryrefslogtreecommitdiff
path: root/lib/gitlab_net.rb
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-04-28 17:10:42 -0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-05-11 12:21:31 -0300
commitee259653e7a00359740ca36cef606f9c3cc1a7cb (patch)
tree6f53403454defd386c4455a6a9ffcf052d4c6695 /lib/gitlab_net.rb
parent1cf14770f3bf5c3255f4c3a8f69ccfab74317fcd (diff)
downloadgitlab-shell-ee259653e7a00359740ca36cef606f9c3cc1a7cb.tar.gz
Handle GL_REPOSITORY env variable and use it in api calls
Diffstat (limited to 'lib/gitlab_net.rb')
-rw-r--r--lib/gitlab_net.rb17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index 438c626..1e60e24 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -15,17 +15,19 @@ class GitlabNet
CHECK_TIMEOUT = 5
READ_TIMEOUT = 300
- def check_access(cmd, repo, actor, changes, protocol, env: {})
+ def check_access(cmd, gl_repository, repo, actor, changes, protocol, env: {})
changes = changes.join("\n") unless changes.kind_of?(String)
params = {
action: cmd,
changes: changes,
+ gl_repository: gl_repository,
project: sanitize_path(repo),
protocol: protocol,
env: env
}
+
if actor =~ /\Akey\-\d+\Z/
params.merge!(key_id: actor.gsub("key-", ""))
elsif actor =~ /\Auser\-\d+\Z/
@@ -38,7 +40,7 @@ class GitlabNet
if resp.code == '200'
GitAccessStatus.create_from_json(resp.body)
else
- GitAccessStatus.new(false, 'API is not accessible', nil)
+ GitAccessStatus.new(false, 'API is not accessible', nil, nil)
end
end
@@ -66,10 +68,12 @@ class GitlabNet
JSON.parse(resp.body) rescue {}
end
- def merge_request_urls(repo_path, changes)
+ def merge_request_urls(gl_repository, repo_path, changes)
changes = changes.join("\n") unless changes.kind_of?(String)
changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '')
- resp = get("#{host_v3}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}")
+ url = "#{host_v3}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}"
+ url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository
+ resp = get(url)
JSON.parse(resp.body) rescue []
end
@@ -93,8 +97,9 @@ class GitlabNet
{}
end
- def notify_post_receive(repo_path)
- resp = post("#{host}/notify_post_receive", repo_path: repo_path)
+ def notify_post_receive(gl_repository, repo_path)
+ params = { gl_repository: gl_repository, project: repo_path }
+ resp = post("#{host}/notify_post_receive", params)
resp.code == '200'
rescue