summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2018-07-26 18:55:22 +1000
committerAsh McKenzie <amckenzie@gitlab.com>2018-08-01 00:24:16 +1000
commit99a65d67df3b77a0ae3bc6abc758708fbcc4de2a (patch)
tree6281c929943c8d2ca16d81211bba797407ef3a5e /lib
parent9853fe040288a8a4703cb5f53c000bafd79a2bd2 (diff)
downloadgitlab-shell-99a65d67df3b77a0ae3bc6abc758708fbcc4de2a.tar.gz
Use HTTP status constants in GitLabNet
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab_net.rb35
1 files changed, 11 insertions, 24 deletions
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index 4124440..2f704df 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -55,16 +55,10 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end
def lfs_authenticate(key, repo)
- params = {
- project: sanitize_path(repo),
- key_id: key.gsub('key-', '')
- }
-
+ params = { project: sanitize_path(repo), key_id: key.gsub('key-', '') }
resp = post("#{internal_api_endpoint}/lfs_authenticate", params)
- if resp.code == '200'
- GitlabLfsAuthentication.build_from_json(resp.body)
- end
+ GitlabLfsAuthentication.build_from_json(resp.body) if resp.code == HTTP_SUCCESS
end
def broadcast_message
@@ -79,11 +73,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository
resp = get(url)
- if resp.code == '200'
- JSON.parse(resp.body)
- else
- []
- end
+ resp.code == HTTP_SUCCESS ? JSON.parse(resp.body) : []
rescue
[]
end
@@ -94,7 +84,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def authorized_key(key)
resp = get("#{internal_api_endpoint}/authorized_keys?key=#{URI.escape(key, '+/=')}")
- JSON.parse(resp.body) if resp.code == "200"
+ JSON.parse(resp.body) if resp.code == HTTP_SUCCESS
rescue
nil
end
@@ -102,8 +92,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def two_factor_recovery_codes(key)
key_id = key.gsub('key-', '')
resp = post("#{internal_api_endpoint}/two_factor_recovery_codes", key_id: key_id)
-
- JSON.parse(resp.body) if resp.code == '200'
+ JSON.parse(resp.body) if resp.code == HTTP_SUCCESS
rescue
{}
end
@@ -112,7 +101,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
params = { gl_repository: gl_repository, project: repo_path }
resp = post("#{internal_api_endpoint}/notify_post_receive", params)
- resp.code == '200'
+ resp.code == HTTP_SUCCESS
rescue
false
end
@@ -124,21 +113,19 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
changes: changes
}
resp = post("#{internal_api_endpoint}/post_receive", params)
+ raise NotFound if resp.code == HTTP_NOT_FOUND
- raise NotFound if resp.code == '404'
-
- JSON.parse(resp.body) if resp.code == '200'
+ JSON.parse(resp.body) if resp.code == HTTP_SUCCESS
end
def pre_receive(gl_repository)
resp = post("#{internal_api_endpoint}/pre_receive", gl_repository: gl_repository)
+ raise NotFound if resp.code == HTTP_NOT_FOUND
- raise NotFound if resp.code == '404'
-
- JSON.parse(resp.body) if resp.code == '200'
+ JSON.parse(resp.body) if resp.code == HTTP_SUCCESS
end
- protected
+ private
def sanitize_path(repo)
repo.delete("'")