diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-09-11 13:38:37 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-09-11 13:38:37 +0200 |
commit | 2ed2ef921026cbde5dddda89177bfa50e2993ecd (patch) | |
tree | a320046ab80fb624d585a6d903a0a1d61dbd4dd3 /app/models | |
parent | 187face620cfa0d5617a1c49e28dfbb20134fe41 (diff) | |
download | gitlab-ce-2ed2ef921026cbde5dddda89177bfa50e2993ecd.tar.gz |
Remove network from CI
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/network.rb | 122 | ||||
-rw-r--r-- | app/models/ci/project.rb | 6 |
2 files changed, 4 insertions, 124 deletions
diff --git a/app/models/ci/network.rb b/app/models/ci/network.rb deleted file mode 100644 index 1a54213f4f1..00000000000 --- a/app/models/ci/network.rb +++ /dev/null @@ -1,122 +0,0 @@ -module Ci - class Network - class UnauthorizedError < StandardError; end - - include HTTParty - - API_PREFIX = '/api/v3/' - - def authenticate(api_opts) - opts = { - query: api_opts - } - - endpoint = File.join(url, API_PREFIX, 'user') - response = self.class.get(endpoint, default_opts.merge(opts)) - - build_response(response) - end - - def projects(api_opts, scope = :owned) - # Dont load archived projects - api_opts.merge!(archived: false) - - opts = { - query: api_opts - } - - query = if scope == :owned - 'projects/owned.json' - else - 'projects.json' - end - - endpoint = File.join(url, API_PREFIX, query) - response = self.class.get(endpoint, default_opts.merge(opts)) - - build_response(response) - end - - def project(api_opts, project_id) - opts = { - query: api_opts - } - - query = "projects/#{project_id}.json" - - endpoint = File.join(url, API_PREFIX, query) - response = self.class.get(endpoint, default_opts.merge(opts)) - - build_response(response) - end - - def project_hooks(api_opts, project_id) - opts = { - query: api_opts - } - - query = "projects/#{project_id}/hooks.json" - - endpoint = File.join(url, API_PREFIX, query) - response = self.class.get(endpoint, default_opts.merge(opts)) - - build_response(response) - end - - def enable_ci(project_id, data, api_opts) - opts = { - body: data.to_json, - query: api_opts - } - - query = "projects/#{project_id}/services/gitlab-ci.json" - endpoint = File.join(url, API_PREFIX, query) - response = self.class.put(endpoint, default_opts.merge(opts)) - - case response.code - when 200 - true - when 401 - raise UnauthorizedError - else - nil - end - end - - def disable_ci(project_id, api_opts) - opts = { - query: api_opts - } - - query = "projects/#{project_id}/services/gitlab-ci.json" - - endpoint = File.join(url, API_PREFIX, query) - response = self.class.delete(endpoint, default_opts.merge(opts)) - - build_response(response) - end - - private - - def url - Gitlab.config.gitlab.url - end - - def default_opts - { - headers: { "Content-Type" => "application/json" }, - } - end - - def build_response(response) - case response.code - when 200 - response.parsed_response - when 401 - raise UnauthorizedError - else - nil - end - end - end -end diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb index c9e5707f218..2cf1783616f 100644 --- a/app/models/ci/project.rb +++ b/app/models/ci/project.rb @@ -31,7 +31,7 @@ module Ci include Ci::ProjectStatus - belongs_to :gl_project, class_name: 'Project', foreign_key: :gitlab_id + belongs_to :gl_project, class_name: '::Project', foreign_key: :gitlab_id has_many :commits, ->() { order(:committed_at) }, dependent: :destroy, class_name: 'Ci::Commit' has_many :builds, through: :commits, dependent: :destroy, class_name: 'Ci::Build' @@ -92,11 +92,13 @@ module Ci project end + # TODO: remove def from_gitlab(user, scope = :owned, options) opts = user.authenticate_options opts.merge! options - projects = Ci::Network.new.projects(opts.compact, scope) + raise 'Implement me of fix' + #projects = Ci::Network.new.projects(opts.compact, scope) if projects projects.map { |pr| OpenStruct.new(pr) } |