Commit ede048b9 authored by Felipe Artur's avatar Felipe Artur

Add project service documentation and update integration documentation

parent 8bd520d7
class Admin::ServicesController < Admin::ApplicationController class Admin::ServicesController < Admin::ApplicationController
include ServiceParams
before_action :service, only: [:edit, :update] before_action :service, only: [:edit, :update]
def index def index
...@@ -37,18 +39,4 @@ class Admin::ServicesController < Admin::ApplicationController ...@@ -37,18 +39,4 @@ class Admin::ServicesController < Admin::ApplicationController
def service def service
@service ||= Service.where(id: params[:id], template: true).first @service ||= Service.where(id: params[:id], template: true).first
end end
def application_services_params
dynamic_params = []
dynamic_params.concat(@service.event_channel_names) if @service.is_a?(SlackService)
application_services_params = params.permit(:id,
service: Projects::ServicesController::ALLOWED_PARAMS + dynamic_params)
if application_services_params[:service].is_a?(Hash)
Projects::ServicesController::FILTER_BLANK_PARAMS.each do |param|
application_services_params[:service].delete(param) if application_services_params[:service][param].blank?
end
end
application_services_params
end
end end
module ServiceParams
extend ActiveSupport::Concern
ALLOWED_PARAMS = [:title, :token, :type, :active, :api_key, :api_url, :api_version, :subdomain,
:room, :recipients, :project_url, :webhook,
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
:build_key, :server, :teamcity_url, :drone_url, :build_type,
:description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
:colorize_messages, :channels,
:push_events, :issues_events, :merge_requests_events, :tag_push_events,
:note_events, :build_events, :wiki_page_events,
:notify_only_broken_builds, :add_pusher,
:send_from_committer_email, :disable_diffs, :external_wiki_url,
:notify, :color,
:server_host, :server_port, :default_irc_uri, :enable_ssl_verification,
:jira_issue_transition_id]
# Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS = [:password]
def application_services_params
dynamic_params = []
dynamic_params.concat(@service.event_channel_names)
application_services_params = params.permit(:id, service: ALLOWED_PARAMS + dynamic_params)
if application_services_params[:service].is_a?(Hash)
FILTER_BLANK_PARAMS.each do |param|
application_services_params[:service].delete(param) if application_services_params[:service][param].blank?
end
end
application_services_params
end
end
class Projects::ServicesController < Projects::ApplicationController class Projects::ServicesController < Projects::ApplicationController
ALLOWED_PARAMS = [:title, :token, :type, :active, :api_key, :api_url, :api_version, :subdomain, include ServiceParams
:room, :recipients, :project_url, :webhook,
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
:build_key, :server, :teamcity_url, :drone_url, :build_type,
:description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
:colorize_messages, :channels,
:push_events, :issues_events, :merge_requests_events, :tag_push_events,
:note_events, :build_events, :wiki_page_events,
:notify_only_broken_builds, :add_pusher,
:send_from_committer_email, :disable_diffs, :external_wiki_url,
:notify, :color,
:server_host, :server_port, :default_irc_uri, :enable_ssl_verification,
:jira_issue_transition_id]
# Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS = [:password]
# Authorize # Authorize
before_action :authorize_admin_project! before_action :authorize_admin_project!
......
...@@ -2,7 +2,7 @@ module ServicesHelper ...@@ -2,7 +2,7 @@ module ServicesHelper
def service_event_description(event) def service_event_description(event)
case event case event
when "push" when "push"
"Webhook will triggered by a push to the repository" "Webhook will be triggered by a push to the repository"
when "tag_push" when "tag_push"
"Webhook will be triggered when a new tag is pushed to the repository" "Webhook will be triggered when a new tag is pushed to the repository"
when "note" when "note"
...@@ -19,7 +19,7 @@ module ServicesHelper ...@@ -19,7 +19,7 @@ module ServicesHelper
end end
def service_event_field_name(event) def service_event_field_name(event)
event = event.pluralize if %w(merge_request issue).include?(event) event = event.pluralize if %w[merge_request issue].include?(event)
"#{event}_events" "#{event}_events"
end end
end end
...@@ -5,7 +5,7 @@ class SlackService < Service ...@@ -5,7 +5,7 @@ class SlackService < Service
def initialize_properties def initialize_properties
# Custom serialized properties initialization # Custom serialized properties initialization
self.supported_events.each { |event| self.class.prop_accessor event_channel_name(event) } self.supported_events.each { |event| self.class.prop_accessor(event_channel_name(event)) }
if properties.nil? if properties.nil?
self.properties = {} self.properties = {}
...@@ -36,7 +36,7 @@ class SlackService < Service ...@@ -36,7 +36,7 @@ class SlackService < Service
[ [
{ type: 'text', name: 'webhook', placeholder: 'https://hooks.slack.com/services/...' }, { type: 'text', name: 'webhook', placeholder: 'https://hooks.slack.com/services/...' },
{ type: 'text', name: 'username', placeholder: 'username' }, { type: 'text', name: 'username', placeholder: 'username' },
{ type: 'text', name: 'channel', placeholder: "#General" }, { type: 'text', name: 'channel', placeholder: "#general" },
{ type: 'checkbox', name: 'notify_only_broken_builds' }, { type: 'checkbox', name: 'notify_only_broken_builds' },
] ]
...@@ -99,18 +99,13 @@ class SlackService < Service ...@@ -99,18 +99,13 @@ class SlackService < Service
def get_channel_field(event) def get_channel_field(event)
field_name = event_channel_name(event) field_name = event_channel_name(event)
self.send(field_name) self.public_send(field_name)
end end
def build_event_channels def build_event_channels
channels = [] supported_events.reduce([]) do |channels, event|
channels << { type: 'text', name: event_channel_name(event), placeholder: "#general" }
supported_events.each do |event|
channel_name = event_channel_name(event)
channels << { type: 'text', name: channel_name, placeholder: "#General" }
end end
channels
end end
def event_channel_name(event) def event_channel_name(event)
......
...@@ -80,6 +80,10 @@ class Service < ActiveRecord::Base ...@@ -80,6 +80,10 @@ class Service < ActiveRecord::Base
Gitlab::PushDataBuilder.build_sample(project, user) Gitlab::PushDataBuilder.build_sample(project, user)
end end
def event_channel_names
[]
end
def supported_events def supported_events
%w(push tag_push issue merge_request wiki_page) %w(push tag_push issue merge_request wiki_page)
end end
......
...@@ -26,12 +26,11 @@ After Slack is ready we need to setup GitLab. Here are the steps to achieve this ...@@ -26,12 +26,11 @@ After Slack is ready we need to setup GitLab. Here are the steps to achieve this
1. Navigate to Settings -> Services -> Slack 1. Navigate to Settings -> Services -> Slack
1. Pick the triggers you want to activate 1. Pick the triggers you want to activate and respective channel(#general by default).
1. Fill in your Slack details 1. Fill in your Slack details
- Webhook: Paste the Webhook URL from the step above - Webhook: Paste the Webhook URL from the step above
- Username: Fill this in if you want to change the username of the bot - Username: Fill this in if you want to change the username of the bot
- Channel: Fill this in if you want to change the channel where the messages will be posted
- Mark it as active - Mark it as active
1. Save your settings 1. Save your settings
......
...@@ -45,7 +45,7 @@ further configuration instructions and details. Contributions are welcome. ...@@ -45,7 +45,7 @@ further configuration instructions and details. Contributions are welcome.
| PivotalTracker | Project Management Software (Source Commits Endpoint) | | PivotalTracker | Project Management Software (Source Commits Endpoint) |
| Pushover | Pushover makes it easy to get real-time notifications on your Android device, iPhone, iPad, and Desktop | | Pushover | Pushover makes it easy to get real-time notifications on your Android device, iPhone, iPad, and Desktop |
| [Redmine](redmine.md) | Redmine issue tracker | | [Redmine](redmine.md) | Redmine issue tracker |
| Slack | A team communication tool for the 21st century | | [Slack](slack.md) | A team communication tool for the 21st century |
## Services Templates ## Services Templates
......
# Slack Service
Go to your project's **Settings > Services > Slack** and you will see a checkbox with the following events that can be triggered:
* Push
* Issue
* Merge request
* Note
* Tag push
* Build
* Wiki page
Bellow each of these event checkboxes you will have a input to insert which Slack channel do you want to send that event message,
#general channel is default.
![Slack configuration](img/slack_configuration.png)
| Field | Description |
| ----- | ----------- |
| `Webhook` | The incoming webhook url which you have to setup on slack. (https://my.slack.com/services/new/incoming-webhook/) |
| `Username` | Optional username which can be on messages sent to slack. |
| `notify only broken builds` | Notify only about broken builds, when build events are marked to be sent.|
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