Class: PushoverService

Inherits:
Service
  • Object
show all
Includes:
HTTParty
Defined in:
app/models/project_services/pushover_service.rb

Overview

Schema Information

Table name: services

id                    :integer          not null, primary key
type                  :string
title                 :string
project_id            :integer
created_at            :datetime         not null
updated_at            :datetime         not null
active                :boolean          not null
properties            :text
template              :boolean          default(FALSE)
push_events           :boolean          default(TRUE)
issues_events         :boolean          default(TRUE)
merge_requests_events :boolean          default(TRUE)
tag_push_events       :boolean          default(TRUE)
note_events           :boolean          default(TRUE), not null
build_events          :boolean          default(FALSE), not null
category              :string           default("common"), not null
default               :boolean          default(FALSE)
wiki_page_events      :boolean          default(TRUE)

Instance Method Summary collapse

Methods inherited from Service

#activated?, #async_execute, available_services_names, boolean_accessor, #can_test?, #category, create_from_template, #help, #initialize_properties, #issue_tracker?, prop_accessor, #reset_updated_properties, #template?, #test, #updated_properties

Instance Method Details

#descriptionObject


36
37
38
# File 'app/models/project_services/pushover_service.rb', line 36

def description
  'Pushover makes it easy to get real-time notifications on your Android device, iPhone, iPad, and Desktop.'
end

#execute(data) ⇒ Object


92
93
94
95
96
97
98
99
100
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
# File 'app/models/project_services/pushover_service.rb', line 92

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

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

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

  if data[:total_commits_count] > 0
    message << "\nTotal commits count: #{data[:total_commits_count]}"
  end

  pushover_data = {
    token: api_key,
    user: user_key,
    device: device,
    priority: priority,
    title: "#{project.name_with_namespace}",
    message: message,
    url: data[:project][:web_url],
    url_title: "See project #{project.name_with_namespace}"
  }

  # Sound parameter MUST NOT be sent to API if not selected
  if sound
    pushover_data.merge!(sound: sound)
  end

  PushoverService.post('/messages.json', body: pushover_data)
end

#fieldsObject


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
# File 'app/models/project_services/pushover_service.rb', line 44

def fields
  [
    { type: 'text', name: 'api_key', placeholder: 'Your application key' },
    { type: 'text', name: 'user_key', placeholder: 'Your user key' },
    { type: 'text', name: 'device', placeholder: 'Leave blank for all active devices' },
    { type: 'select', name: 'priority', choices:
      [
        ['Lowest Priority', -2],
        ['Low Priority', -1],
        ['Normal Priority', 0],
        ['High Priority', 1]
      ],
      default_choice: 0
    },
    { type: 'select', name: 'sound', choices:
      [
        ['Device default sound', nil],
        ['Pushover (default)', 'pushover'],
        ['Bike', 'bike'],
        ['Bugle', 'bugle'],
        ['Cash Register', 'cashregister'],
        ['Classical', 'classical'],
        ['Cosmic', 'cosmic'],
        ['Falling', 'falling'],
        ['Gamelan', 'gamelan'],
        ['Incoming', 'incoming'],
        ['Intermission', 'intermission'],
        ['Magic', 'magic'],
        ['Mechanical', 'mechanical'],
        ['Piano Bar', 'pianobar'],
        ['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

#supported_eventsObject


88
89
90
# File 'app/models/project_services/pushover_service.rb', line 88

def supported_events
  %w(push)
end

#titleObject


32
33
34
# File 'app/models/project_services/pushover_service.rb', line 32

def title
  'Pushover'
end

#to_paramObject


40
41
42
# File 'app/models/project_services/pushover_service.rb', line 40

def to_param
  'pushover'
end