Add project service documentation and update integration documentation

This commit is contained in:
Felipe Artur 2016-07-12 17:00:49 -03:00
parent 8bd520d70e
commit ede048b930
10 changed files with 78 additions and 46 deletions

View file

@ -1,4 +1,6 @@
class Admin::ServicesController < Admin::ApplicationController
include ServiceParams
before_action :service, only: [:edit, :update]
def index
@ -37,18 +39,4 @@ class Admin::ServicesController < Admin::ApplicationController
def service
@service ||= Service.where(id: params[:id], template: true).first
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

View file

@ -0,0 +1,35 @@
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

View file

@ -1,20 +1,5 @@
class Projects::ServicesController < Projects::ApplicationController
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]
include ServiceParams
# Authorize
before_action :authorize_admin_project!

View file

@ -2,7 +2,7 @@ module ServicesHelper
def service_event_description(event)
case event
when "push"
"Webhook will triggered by a push to the repository"
"Webhook will be triggered by a push to the repository"
when "tag_push"
"Webhook will be triggered when a new tag is pushed to the repository"
when "note"
@ -19,7 +19,7 @@ module ServicesHelper
end
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"
end
end

View file

@ -5,7 +5,7 @@ class SlackService < Service
def initialize_properties
# 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?
self.properties = {}
@ -36,7 +36,7 @@ class SlackService < Service
[
{ type: 'text', name: 'webhook', placeholder: 'https://hooks.slack.com/services/...' },
{ 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' },
]
@ -99,18 +99,13 @@ class SlackService < Service
def get_channel_field(event)
field_name = event_channel_name(event)
self.send(field_name)
self.public_send(field_name)
end
def build_event_channels
channels = []
supported_events.each do |event|
channel_name = event_channel_name(event)
channels << { type: 'text', name: channel_name, placeholder: "#General" }
supported_events.reduce([]) do |channels, event|
channels << { type: 'text', name: event_channel_name(event), placeholder: "#general" }
end
channels
end
def event_channel_name(event)

View file

@ -80,6 +80,10 @@ class Service < ActiveRecord::Base
Gitlab::PushDataBuilder.build_sample(project, user)
end
def event_channel_names
[]
end
def supported_events
%w(push tag_push issue merge_request wiki_page)
end

View file

@ -26,14 +26,13 @@ After Slack is ready we need to setup GitLab. Here are the steps to achieve this
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
- Webhook: Paste the Webhook URL from the step above
- 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
1. Save your settings
Have fun :)

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View file

@ -45,7 +45,7 @@ further configuration instructions and details. Contributions are welcome.
| 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 |
| [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

View file

@ -0,0 +1,26 @@
# 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.|