2014-09-30 20:48:41 -04:00
|
|
|
class PushoverService < Service
|
|
|
|
include HTTParty
|
|
|
|
base_uri 'https://api.pushover.net/1'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def to_param
|
|
|
|
'pushover'
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-02-28 11:33:18 -05:00
|
|
|
def supported_events
|
|
|
|
%w(push)
|
|
|
|
end
|
|
|
|
|
2015-02-20 08:49:26 -05:00
|
|
|
def execute(data)
|
2015-02-28 11:33:18 -05:00
|
|
|
return unless supported_events.include?(data[:object_kind])
|
2015-02-19 00:02:57 -05:00
|
|
|
|
2015-03-10 06:51:36 -04:00
|
|
|
ref = Gitlab::Git.ref_name(data[:ref])
|
2015-02-20 08:49:26 -05:00
|
|
|
before = data[:before]
|
|
|
|
after = data[:after]
|
2014-09-30 20:48:41 -04:00
|
|
|
|
2015-03-10 06:51:36 -04:00
|
|
|
if Gitlab::Git.blank_ref?(before)
|
2015-02-20 08:49:26 -05:00
|
|
|
message = "#{data[:user_name]} pushed new branch \"#{ref}\"."
|
2015-03-10 06:51:36 -04:00
|
|
|
elsif Gitlab::Git.blank_ref?(after)
|
2015-02-20 08:49:26 -05:00
|
|
|
message = "#{data[:user_name]} deleted branch \"#{ref}\"."
|
2014-09-30 20:48:41 -04:00
|
|
|
else
|
2015-02-20 08:49:26 -05:00
|
|
|
message = "#{data[:user_name]} push to branch \"#{ref}\"."
|
2014-09-30 20:48:41 -04:00
|
|
|
end
|
|
|
|
|
2015-02-20 08:49:26 -05:00
|
|
|
if data[:total_commits_count] > 0
|
|
|
|
message << "\nTotal commits count: #{data[:total_commits_count]}"
|
2014-09-30 20:48:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
pushover_data = {
|
|
|
|
token: api_key,
|
|
|
|
user: user_key,
|
|
|
|
device: device,
|
|
|
|
priority: priority,
|
|
|
|
title: "#{project.name_with_namespace}",
|
|
|
|
message: message,
|
2016-02-16 07:03:00 -05:00
|
|
|
url: data[:project][:web_url],
|
2014-09-30 20:48:41 -04:00
|
|
|
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
|
|
|
|
end
|