Class: Integrations::MockCi

Inherits:
BaseCi show all
Includes:
EnableSslVerification
Defined in:
app/models/integrations/mock_ci.rb

Constant Summary collapse

ALLOWED_STATES =
%w[failed canceled running pending success success-with-warnings skipped not_found].freeze

Constants inherited from Integration

Integration::BASE_CLASSES, Integration::DEV_INTEGRATION_NAMES, Integration::INTEGRATION_NAMES, Integration::PROJECT_SPECIFIC_INTEGRATION_NAMES, Integration::SECTION_TYPE_CONFIGURATION, Integration::SECTION_TYPE_CONNECTION, Integration::SECTION_TYPE_TRIGGER, Integration::SNOWPLOW_EVENT_ACTION, Integration::SNOWPLOW_EVENT_LABEL, Integration::UnknownType

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EnableSslVerification

#fields, #initialize_properties

Methods inherited from BaseCi

supported_events, #valid_token?

Methods inherited from Integration

#activate_disabled_reason, #activated?, #api_field_names, #async_execute, #attributes, available_integration_names, available_integration_types, boolean_accessor, build_from_integration, #category, #chat?, #ci?, #configurable_events, create_from_active_default_integrations, default_integration, #default_test_event, default_test_event, dev_integration_names, #dup, #editable?, #event_channel_names, event_description, #event_names, event_names, #execute, field, #fields, fields, find_or_initialize_all_non_project_specific, find_or_initialize_non_project_specific_integration, #form_fields, #group_level?, #help, #inheritable?, inherited_descendants_from_self_or_ancestors_from, #initialize_properties, instance_exists_for?, #instance_level?, integration_name_to_model, integration_name_to_type, integration_names, #json_fields, #operating?, #parent, #project_level?, project_specific_integration_names, prop_accessor, #properties=, #reencrypt_properties, #reset_updated_properties, #secret_fields, #sections, #show_active_box?, supported_events, #supported_events, #supports_data_fields?, #test, #to_database_hash, #to_param, #updated_properties

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from ResetSecretFields

#exposing_secrets_fields

Methods included from Loggable

#build_message, #log_error, #log_exception, #log_info, #logger

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.to_paramObject



25
26
27
# File 'app/models/integrations/mock_ci.rb', line 25

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


34
35
36
37
38
# File 'app/models/integrations/mock_ci.rb', line 34

def build_page(sha, ref)
  Gitlab::Utils.append_path(
    mock_service_url,
    "#{project.namespace.path}/#{project.path}/status/#{sha}")
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'


51
52
53
54
55
56
# File 'app/models/integrations/mock_ci.rb', line 51

def commit_status(sha, ref)
  response = Gitlab::HTTP.get(commit_status_path(sha), verify: enable_ssl_verification)
  read_commit_status(response)
rescue Errno::ECONNREFUSED
  :error
end

#commit_status_path(sha) ⇒ Object



58
59
60
61
62
# File 'app/models/integrations/mock_ci.rb', line 58

def commit_status_path(sha)
  Gitlab::Utils.append_path(
    mock_service_url,
    "#{project.namespace.path}/#{project.path}/status/#{sha}.json")
end

#descriptionObject



21
22
23
# File 'app/models/integrations/mock_ci.rb', line 21

def description
  'Mock an external CI'
end

#read_commit_status(response) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/integrations/mock_ci.rb', line 64

def read_commit_status(response)
  return :pending if response.code == 404
  return :error unless response.code == 200

  begin
    status = Gitlab::Json.parse(response.body).try(:fetch, 'status', nil)
    return status if ALLOWED_STATES.include?(status)
  rescue JSON::ParserError
  end

  :error
end

#testable?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/models/integrations/mock_ci.rb', line 77

def testable?
  false
end

#titleObject



17
18
19
# File 'app/models/integrations/mock_ci.rb', line 17

def title
  'MockCI'
end