Class: MockCiService
- Inherits:
-
CiService
- Object
- ActiveRecord::Base
- ApplicationRecord
- Service
- CiService
- MockCiService
- Defined in:
- app/models/project_services/mock_ci_service.rb
Overview
For an example companion mocking service, see gitlab.com/gitlab-org/gitlab-mock-ci-service
Constant Summary collapse
- ALLOWED_STATES =
%w[failed canceled running pending success success-with-warnings skipped not_found].freeze
Constants inherited from Service
Service::DEV_SERVICE_NAMES, Service::SERVICE_NAMES
Instance Attribute Summary
Attributes included from Importable
Class Method Summary collapse
Instance Method Summary collapse
-
#build_page(sha, ref) ⇒ Object
Return complete url to build page.
- #can_test? ⇒ Boolean
-
#commit_status(sha, ref) ⇒ Object
Return string with build status or :error symbol.
- #commit_status_path(sha) ⇒ Object
- #description ⇒ Object
- #fields ⇒ Object
- #read_commit_status(response) ⇒ Object
- #title ⇒ Object
Methods inherited from CiService
supported_events, #valid_token?
Methods inherited from Service
#activated?, #api_field_names, #async_execute, available_services_names, available_services_types, boolean_accessor, build_from_integration, #category, #configurable_event_actions, #configurable_events, default_integration, dev_services_names, #editable?, #event_channel_names, event_description, #event_field, event_names, #event_names, #execute, find_or_create_templates, find_or_initialize_all, find_or_initialize_integration, #global_fields, #help, #initialize_properties, instance_exists_for?, #issue_tracker?, #json_fields, #operating?, prop_accessor, #reset_updated_properties, services_names, services_types, #show_active_box?, supported_event_actions, #supported_events, supported_events, #supports_data_fields?, #test, #to_data_fields_hash, #to_param, #to_service_hash, #updated_properties
Methods included from ProjectServicesLoggable
#build_message, #log_error, #log_info, #logger
Methods inherited from ApplicationRecord
at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order
Class Method Details
.to_param ⇒ Object
18 19 20 |
# File 'app/models/project_services/mock_ci_service.rb', line 18 def self.to_param 'mock_ci' end |
Instance Method Details
#build_page(sha, ref) ⇒ Object
Return complete url to build page
Ex.
http://jenkins.example.com:8888/job/test1/scm/bySHA1/12d65c
36 37 38 39 40 |
# File 'app/models/project_services/mock_ci_service.rb', line 36 def build_page(sha, ref) Gitlab::Utils.append_path( mock_service_url, "#{project.namespace.path}/#{project.path}/status/#{sha}") end |
#can_test? ⇒ Boolean
84 85 86 |
# File 'app/models/project_services/mock_ci_service.rb', line 84 def can_test? false end |
#commit_status(sha, ref) ⇒ Object
Return string with build status or :error symbol
Allowed states: 'success', 'failed', 'running', 'pending', 'skipped'
Ex.
@service.commit_status('13be4ac', 'master')
# => 'success'
@service.commit_status('2abe4ac', 'dev')
# => 'running'
55 56 57 58 59 60 |
# File 'app/models/project_services/mock_ci_service.rb', line 55 def commit_status(sha, ref) response = Gitlab::HTTP.get(commit_status_path(sha), verify: false) read_commit_status(response) rescue Errno::ECONNREFUSED :error end |
#commit_status_path(sha) ⇒ Object
62 63 64 65 66 |
# File 'app/models/project_services/mock_ci_service.rb', line 62 def commit_status_path(sha) Gitlab::Utils.append_path( mock_service_url, "#{project.namespace.path}/#{project.path}/status/#{sha}.json") end |
#description ⇒ Object
14 15 16 |
# File 'app/models/project_services/mock_ci_service.rb', line 14 def description 'Mock an external CI' end |
#fields ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/models/project_services/mock_ci_service.rb', line 22 def fields [ { type: 'text', name: 'mock_service_url', placeholder: 'http://localhost:4004', required: true } ] end |
#read_commit_status(response) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/project_services/mock_ci_service.rb', line 68 def read_commit_status(response) return :error unless response.code == 200 || response.code == 404 status = if response.code == 404 'pending' else response['status'] end if status.present? && ALLOWED_STATES.include?(status) status else :error end end |
#title ⇒ Object
10 11 12 |
# File 'app/models/project_services/mock_ci_service.rb', line 10 def title 'MockCI' end |