Commit cce27a6a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add parent CiService class for easy add of new services

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent e6d2c02e
# 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?
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# api_key :string(255) # api_key :string(255)
# #
class JenkinsService < Service class JenkinsService < CiService
attr_accessible :project_url attr_accessible :project_url
validates :project_url, presence: true, if: :activated? validates :project_url, presence: true, if: :activated?
...@@ -55,7 +55,7 @@ class JenkinsService < Service ...@@ -55,7 +55,7 @@ class JenkinsService < Service
end end
def commit_status sha def commit_status sha
response = HTTParty.get(commit_status_path(sha), verify: false) response = HTTParty.get(build_page(sha), verify: false)
if response.code == 200 if response.code == 200
if response.include?('alt="Success"') if response.include?('alt="Success"')
...@@ -71,8 +71,4 @@ class JenkinsService < Service ...@@ -71,8 +71,4 @@ class JenkinsService < Service
:error :error
end end
end end
def commit_status_path sha
project_url + "/job/test1/scm/bySHA1/#{sha}"
end
end end
...@@ -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
......
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