Commit f7471e0b authored by Markus Koller's avatar Markus Koller

Move Pushover integration to Integrations namespace

Part of https://gitlab.com/gitlab-org/gitlab/-/issues/201855
parent e7cfd585
......@@ -1652,7 +1652,6 @@ Gitlab/NamespacedClass:
- 'app/models/project_services/mock_monitoring_service.rb'
- 'app/models/project_services/monitoring_service.rb'
- 'app/models/project_services/prometheus_service.rb'
- 'app/models/project_services/pushover_service.rb'
- 'app/models/project_services/slack_slash_commands_service.rb'
- 'app/models/project_services/slash_commands_service.rb'
- 'app/models/project_setting.rb'
......
# frozen_string_literal: true
module Integrations
class Pushover < Integration
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
s_('PushoverService|Get real-time notifications on your device.')
end
def self.to_param
'pushover'
end
def fields
[
{ type: 'text', name: 'api_key', title: _('API key'), placeholder: s_('PushoverService|Your application key'), required: true },
{ type: 'text', name: 'user_key', placeholder: s_('PushoverService|Your user key'), required: true },
{ type: 'text', name: 'device', placeholder: s_('PushoverService|Leave blank for all active devices') },
{ 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
def self.supported_events
%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]
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
end
end
......@@ -182,6 +182,7 @@ class Project < ApplicationRecord
has_one :packagist_service, class_name: 'Integrations::Packagist'
has_one :pipelines_email_service, class_name: 'Integrations::PipelinesEmail'
has_one :pivotaltracker_service, class_name: 'Integrations::Pivotaltracker'
has_one :pushover_service, class_name: 'Integrations::Pushover'
has_one :redmine_service, class_name: 'Integrations::Redmine'
has_one :slack_service, class_name: 'Integrations::Slack'
has_one :teamcity_service, class_name: 'Integrations::Teamcity'
......@@ -190,7 +191,6 @@ class Project < ApplicationRecord
has_one :youtrack_service, class_name: 'Integrations::Youtrack'
has_one :mattermost_slash_commands_service
has_one :slack_slash_commands_service
has_one :pushover_service
has_one :prometheus_service, inverse_of: :project
has_one :mock_monitoring_service
......
# frozen_string_literal: true
class PushoverService < Integration
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
s_('PushoverService|Get real-time notifications on your device.')
end
def self.to_param
'pushover'
end
def fields
[
{ type: 'text', name: 'api_key', title: _('API key'), placeholder: s_('PushoverService|Your application key'), required: true },
{ type: 'text', name: 'user_key', placeholder: s_('PushoverService|Your user key'), required: true },
{ type: 'text', name: 'device', placeholder: s_('PushoverService|Leave blank for all active devices') },
{ 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
def self.supported_events
%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]
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
end
......@@ -798,14 +798,14 @@ module API
::Integrations::Packagist,
::Integrations::PipelinesEmail,
::Integrations::Pivotaltracker,
::Integrations::Pushover,
::Integrations::Redmine,
::Integrations::Slack,
::Integrations::Teamcity,
::Integrations::Youtrack,
::MattermostSlashCommandsService,
::SlackSlashCommandsService,
::PrometheusService,
::PushoverService
::PrometheusService
]
end
......
......@@ -7,7 +7,7 @@ module Gitlab
Asana Assembla Bamboo Bugzilla Buildkite Campfire Confluence CustomIssueTracker Datadog
Discord DroneCi EmailsOnPush Ewm ExternalWiki Flowdock HangoutsChat IssueTracker Irker
Jenkins Jira Mattermost MicrosoftTeams MockCi Packagist PipelinesEmail Pivotaltracker
Redmine Slack Teamcity UnifyCircuit Youtrack WebexTeams
Pushover Redmine Slack Teamcity UnifyCircuit Youtrack WebexTeams
)).freeze
def cast(value)
......
......@@ -446,7 +446,7 @@ RSpec.describe Integration do
describe "for pushover service" do
let!(:service_template) do
PushoverService.create!(
Integrations::Pushover.create!(
template: true,
properties: {
device: 'MyDevice',
......@@ -672,7 +672,7 @@ RSpec.describe Integration do
expect(described_class.service_name_to_model('asana')).to eq(Integrations::Asana)
# TODO We can remove this test when all models have been namespaced:
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/60968#note_570994955
expect(described_class.service_name_to_model('pushover')).to eq(PushoverService)
expect(described_class.service_name_to_model('prometheus')).to eq(PrometheusService)
end
it 'raises an error if service name is invalid' do
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe PushoverService do
RSpec.describe Integrations::Pushover do
include StubRequests
describe 'Associations' do
......
......@@ -6,7 +6,7 @@ RSpec.describe Admin::PropagateServiceTemplate do
describe '.propagate' do
let_it_be(:project) { create(:project) }
let!(:service_template) do
PushoverService.create!(
Integrations::Pushover.create!(
template: true,
active: true,
push_events: false,
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe PropagateIntegrationWorker do
describe '#perform' do
let(:integration) do
PushoverService.create!(
Integrations::Pushover.create!(
template: true,
active: true,
device: 'MyDevice',
......
......@@ -7,7 +7,7 @@ RSpec.describe PropagateServiceTemplateWorker do
describe '#perform' do
it 'calls the propagate service with the template' do
template = PushoverService.create!(
template = Integrations::Pushover.create!(
template: true,
active: true,
properties: {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment