Class: Integrations::BaseIssueTracker

Inherits:
Integration show all
Defined in:
app/models/integrations/base_issue_tracker.rb

Constant Summary

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 inherited from Integration

#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, #description, dev_integration_names, #dup, #editable?, #event_channel_names, event_description, event_names, #event_names, 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, #test, #testable?, #title, #to_database_hash, #to_param, 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

.base_reference_pattern(only_long: false) ⇒ Object

Pattern used to extract links from comments Override this method on services that uses different patterns This pattern does not support cross-project references The other code assumes that this pattern is a superset of all overridden patterns. See ReferenceRegexes.external_pattern



17
18
19
20
21
22
23
# File 'app/models/integrations/base_issue_tracker.rb', line 17

def self.base_reference_pattern(only_long: false)
  if only_long
    /(\b[A-Z][A-Z0-9_]*-)#{Gitlab::Regex.issue}/
  else
    /(\b[A-Z][A-Z0-9_]*-|#{Issue.reference_prefix})#{Gitlab::Regex.issue}/
  end
end

.supported_eventsObject



90
91
92
# File 'app/models/integrations/base_issue_tracker.rb', line 90

def self.supported_events
  %w[push]
end

Instance Method Details

#activate_disabled_reasonObject



126
127
128
# File 'app/models/integrations/base_issue_tracker.rb', line 126

def activate_disabled_reason
  { trackers: other_external_issue_trackers } if other_external_issue_trackers.any?
end

#create_cross_reference_note(external_issue, mentioned_in, author) ⇒ Object



122
123
124
# File 'app/models/integrations/base_issue_tracker.rb', line 122

def create_cross_reference_note(external_issue, mentioned_in, author)
  # implement inside child
end

#data_fieldsObject



54
55
56
# File 'app/models/integrations/base_issue_tracker.rb', line 54

def data_fields
  issue_tracker_data || self.build_issue_tracker_data
end

#default?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/integrations/base_issue_tracker.rb', line 58

def default?
  default
end

#execute(data) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/integrations/base_issue_tracker.rb', line 94

def execute(data)
  return unless supported_events.include?(data[:object_kind])

  message = "#{self.type} was unable to reach #{self.project_url}. Check the url and try again."
  result = false

  begin
    response = Gitlab::HTTP.head(self.project_url, verify: true)

    if response
      message = "#{self.type} received response #{response.code} when attempting to connect to #{self.project_url}"
      result = true
    end
  rescue Gitlab::HTTP::Error, Timeout::Error, SocketError, Errno::ECONNRESET, Errno::ECONNREFUSED, OpenSSL::SSL::SSLError => e
    message = "#{self.type} had an error when trying to connect to #{self.project_url}: #{e.message}"
  end
  log_info(message)
  result
end

#handle_propertiesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/integrations/base_issue_tracker.rb', line 29

def handle_properties
  # this has been moved from initialize_properties and should be improved
  # as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
  return unless properties.present?

  safe_keys = data_fields.attributes.keys.grep_v(/encrypted/) - %w[id service_id created_at]

  @legacy_properties_data = properties.dup

  data_values = properties.slice(*safe_keys)
  data_values.reject! { |key| data_fields.changed.include?(key) }

  data_fields.assign_attributes(data_values) if data_values.present?

  self.properties = {}
end

#issue_path(iid) ⇒ Object



74
75
76
# File 'app/models/integrations/base_issue_tracker.rb', line 74

def issue_path(iid)
  issue_url(iid)
end

#issue_tracker_pathObject



66
67
68
# File 'app/models/integrations/base_issue_tracker.rb', line 66

def issue_tracker_path
  project_url
end

#issue_url(iid) ⇒ Object



62
63
64
# File 'app/models/integrations/base_issue_tracker.rb', line 62

def issue_url(iid)
  issues_url.gsub(':id', iid.to_s)
end

#legacy_properties_dataObject



46
47
48
# File 'app/models/integrations/base_issue_tracker.rb', line 46

def legacy_properties_data
  @legacy_properties_data ||= {}
end

#new_issue_pathObject



70
71
72
# File 'app/models/integrations/base_issue_tracker.rb', line 70

def new_issue_path
  new_issue_url
end

#reference_pattern(only_long: false) ⇒ Object



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

def reference_pattern(only_long: false)
  self.class.base_reference_pattern(only_long: only_long)
end

#set_default_dataObject

Initialize with default properties values



79
80
81
82
83
84
85
86
87
88
# File 'app/models/integrations/base_issue_tracker.rb', line 79

def set_default_data
  return unless issues_tracker.present?

  # we don't want to override if we have set something
  return if project_url || issues_url || new_issue_url

  data_fields.project_url = issues_tracker['project_url']
  data_fields.issues_url = issues_tracker['issues_url']
  data_fields.new_issue_url = issues_tracker['new_issue_url']
end

#support_close_issue?Boolean

Returns:

  • (Boolean)


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

def support_close_issue?
  false
end

#support_cross_reference?Boolean

Returns:

  • (Boolean)


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

def support_cross_reference?
  false
end

#supports_data_fields?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/models/integrations/base_issue_tracker.rb', line 50

def supports_data_fields?
  true
end