diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-09-16 12:43:16 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-09-18 18:02:11 +0200 |
commit | a0c1a12dee276f5d587514d24432e7647e07aeec (patch) | |
tree | 8c5797f2fff43c72361343dbcd70d1cd13067a88 /app | |
parent | bdfe6b9603a7a6947644929c4ea966018f98c840 (diff) | |
download | gitlab-ce-a0c1a12dee276f5d587514d24432e7647e07aeec.tar.gz |
remove API calls from CE to CIci_closer_integration
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/ci/projects_controller.rb | 12 | ||||
-rw-r--r-- | app/models/ci/project.rb | 15 | ||||
-rw-r--r-- | app/models/project_services/gitlab_ci_service.rb | 47 | ||||
-rw-r--r-- | app/services/ci/create_project_service.rb | 9 | ||||
-rw-r--r-- | app/services/projects/fork_service.rb | 2 | ||||
-rw-r--r-- | app/workers/fork_registration_worker.rb | 12 |
6 files changed, 18 insertions, 79 deletions
diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index b1f1c087b9e..40b61edb0a9 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -55,7 +55,7 @@ module Ci return redirect_to ci_root_path, alert: 'You have to have at least master role to enable CI for this project' end - @project = Ci::CreateProjectService.new.execute(current_user, project_data, ci_project_url(":project_id")) + @project = Ci::CreateProjectService.new.execute(current_user, project_data) if @project.persisted? redirect_to ci_project_path(@project, show_guide: true), notice: 'Project was successfully created.' @@ -86,16 +86,6 @@ module Ci redirect_to ci_projects_url end - def build - @commit = Ci::CreateCommitService.new.execute(@project, params.dup) - - if @commit && @commit.valid? - head 201 - else - head 400 - end - end - # Project status badge # Image with build status for sha or ref def badge diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb index ae901d4ccd0..37fbcc287bb 100644 --- a/app/models/ci/project.rb +++ b/app/models/ci/project.rb @@ -92,21 +92,6 @@ module Ci project end - # TODO: remove - def from_gitlab(user, scope = :owned, options) - opts = user.authenticate_options - opts.merge! options - - raise 'Implement me of fix' - #projects = Ci::Network.new.projects(opts.compact, scope) - - if projects - projects.map { |pr| OpenStruct.new(pr) } - else - [] - end - end - def already_added?(project) where(gitlab_id: project.id).any? end diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb index 1bba6326949..820dd3f567c 100644 --- a/app/models/project_services/gitlab_ci_service.rb +++ b/app/models/project_services/gitlab_ci_service.rb @@ -19,22 +19,12 @@ # class GitlabCiService < CiService - API_PREFIX = "api/v1" - - prop_accessor :project_url, :token, :enable_ssl_verification - validates :project_url, - presence: true, - format: { with: /\A#{URI.regexp(%w(http https))}\z/, message: "should be a valid url" }, if: :activated? - validates :token, - presence: true, - format: { with: /\A([A-Za-z0-9]+)\z/ }, if: :activated? + prop_accessor :token after_save :compose_service_hook, if: :activated? def compose_service_hook hook = service_hook || build_service_hook - hook.url = [project_url, "/build", "?token=#{token}"].join("") - hook.enable_ssl_verification = enable_ssl_verification hook.save end @@ -55,7 +45,8 @@ class GitlabCiService < CiService end end - service_hook.execute(data) + ci_project = Ci::Project.find_by(gitlab_id: project.id) + Ci::CreateCommitService.new.execute(ci_project, data) end def get_ci_commit(sha, ref) @@ -68,24 +59,22 @@ class GitlabCiService < CiService :error end - def fork_registration(new_project, private_token) - params = { + def fork_registration(new_project, current_user) + params = OpenStruct.new({ id: new_project.id, name_with_namespace: new_project.name_with_namespace, path_with_namespace: new_project.path_with_namespace, web_url: new_project.web_url, default_branch: new_project.default_branch, ssh_url_to_repo: new_project.ssh_url_to_repo - } - - HTTParty.post( - fork_registration_path, - body: { - project_id: project.id, - project_token: token, - private_token: private_token, - data: params }, - verify: false + }) + + ci_project = Ci::Project.find_by!(gitlab_id: project.id) + + Ci::CreateProjectService.new.execute( + current_user, + params, + ci_project ) end @@ -112,11 +101,7 @@ class GitlabCiService < CiService end def fields - [ - { type: 'text', name: 'token', placeholder: 'GitLab CI project specific token' }, - { type: 'text', name: 'project_url', placeholder: 'http://ci.gitlabhq.com/projects/3' }, - { type: 'checkbox', name: 'enable_ssl_verification', title: "Enable SSL verification" } - ] + [] end private @@ -125,10 +110,6 @@ class GitlabCiService < CiService repository.blob_at(sha, '.gitlab-ci.yml') end - def fork_registration_path - project_url.sub(/projects\/\d*/, "#{API_PREFIX}/forks") - end - def repository project.repository end diff --git a/app/services/ci/create_project_service.rb b/app/services/ci/create_project_service.rb index 0419612d521..839d3f6b444 100644 --- a/app/services/ci/create_project_service.rb +++ b/app/services/ci/create_project_service.rb @@ -2,20 +2,15 @@ module Ci class CreateProjectService include Gitlab::Application.routes.url_helpers - def execute(current_user, params, project_route, forked_project = nil) + def execute(current_user, params, forked_project = nil) @project = Ci::Project.parse(params) Ci::Project.transaction do @project.save! - data = { - token: @project.token, - project_url: project_route.gsub(":project_id", @project.id.to_s), - } - gl_project = ::Project.find(@project.gitlab_id) gl_project.build_missing_services - gl_project.gitlab_ci_service.update_attributes(data.merge(active: true)) + gl_project.gitlab_ci_service.update_attributes(active: true, token: @project.token) end if forked_project diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb index 50f208b11d1..2e995d6fd51 100644 --- a/app/services/projects/fork_service.rb +++ b/app/services/projects/fork_service.rb @@ -18,7 +18,7 @@ module Projects if new_project.persisted? if @project.gitlab_ci? - ForkRegistrationWorker.perform_async(@project.id, new_project.id, @current_user.private_token) + @project.gitlab_ci_service.fork_registration(new_project, @current_user) end end diff --git a/app/workers/fork_registration_worker.rb b/app/workers/fork_registration_worker.rb deleted file mode 100644 index fffa8b3a659..00000000000 --- a/app/workers/fork_registration_worker.rb +++ /dev/null @@ -1,12 +0,0 @@ -class ForkRegistrationWorker - include Sidekiq::Worker - - sidekiq_options queue: :default - - def perform(from_project_id, to_project_id, private_token) - from_project = Project.find(from_project_id) - to_project = Project.find(to_project_id) - - from_project.gitlab_ci_service.fork_registration(to_project, private_token) - end -end |