Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
5b3abe4c0676
Commit
ede048b9
authored
Jul 12, 2016
by
Felipe Artur
Browse files
Add project service documentation and update integration documentation
parent
5e4c47c2d2a3
Changes
10
Hide whitespace changes
Inline
Side-by-side
app/controllers/admin/services_controller.rb
View file @
5b3abe4c
class
Admin::ServicesController
<
Admin
::
ApplicationController
include
ServiceParams
before_action
:service
,
only:
[
:edit
,
:update
]
def
index
...
...
@@ -37,18 +39,4 @@ def services_templates
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
app/controllers/concerns/service_params.rb
0 → 100644
View file @
5b3abe4c
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
app/controllers/projects/services_controller.rb
View file @
5b3abe4c
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!
...
...
app/helpers/services_helper.rb
View file @
5b3abe4c
...
...
@@ -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 @@ def service_event_description(event)
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
app/models/project_services/slack_service.rb
View file @
5b3abe4c
...
...
@@ -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 @@ def fields
[
{
type:
'text'
,
name:
'webhook'
,
placeholder:
'https://hooks.slack.com/services/...'
},
{
type:
'text'
,
name:
'username'
,
placeholder:
'username'
},
{
type:
'text'
,
name:
'channel'
,
placeholder:
"#
G
eneral"
},
{
type:
'text'
,
name:
'channel'
,
placeholder:
"#
g
eneral"
},
{
type:
'checkbox'
,
name:
'notify_only_broken_builds'
},
]
...
...
@@ -99,18 +99,13 @@ def event_channel_names
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
)
...
...
app/models/service.rb
View file @
5b3abe4c
...
...
@@ -80,6 +80,10 @@ def test_data(project, user)
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
...
...
doc/integration/slack.md
View file @
5b3abe4c
...
...
@@ -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 :)
...
...
doc/project_services/img/slack_configuration.png
0 → 100644
View file @
5b3abe4c
65.8 KB
doc/project_services/project_services.md
View file @
5b3abe4c
...
...
@@ -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
...
...
doc/project_services/slack.md
0 → 100644
View file @
5b3abe4c
# 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.

| 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.|
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment