Class: Integrations::DroneCi

Inherits:
BaseCi show all
Extended by:
Gitlab::Utils::Override
Includes:
EnableSslVerification, HasWebHook, PushDataValidations, ReactivelyCached
Defined in:
app/models/integrations/drone_ci.rb

Constant Summary collapse

DRONE_SAAS_HOSTNAME =
'cloud.drone.io'

Constants inherited from Integration

Integration::BASE_CLASSES, Integration::DEV_INTEGRATION_NAMES, Integration::INTEGRATION_NAMES, Integration::PROJECT_SPECIFIC_INTEGRATION_NAMES, Integration::SECTION_TYPE_CONNECTION, Integration::UnknownType

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

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

Methods included from PushDataValidations

#merge_request_valid?, #push_valid?, #tag_push_valid?

Methods included from HasWebHook

#execute_web_hook!, #hook_ssl_verification

Methods included from EnableSslVerification

#fields, #initialize_properties

Methods inherited from BaseCi

#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, #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_field, #event_names, event_names, field, fields, #fields, find_or_initialize_all_non_project_specific, find_or_initialize_non_project_specific_integration, #global_fields, #group_level?, #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, #supports_data_fields?, #test, #testable?, #to_data_fields_hash, #to_integration_hash, #to_param, #updated_properties

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

.supported_eventsObject


45
46
47
# File 'app/models/integrations/drone_ci.rb', line 45

def self.supported_events
  %w(push merge_request tag_push)
end

.to_paramObject


99
100
101
# File 'app/models/integrations/drone_ci.rb', line 99

def self.to_param
  'drone_ci'
end

Instance Method Details

#allow_target_ci?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'app/models/integrations/drone_ci.rb', line 41

def allow_target_ci?
  true
end

#build_page(sha, ref) ⇒ Object


85
86
87
88
89
# File 'app/models/integrations/drone_ci.rb', line 85

def build_page(sha, ref)
  Gitlab::Utils.append_path(
    drone_url,
    "gitlab/#{project.full_path}/redirect/commits/#{sha}?branch=#{Addressable::URI.encode_component(ref.to_s)}")
end

#calculate_reactive_cache(sha, ref) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/integrations/drone_ci.rb', line 59

def calculate_reactive_cache(sha, ref)
  response = Gitlab::HTTP.try_get(
    commit_status_path(sha, ref),
    verify: enable_ssl_verification,
    extra_log_info: { project_id: project_id },
    use_read_total_timeout: true
  )

  status =
    if response && response.code == 200 && response['status']
      case response['status']
      when 'killed'
        :canceled
      when 'failure', 'error'
        # Because drone return error if some test env failed
        :failed
      else
        response["status"]
      end
    else
      :error
    end

  { commit_status: status }
end

#commit_status(sha, ref) ⇒ Object


55
56
57
# File 'app/models/integrations/drone_ci.rb', line 55

def commit_status(sha, ref)
  with_reactive_cache(sha, ref) { |cached| cached[:commit_status] }
end

#commit_status_path(sha, ref) ⇒ Object


49
50
51
52
53
# File 'app/models/integrations/drone_ci.rb', line 49

def commit_status_path(sha, ref)
  Gitlab::Utils.append_path(
    drone_url,
    "gitlab/#{project.full_path}/commits/#{sha}?branch=#{Addressable::URI.encode_component(ref.to_s)}&access_token=#{token}")
end

#descriptionObject


95
96
97
# File 'app/models/integrations/drone_ci.rb', line 95

def description
  s_('ProjectService|Run CI/CD pipelines with Drone.')
end

#enable_ssl_verificationObject


118
119
120
121
# File 'app/models/integrations/drone_ci.rb', line 118

def enable_ssl_verification
  original_value = Gitlab::Utils.to_boolean(properties['enable_ssl_verification'])
  original_value.nil? ? (new_record? || url_is_saas?) : original_value
end

#execute(data) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/integrations/drone_ci.rb', line 28

def execute(data)
  return unless project

  case data[:object_kind]
  when 'push'
    execute_web_hook!(data) if push_valid?(data)
  when 'merge_request'
    execute_web_hook!(data) if merge_request_valid?(data)
  when 'tag_push'
    execute_web_hook!(data) if tag_push_valid?(data)
  end
end

#helpObject


103
104
105
# File 'app/models/integrations/drone_ci.rb', line 103

def help
  s_('ProjectService|Run CI/CD pipelines with Drone.')
end

#hook_urlObject


108
109
110
# File 'app/models/integrations/drone_ci.rb', line 108

def hook_url
  [drone_url, "/hook", "?owner=#{project.namespace.full_path}", "&name=#{project.path}", "&access_token=#{token}"].join
end

#titleObject


91
92
93
# File 'app/models/integrations/drone_ci.rb', line 91

def title
  'Drone'
end

#update_web_hook!Object


113
114
115
116
# File 'app/models/integrations/drone_ci.rb', line 113

def update_web_hook!
  # If using a service template, project may not be available
  super if project
end