Commit 5580dc99 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'backport-ci-service' into 'master'

Backport CI service refactoring from EE

It allows easier contribution of different CI services.
Fixes #1280
parents 666260bf a3db7631
...@@ -160,7 +160,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -160,7 +160,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def ci_status 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} response = {status: status}
render json: response render json: response
......
...@@ -32,7 +32,7 @@ module MergeRequestsHelper ...@@ -32,7 +32,7 @@ module MergeRequestsHelper
end end
def ci_build_details_path merge_request 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 end
def merge_path_description(merge_request, separator) def merge_path_description(merge_request, separator)
......
...@@ -54,6 +54,9 @@ class Project < ActiveRecord::Base ...@@ -54,6 +54,9 @@ class Project < ActiveRecord::Base
belongs_to :namespace belongs_to :namespace
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event', foreign_key: 'project_id' 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 :gitlab_ci_service, dependent: :destroy
has_one :campfire_service, dependent: :destroy has_one :campfire_service, dependent: :destroy
has_one :emails_on_push_service, dependent: :destroy has_one :emails_on_push_service, dependent: :destroy
...@@ -322,6 +325,14 @@ class Project < ActiveRecord::Base ...@@ -322,6 +325,14 @@ class Project < ActiveRecord::Base
gitlab_ci_service && gitlab_ci_service.active gitlab_ci_service && gitlab_ci_service.active
end 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 # For compatibility with old code
def code def code
path 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 @@ ...@@ -17,7 +17,7 @@
# api_key :string(255) # api_key :string(255)
# #
class GitlabCiService < Service class GitlabCiService < CiService
attr_accessible :project_url attr_accessible :project_url
validates :project_url, presence: true, if: :activated? validates :project_url, presence: true, if: :activated?
......
...@@ -33,6 +33,10 @@ class Service < ActiveRecord::Base ...@@ -33,6 +33,10 @@ class Service < ActiveRecord::Base
active active
end end
def category
:common
end
def title def title
# implement inside child # implement inside child
end end
...@@ -41,6 +45,10 @@ class Service < ActiveRecord::Base ...@@ -41,6 +45,10 @@ class Service < ActiveRecord::Base
# implement inside child # implement inside child
end end
def help
# implement inside child
end
def to_param def to_param
# implement inside child # implement inside child
end end
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}", url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}",
check_enable: #{@merge_request.unchecked? ? "true" : "false"}, check_enable: #{@merge_request.unchecked? ? "true" : "false"},
url_to_ci_check: "#{ci_status_project_merge_request_path(@project, @merge_request)}", 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}", current_status: "#{@merge_request.merge_status_name}",
action: "#{controller.action_name}" action: "#{controller.action_name}"
}); });
.panel.mr-state-widget.panel-default .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 .panel-heading
= render "projects/merge_requests/show/mr_ci" = render "projects/merge_requests/show/mr_ci"
.panel-body .panel-body
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
- @service.errors.full_messages.each do |msg| - @service.errors.full_messages.each do |msg|
%li= msg %li= msg
- if @service.help.present?
.bs-callout
= @service.help
.form-group .form-group
= f.label :active, "Active", class: "control-label" = 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