2015-04-26 12:48:37 +05:30
|
|
|
class PushoverService < Service
|
2018-03-26 14:24:53 +05:30
|
|
|
BASE_URI = 'https://api.pushover.net/1'.freeze
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
prop_accessor :api_key, :user_key, :device, :priority, :sound
|
|
|
|
validates :api_key, :user_key, :priority, presence: true, if: :activated?
|
|
|
|
|
|
|
|
def title
|
|
|
|
'Pushover'
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
'Pushover makes it easy to get real-time notifications on your Android device, iPhone, iPad, and Desktop.'
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def self.to_param
|
2015-04-26 12:48:37 +05:30
|
|
|
'pushover'
|
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
[
|
2017-09-10 17:25:29 +05:30
|
|
|
{ type: 'text', name: 'api_key', placeholder: 'Your application key', required: true },
|
|
|
|
{ type: 'text', name: 'user_key', placeholder: 'Your user key', required: true },
|
2015-04-26 12:48:37 +05:30
|
|
|
{ type: 'text', name: 'device', placeholder: 'Leave blank for all active devices' },
|
2017-09-10 17:25:29 +05:30
|
|
|
{ type: 'select', name: 'priority', required: true, choices:
|
2015-04-26 12:48:37 +05:30
|
|
|
[
|
|
|
|
['Lowest Priority', -2],
|
|
|
|
['Low Priority', -1],
|
|
|
|
['Normal Priority', 0],
|
|
|
|
['High Priority', 1]
|
|
|
|
],
|
2017-08-17 22:00:37 +05:30
|
|
|
default_choice: 0 },
|
2015-04-26 12:48:37 +05:30
|
|
|
{ type: 'select', name: 'sound', choices:
|
|
|
|
[
|
|
|
|
['Device default sound', nil],
|
|
|
|
['Pushover (default)', 'pushover'],
|
2017-08-17 22:00:37 +05:30
|
|
|
%w(Bike bike),
|
|
|
|
%w(Bugle bugle),
|
2015-04-26 12:48:37 +05:30
|
|
|
['Cash Register', 'cashregister'],
|
2017-08-17 22:00:37 +05:30
|
|
|
%w(Classical classical),
|
|
|
|
%w(Cosmic cosmic),
|
|
|
|
%w(Falling falling),
|
|
|
|
%w(Gamelan gamelan),
|
|
|
|
%w(Incoming incoming),
|
|
|
|
%w(Intermission intermission),
|
|
|
|
%w(Magic magic),
|
|
|
|
%w(Mechanical mechanical),
|
2015-04-26 12:48:37 +05:30
|
|
|
['Piano Bar', 'pianobar'],
|
2017-08-17 22:00:37 +05:30
|
|
|
%w(Siren siren),
|
2015-04-26 12:48:37 +05:30
|
|
|
['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']
|
2017-09-10 17:25:29 +05:30
|
|
|
] }
|
2015-04-26 12:48:37 +05:30
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def self.supported_events
|
2015-04-26 12:48:37 +05:30
|
|
|
%w(push)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(data)
|
|
|
|
return unless supported_events.include?(data[:object_kind])
|
|
|
|
|
|
|
|
ref = Gitlab::Git.ref_name(data[:ref])
|
|
|
|
before = data[:before]
|
|
|
|
after = data[:after]
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
message =
|
|
|
|
if Gitlab::Git.blank_ref?(before)
|
|
|
|
"#{data[:user_name]} pushed new branch \"#{ref}\"."
|
|
|
|
elsif Gitlab::Git.blank_ref?(after)
|
|
|
|
"#{data[:user_name]} deleted branch \"#{ref}\"."
|
|
|
|
else
|
|
|
|
"#{data[:user_name]} push to branch \"#{ref}\"."
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
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,
|
2016-04-02 18:10:28 +05:30
|
|
|
url: data[:project][:web_url],
|
2015-04-26 12:48:37 +05:30
|
|
|
url_title: "See project #{project.name_with_namespace}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sound parameter MUST NOT be sent to API if not selected
|
|
|
|
if sound
|
2017-08-17 22:00:37 +05:30
|
|
|
pushover_data[:sound] = sound
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-26 14:24:53 +05:30
|
|
|
Gitlab::HTTP.post('/messages.json', base_uri: BASE_URI, body: pushover_data)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|