Class: Integrations::Pushover

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

Constant Summary collapse

BASE_URI =
'https://api.pushover.net/1'

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::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 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_names, #event_names, field, 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, #supports_data_fields?, #test, #testable?, #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

.supported_eventsObject


97
98
99
# File 'app/models/integrations/pushover.rb', line 97

def self.supported_events
  %w(push)
end

.to_paramObject


18
19
20
# File 'app/models/integrations/pushover.rb', line 18

def self.to_param
  'pushover'
end

Instance Method Details

#descriptionObject


14
15
16
# File 'app/models/integrations/pushover.rb', line 14

def description
  s_('PushoverService|Get real-time notifications on your device.')
end

#execute(data) ⇒ Object


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/models/integrations/pushover.rb', line 101

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

  ref = Gitlab::Git.ref_name(data[:ref])
  before = data[:before]
  after = data[:after]

  message =
    if Gitlab::Git.blank_ref?(before)
      s_("PushoverService|%{user_name} pushed new branch \"%{ref}\".") % { user_name: data[:user_name], ref: ref }
    elsif Gitlab::Git.blank_ref?(after)
      s_("PushoverService|%{user_name} deleted branch \"%{ref}\".") % { user_name: data[:user_name], ref: ref }
    else
      s_("PushoverService|%{user_name} push to branch \"%{ref}\".") % { user_name: data[:user_name], ref: ref }
    end

  if data[:total_commits_count] > 0
    message = [message, s_("PushoverService|Total commits count: %{total_commits_count}") % { total_commits_count: data[:total_commits_count] }].join("\n")
  end

  pushover_data = {
    token: api_key,
    user: user_key,
    device: device,
    priority: priority,
    title: "#{project.full_name}",
    message: message,
    url: data[:project][:web_url],
    url_title: s_("PushoverService|See project %{project_full_name}") % { project_full_name: project.full_name }
  }

  # Sound parameter MUST NOT be sent to API if not selected
  if sound
    pushover_data[:sound] = sound
  end

  Gitlab::HTTP.post('/messages.json', base_uri: BASE_URI, body: pushover_data)
end

#fieldsObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/integrations/pushover.rb', line 22

def fields
  [
    {
      type: 'password',
      name: 'api_key',
      title: _('API key'),
      help: s_('PushoverService|Enter your application key.'),
      non_empty_password_title: s_('ProjectService|Enter new API key'),
      non_empty_password_help: s_('ProjectService|Leave blank to use your current API key.'),
      placeholder: '',
      required: true
    },
    {
      type: 'password',
      name: 'user_key',
      title: _('User key'),
      help: s_('PushoverService|Enter your user key.'),
      non_empty_password_title: s_('PushoverService|Enter new user key'),
      non_empty_password_help: s_('PushoverService|Leave blank to use your current user key.'),
      placeholder: '',
      required: true
    },
    {
      type: 'text',
      name: 'device',
      title: _('Devices (optional)'),
      help: s_('PushoverService|Leave blank for all active devices.'),
      placeholder: ''
    },
    {
      type: 'select',
      name: 'priority',
      required: true,
      choices:
      [
        [s_('PushoverService|Lowest priority'), -2],
        [s_('PushoverService|Low priority'), -1],
        [s_('PushoverService|Normal priority'), 0],
        [s_('PushoverService|High priority'), 1]
      ],
      default_choice: 0
    },
    {
      type: 'select',
      name: 'sound',
      choices:
      [
        ['Device default sound', nil],
        ['Pushover (default)', 'pushover'],
        %w(Bike bike),
        %w(Bugle bugle),
        ['Cash Register', 'cashregister'],
        %w(Classical classical),
        %w(Cosmic cosmic),
        %w(Falling falling),
        %w(Gamelan gamelan),
        %w(Incoming incoming),
        %w(Intermission intermission),
        %w(Magic magic),
        %w(Mechanical mechanical),
        ['Piano Bar', 'pianobar'],
        %w(Siren siren),
        ['Space Alarm', 'spacealarm'],
        ['Tug Boat', 'tugboat'],
        ['Alien Alarm (long)', 'alien'],
        ['Climb (long)', 'climb'],
        ['Persistent (long)', 'persistent'],
        ['Pushover Echo (long)', 'echo'],
        ['Up Down (long)', 'updown'],
        ['None (silent)', 'none']
      ]
    }
  ]
end

#titleObject


10
11
12
# File 'app/models/integrations/pushover.rb', line 10

def title
  'Pushover'
end