diff options
author | Sullivan SENECHAL <soullivaneuh@gmail.com> | 2014-10-01 02:48:41 +0200 |
---|---|---|
committer | Sullivan SENECHAL <soullivaneuh@gmail.com> | 2014-10-03 13:54:37 +0200 |
commit | d1fa3b336d1d3e3c1f9a10ca007e3d1193e5e205 (patch) | |
tree | 4ab193d600aa60182b1f0ff01bfd116b640b274f /app | |
parent | 43217dd5ddcb7557ea0c7300c6a02253f1b99d7d (diff) | |
download | gitlab-ce-d1fa3b336d1d3e3c1f9a10ca007e3d1193e5e205.tar.gz |
Add Pushover service integration
That introduce select field type for services options.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/services_controller.rb | 3 | ||||
-rw-r--r-- | app/models/project.rb | 3 | ||||
-rw-r--r-- | app/models/project_services/pushover_service.rb | 113 | ||||
-rw-r--r-- | app/views/projects/services/_form.html.haml | 5 |
4 files changed, 122 insertions, 2 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb index b143dec3a93..4c558e137ea 100644 --- a/app/controllers/projects/services_controller.rb +++ b/app/controllers/projects/services_controller.rb @@ -40,7 +40,8 @@ class Projects::ServicesController < Projects::ApplicationController def service_params params.require(:service).permit( :title, :token, :type, :active, :api_key, :subdomain, - :room, :recipients, :project_url + :room, :recipients, :project_url, + :user_key, :device, :priority, :sound ) end end diff --git a/app/models/project.rb b/app/models/project.rb index d228da192e4..44d63d37bee 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -64,6 +64,7 @@ class Project < ActiveRecord::Base has_one :assembla_service, dependent: :destroy has_one :gemnasium_service, dependent: :destroy has_one :slack_service, dependent: :destroy + has_one :pushover_service, dependent: :destroy has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" has_one :forked_from_project, through: :forked_project_link # Merge Requests for target project should be removed with it @@ -311,7 +312,7 @@ class Project < ActiveRecord::Base end def available_services_names - %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium slack) + %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium slack pushover) end def gitlab_ci? diff --git a/app/models/project_services/pushover_service.rb b/app/models/project_services/pushover_service.rb new file mode 100644 index 00000000000..f247fde7762 --- /dev/null +++ b/app/models/project_services/pushover_service.rb @@ -0,0 +1,113 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +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 + + def execute(push_data) + ref = push_data[:ref].gsub('refs/heads/', '') + before = push_data[:before] + after = push_data[:after] + + if before =~ /000000/ + message = "#{push_data[:user_name]} pushed new branch \"#{ref}\"." + elsif after =~ /000000/ + message = "#{push_data[:user_name]} deleted branch \"#{ref}\"." + else + message = "#{push_data[:user_name]} push to branch \"#{ref}\"." + end + + if push_data[:total_commits_count] > 0 + message << "\nTotal commits count: #{push_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: push_data[:repository][:homepage], + 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 diff --git a/app/views/projects/services/_form.html.haml b/app/views/projects/services/_form.html.haml index a5db7969a68..16d59d1fe9d 100644 --- a/app/views/projects/services/_form.html.haml +++ b/app/views/projects/services/_form.html.haml @@ -28,8 +28,11 @@ - @service.fields.each do |field| - name = field[:name] + - value = @service.send(name) - type = field[:type] - placeholder = field[:placeholder] + - choices = field[:choices] + - default_choice = field[:default_choice] .form-group = f.label name, class: "control-label" @@ -40,6 +43,8 @@ = f.text_area name, rows: 5, class: "form-control", placeholder: placeholder - elsif type == 'checkbox' = f.check_box name + - elsif type == 'select' + = f.select name, options_for_select(choices, value ? value : default_choice), {}, { class: "form-control" } .form-actions = f.submit 'Save', class: 'btn btn-save' |