diff options
Diffstat (limited to 'app/models/project_services/gitlab_ci_service.rb')
-rw-r--r-- | app/models/project_services/gitlab_ci_service.rb | 86 |
1 files changed, 22 insertions, 64 deletions
diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb index acbbc9935b6..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,71 +45,47 @@ class GitlabCiService < CiService end end - service_hook.execute(data) - end - - def commit_status_path(sha, ref) - URI::encode(project_url + "/refs/#{ref}/commits/#{sha}/status.json?token=#{token}") + ci_project = Ci::Project.find_by(gitlab_id: project.id) + Ci::CreateCommitService.new.execute(ci_project, data) end - def get_ci_build(sha, ref) - @ci_builds ||= {} - @ci_builds[sha] ||= HTTParty.get(commit_status_path(sha, ref), verify: false) + def get_ci_commit(sha, ref) + Ci::Project.find(project.gitlab_ci_project).commits.find_by_sha_and_ref!(sha, ref) end def commit_status(sha, ref) - response = get_ci_build(sha, ref) - - if response.code == 200 and response["status"] - response["status"] - else - :error - end - rescue Errno::ECONNREFUSED + get_ci_commit(sha, ref).status + rescue ActiveRecord::RecordNotFound :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 def commit_coverage(sha, ref) - response = get_ci_build(sha, ref) - - if response.code == 200 and response["coverage"] - response["coverage"] - end - rescue Errno::ECONNREFUSED - nil + get_ci_commit(sha, ref).coverage + rescue ActiveRecord::RecordNotFound + :error end def build_page(sha, ref) - URI::encode(project_url + "/refs/#{ref}/commits/#{sha}") - end - - def builds_path - project_url + "?ref=" + project.default_branch - end - - def status_img_path - project_url + "/status.png?ref=" + project.default_branch + Ci::RoutesHelper.ci_project_ref_commits_path(project.gitlab_ci_project, ref, sha) end def title @@ -135,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 @@ -148,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 |