Commit 99a65d67 authored by Ash McKenzie's avatar Ash McKenzie

Use HTTP status constants in GitLabNet

parent 9853fe04
...@@ -55,16 +55,10 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -55,16 +55,10 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end end
def lfs_authenticate(key, repo) def lfs_authenticate(key, repo)
params = { params = { project: sanitize_path(repo), key_id: key.gsub('key-', '') }
project: sanitize_path(repo),
key_id: key.gsub('key-', '')
}
resp = post("#{internal_api_endpoint}/lfs_authenticate", params) resp = post("#{internal_api_endpoint}/lfs_authenticate", params)
if resp.code == '200' GitlabLfsAuthentication.build_from_json(resp.body) if resp.code == HTTP_SUCCESS
GitlabLfsAuthentication.build_from_json(resp.body)
end
end end
def broadcast_message def broadcast_message
...@@ -79,11 +73,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -79,11 +73,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository
resp = get(url) resp = get(url)
if resp.code == '200' resp.code == HTTP_SUCCESS ? JSON.parse(resp.body) : []
JSON.parse(resp.body)
else
[]
end
rescue rescue
[] []
end end
...@@ -94,7 +84,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -94,7 +84,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def authorized_key(key) def authorized_key(key)
resp = get("#{internal_api_endpoint}/authorized_keys?key=#{URI.escape(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 rescue
nil nil
end end
...@@ -102,8 +92,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -102,8 +92,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def two_factor_recovery_codes(key) def two_factor_recovery_codes(key)
key_id = key.gsub('key-', '') key_id = key.gsub('key-', '')
resp = post("#{internal_api_endpoint}/two_factor_recovery_codes", key_id: key_id) resp = post("#{internal_api_endpoint}/two_factor_recovery_codes", key_id: key_id)
JSON.parse(resp.body) if resp.code == HTTP_SUCCESS
JSON.parse(resp.body) if resp.code == '200'
rescue rescue
{} {}
end end
...@@ -112,7 +101,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -112,7 +101,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
params = { gl_repository: gl_repository, project: repo_path } params = { gl_repository: gl_repository, project: repo_path }
resp = post("#{internal_api_endpoint}/notify_post_receive", params) resp = post("#{internal_api_endpoint}/notify_post_receive", params)
resp.code == '200' resp.code == HTTP_SUCCESS
rescue rescue
false false
end end
...@@ -124,21 +113,19 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -124,21 +113,19 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
changes: changes changes: changes
} }
resp = post("#{internal_api_endpoint}/post_receive", params) 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 == HTTP_SUCCESS
JSON.parse(resp.body) if resp.code == '200'
end end
def pre_receive(gl_repository) def pre_receive(gl_repository)
resp = post("#{internal_api_endpoint}/pre_receive", gl_repository: 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 == HTTP_SUCCESS
JSON.parse(resp.body) if resp.code == '200'
end end
protected private
def sanitize_path(repo) def sanitize_path(repo)
repo.delete("'") repo.delete("'")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment