Commit a18ae13e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Backport CI service refactoring from EE

It allows easier contribution of different CI services
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 49c50ee8
......@@ -160,7 +160,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
def ci_status
status = @merge_request.source_project.gitlab_ci_service.commit_status(merge_request.last_commit.sha)
status = @merge_request.source_project.ci_service.commit_status(merge_request.last_commit.sha)
response = {status: status}
render json: response
......
......@@ -32,7 +32,7 @@ module MergeRequestsHelper
end
def ci_build_details_path merge_request
merge_request.source_project.gitlab_ci_service.build_page(merge_request.last_commit.sha)
merge_request.source_project.ci_service.build_page(merge_request.last_commit.sha)
end
def merge_path_description(merge_request, separator)
......
......@@ -54,6 +54,9 @@ class Project < ActiveRecord::Base
belongs_to :namespace
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event', foreign_key: 'project_id'
# Project services
has_many :services
has_one :gitlab_ci_service, dependent: :destroy
has_one :campfire_service, dependent: :destroy
has_one :emails_on_push_service, dependent: :destroy
......@@ -322,6 +325,14 @@ class Project < ActiveRecord::Base
gitlab_ci_service && gitlab_ci_service.active
end
def ci_services
services.select { |service| service.category == :ci }
end
def ci_service
@ci_service ||= services.select(&:activated?).first
end
# For compatibility with old code
def code
path
......
# Base class for CI services
# List methods you need to implement to get your CI service
# working with GitLab Merge Requests
class CiService < Service
def category
:ci
end
# Return complete url to build page
#
# Ex.
# http://jenkins.example.com:8888/job/test1/scm/bySHA1/12d65c
#
def build_page(sha)
# implement inside child
end
# Return string with build status or :error symbol
#
# Allowed states: 'success', 'failed', 'running', 'pending'
#
#
# Ex.
# @service.commit_status('13be4ac')
# # => 'success'
#
# @service.commit_status('2abe4ac')
# # => 'running'
#
#
def commit_status(sha)
# implement inside child
end
end
......@@ -17,7 +17,7 @@
# api_key :string(255)
#
class GitlabCiService < Service
class GitlabCiService < CiService
attr_accessible :project_url
validates :project_url, presence: true, if: :activated?
......
......@@ -33,6 +33,10 @@ class Service < ActiveRecord::Base
active
end
def category
:common
end
def title
# implement inside child
end
......@@ -41,6 +45,10 @@ class Service < ActiveRecord::Base
# implement inside child
end
def help
# implement inside child
end
def to_param
# implement inside child
end
......
......@@ -40,7 +40,7 @@
url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}",
check_enable: #{@merge_request.unchecked? ? "true" : "false"},
url_to_ci_check: "#{ci_status_project_merge_request_path(@project, @merge_request)}",
ci_enable: #{@project.gitlab_ci? ? "true" : "false"},
ci_enable: #{@project.ci_service ? "true" : "false"},
current_status: "#{@merge_request.merge_status_name}",
action: "#{controller.action_name}"
});
.panel.mr-state-widget.panel-default
- if @merge_request.source_project.gitlab_ci? && @commits.any?
- if @merge_request.source_project.ci_service && @commits.any?
.panel-heading
= render "projects/merge_requests/show/mr_ci"
.panel-body
......
......@@ -17,6 +17,9 @@
- @service.errors.full_messages.each do |msg|
%li= msg
- if @service.help.present?
.bs-callout
= @service.help
.form-group
= f.label :active, "Active", class: "control-label"
......
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