Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
323d796a
Commit
323d796a
authored
Jul 13, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor service settings view
parent
ede048b9
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
86 additions
and
138 deletions
+86
-138
app/controllers/admin/services_controller.rb
app/controllers/admin/services_controller.rb
+1
-1
app/controllers/concerns/service_params.rb
app/controllers/concerns/service_params.rb
+5
-5
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+1
-14
app/helpers/services_helper.rb
app/helpers/services_helper.rb
+7
-7
app/models/project_services/slack_service.rb
app/models/project_services/slack_service.rb
+8
-0
app/models/service.rb
app/models/service.rb
+8
-0
app/views/admin/services/_form.html.haml
app/views/admin/services/_form.html.haml
+1
-4
app/views/projects/services/_form.html.haml
app/views/projects/services/_form.html.haml
+1
-4
app/views/projects/services/slack/_service_settings.html.haml
...views/projects/services/slack/_service_settings.html.haml
+0
-34
app/views/shared/_service_settings.html.haml
app/views/shared/_service_settings.html.haml
+20
-61
doc/integration/slack.md
doc/integration/slack.md
+1
-1
doc/project_services/img/slack_configuration.png
doc/project_services/img/slack_configuration.png
+0
-0
doc/project_services/slack.md
doc/project_services/slack.md
+2
-2
spec/features/projects/slack_service/slack_service_spec.rb
spec/features/projects/slack_service/slack_service_spec.rb
+26
-0
spec/models/project_services/slack_service_spec.rb
spec/models/project_services/slack_service_spec.rb
+5
-5
No files found.
app/controllers/admin/services_controller.rb
View file @
323d796a
...
@@ -15,7 +15,7 @@ class Admin::ServicesController < Admin::ApplicationController
...
@@ -15,7 +15,7 @@ class Admin::ServicesController < Admin::ApplicationController
end
end
def
update
def
update
if
service
.
update_attributes
(
application_services
_params
[
:service
])
if
service
.
update_attributes
(
service
_params
[
:service
])
redirect_to
admin_application_settings_services_path
,
redirect_to
admin_application_settings_services_path
,
notice:
'Application settings saved successfully'
notice:
'Application settings saved successfully'
else
else
...
...
app/controllers/concerns/service_params.rb
View file @
323d796a
...
@@ -18,18 +18,18 @@ module ServiceParams
...
@@ -18,18 +18,18 @@ module ServiceParams
# Parameters to ignore if no value is specified
# Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS
=
[
:password
]
FILTER_BLANK_PARAMS
=
[
:password
]
def
application_services
_params
def
service
_params
dynamic_params
=
[]
dynamic_params
=
[]
dynamic_params
.
concat
(
@service
.
event_channel_names
)
dynamic_params
.
concat
(
@service
.
event_channel_names
)
application_services
_params
=
params
.
permit
(
:id
,
service:
ALLOWED_PARAMS
+
dynamic_params
)
service
_params
=
params
.
permit
(
:id
,
service:
ALLOWED_PARAMS
+
dynamic_params
)
if
application_services
_params
[
:service
].
is_a?
(
Hash
)
if
service
_params
[
:service
].
is_a?
(
Hash
)
FILTER_BLANK_PARAMS
.
each
do
|
param
|
FILTER_BLANK_PARAMS
.
each
do
|
param
|
application_services_params
[
:service
].
delete
(
param
)
if
application_services
_params
[
:service
][
param
].
blank?
service_params
[
:service
].
delete
(
param
)
if
service
_params
[
:service
][
param
].
blank?
end
end
end
end
application_services
_params
service
_params
end
end
end
end
app/controllers/projects/services_controller.rb
View file @
323d796a
...
@@ -18,7 +18,7 @@ class Projects::ServicesController < Projects::ApplicationController
...
@@ -18,7 +18,7 @@ class Projects::ServicesController < Projects::ApplicationController
end
end
def
update
def
update
if
@service
.
update_attributes
(
service_params
)
if
@service
.
update_attributes
(
service_params
[
:service
]
)
redirect_to
(
redirect_to
(
edit_namespace_project_service_path
(
@project
.
namespace
,
@project
,
edit_namespace_project_service_path
(
@project
.
namespace
,
@project
,
@service
.
to_param
,
notice:
@service
.
to_param
,
notice:
...
@@ -49,17 +49,4 @@ class Projects::ServicesController < Projects::ApplicationController
...
@@ -49,17 +49,4 @@ class Projects::ServicesController < Projects::ApplicationController
def
service
def
service
@service
||=
@project
.
services
.
find
{
|
service
|
service
.
to_param
==
params
[
:id
]
}
@service
||=
@project
.
services
.
find
{
|
service
|
service
.
to_param
==
params
[
:id
]
}
end
end
def
service_params
dynamic_params
=
[]
dynamic_params
.
concat
(
@service
.
event_channel_names
)
if
@service
.
is_a?
(
SlackService
)
service_params
=
params
.
require
(
:service
).
permit
(
ALLOWED_PARAMS
+
dynamic_params
)
FILTER_BLANK_PARAMS
.
each
do
|
param
|
service_params
.
delete
(
param
)
if
service_params
[
param
].
blank?
end
service_params
end
end
end
app/helpers/services_helper.rb
View file @
323d796a
...
@@ -2,19 +2,19 @@ module ServicesHelper
...
@@ -2,19 +2,19 @@ module ServicesHelper
def
service_event_description
(
event
)
def
service_event_description
(
event
)
case
event
case
event
when
"push"
when
"push"
"
Webhook
will be triggered by a push to the repository"
"
Event
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"
"
Event
will be triggered when a new tag is pushed to the repository"
when
"note"
when
"note"
"
Webhook
will be triggered when someone adds a comment"
"
Event
will be triggered when someone adds a comment"
when
"issue"
when
"issue"
"
Webhook
will be triggered when an issue is created/updated/merged"
"
Event
will be triggered when an issue is created/updated/merged"
when
"merge_request"
when
"merge_request"
"
Webhook
will be triggered when a merge request is created/updated/merged"
"
Event
will be triggered when a merge request is created/updated/merged"
when
"build"
when
"build"
"
Webhook
will be triggered when a build status changes"
"
Event
will be triggered when a build status changes"
when
"wiki_page"
when
"wiki_page"
"
Webhook
will be triggered when a wiki page is created/updated"
"
Event
will be triggered when a wiki page is created/updated"
end
end
end
end
...
...
app/models/project_services/slack_service.rb
View file @
323d796a
...
@@ -95,6 +95,14 @@ class SlackService < Service
...
@@ -95,6 +95,14 @@ class SlackService < Service
supported_events
.
map
{
|
event
|
event_channel_name
(
event
)
}
supported_events
.
map
{
|
event
|
event_channel_name
(
event
)
}
end
end
def
event_field
(
event
)
fields
.
find
{
|
field
|
field
[
:name
]
==
event_channel_name
(
event
)
}
end
def
global_fields
fields
.
reject
{
|
field
|
field
[
:name
].
end_with?
(
'channel'
)
}
end
private
private
def
get_channel_field
(
event
)
def
get_channel_field
(
event
)
...
...
app/models/service.rb
View file @
323d796a
...
@@ -84,6 +84,14 @@ class Service < ActiveRecord::Base
...
@@ -84,6 +84,14 @@ class Service < ActiveRecord::Base
[]
[]
end
end
def
event_field
(
event
)
nil
end
def
global_fields
fields
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
...
...
app/views/admin/services/_form.html.haml
View file @
323d796a
...
@@ -4,9 +4,6 @@
...
@@ -4,9 +4,6 @@
%p
#{
@service
.
description
}
template
%p
#{
@service
.
description
}
template
=
form_for
:service
,
url:
admin_application_settings_service_path
,
method: :put
,
html:
{
class:
'form-horizontal fieldset-form'
}
do
|
form
|
=
form_for
:service
,
url:
admin_application_settings_service_path
,
method: :put
,
html:
{
class:
'form-horizontal fieldset-form'
}
do
|
form
|
-
if
@service
.
is_a?
(
SlackService
)
=
render
'projects/services/slack/service_settings'
,
form:
form
-
else
=
render
'shared/service_settings'
,
form:
form
=
render
'shared/service_settings'
,
form:
form
.form-actions
.form-actions
...
...
app/views/projects/services/_form.html.haml
View file @
323d796a
...
@@ -7,9 +7,6 @@
...
@@ -7,9 +7,6 @@
%p
=
@service
.
description
%p
=
@service
.
description
.col-lg-9
.col-lg-9
=
form_for
(
@service
,
as: :service
,
url:
namespace_project_service_path
(
@project
.
namespace
,
@project
,
@service
.
to_param
),
method: :put
,
html:
{
class:
'form-horizontal'
})
do
|
form
|
=
form_for
(
@service
,
as: :service
,
url:
namespace_project_service_path
(
@project
.
namespace
,
@project
,
@service
.
to_param
),
method: :put
,
html:
{
class:
'form-horizontal'
})
do
|
form
|
-
if
@service
.
is_a?
(
SlackService
)
=
render
'projects/services/slack/service_settings'
,
form:
form
-
else
=
render
'shared/service_settings'
,
form:
form
=
render
'shared/service_settings'
,
form:
form
=
form
.
submit
'Save changes'
,
class:
'btn btn-save'
=
form
.
submit
'Save changes'
,
class:
'btn btn-save'
...
...
app/views/projects/services/slack/_service_settings.html.haml
deleted
100644 → 0
View file @
ede048b9
=
form_errors
(
@service
)
-
if
@service
.
help
.
present?
.well
=
preserve
do
=
markdown
@service
.
help
.form-group
=
form
.
label
:active
,
"Active"
,
class:
"control-label"
.col-sm-10
=
form
.
check_box
:active
.form-group
=
form
.
label
:url
,
"Trigger"
,
class:
'control-label'
.col-sm-10
-
@service
.
supported_events
.
each
do
|
event
|
%div
=
form
.
check_box
service_event_field_name
(
event
),
class:
'pull-left'
.prepend-left-20
=
form
.
label
service_event_field_name
(
event
),
class:
'list-label'
do
%strong
=
event
.
humanize
%p
-
field
=
@service
.
fields
.
select
{
|
field
|
field
[
:name
]
==
"
#{
event
}
_channel"
}.
first
=
form
.
text_field
field
[
:name
],
class:
"form-control"
,
placeholder:
field
[
:placeholder
]
%p
.light
=
service_event_description
(
event
)
-
@service
.
fields
.
each
do
|
field
|
-
if
%w(webhook username notify_only_broken_builds)
.
include?
(
field
[
:name
])
=
render
'shared/field'
,
form:
form
,
field:
field
app/views/shared/_service_settings.html.haml
View file @
323d796a
...
@@ -10,69 +10,28 @@
...
@@ -10,69 +10,28 @@
.col-sm-10
.col-sm-10
=
form
.
check_box
:active
=
form
.
check_box
:active
-
if
@service
.
supported_events
.
length
>
1
.form-group
.form-group
=
form
.
label
:url
,
"Trigger"
,
class:
'control-label'
=
form
.
label
:url
,
"Trigger"
,
class:
'control-label'
.col-sm-10
.col-sm-10
-
if
@service
.
supported_events
.
include?
(
"push"
)
-
@service
.
supported_events
.
each
do
|
event
|
%div
=
form
.
check_box
:push_events
,
class:
'pull-left'
.prepend-left-20
=
form
.
label
:push_events
,
class:
'list-label'
do
%strong
Push events
%p
.light
This url will be triggered by a push to the repository
-
if
@service
.
supported_events
.
include?
(
"tag_push"
)
%div
=
form
.
check_box
:tag_push_events
,
class:
'pull-left'
.prepend-left-20
=
form
.
label
:tag_push_events
,
class:
'list-label'
do
%strong
Tag push events
%p
.light
This url will be triggered when a new tag is pushed to the repository
-
if
@service
.
supported_events
.
include?
(
"note"
)
%div
=
form
.
check_box
:note_events
,
class:
'pull-left'
.prepend-left-20
=
form
.
label
:note_events
,
class:
'list-label'
do
%strong
Comments
%p
.light
This url will be triggered when someone adds a comment
-
if
@service
.
supported_events
.
include?
(
"issue"
)
%div
=
form
.
check_box
:issues_events
,
class:
'pull-left'
.prepend-left-20
=
form
.
label
:issues_events
,
class:
'list-label'
do
%strong
Issues events
%p
.light
This url will be triggered when an issue is created/updated/merged
-
if
@service
.
supported_events
.
include?
(
"merge_request"
)
%div
=
form
.
check_box
:merge_requests_events
,
class:
'pull-left'
.prepend-left-20
=
form
.
label
:merge_requests_events
,
class:
'list-label'
do
%strong
Merge Request events
%p
.light
This url will be triggered when a merge request is created/updated/merged
-
if
@service
.
supported_events
.
include?
(
"build"
)
%div
=
form
.
check_box
:build_events
,
class:
'pull-left'
.prepend-left-20
=
form
.
label
:build_events
,
class:
'list-label'
do
%strong
Build events
%p
.light
This url will be triggered when a build status changes
-
if
@service
.
supported_events
.
include?
(
"wiki_page"
)
%div
%div
=
form
.
check_box
:wiki_page_events
,
class:
'pull-left'
=
form
.
check_box
service_event_field_name
(
event
)
,
class:
'pull-left'
.prepend-left-20
.prepend-left-20
=
form
.
label
:wiki_page_events
,
class:
'list-label'
do
=
form
.
label
service_event_field_name
(
event
),
class:
'list-label'
do
%strong
Wiki Page events
%strong
%p
.light
=
event
.
humanize
This url will be triggered when a wiki page is created/updated
-
field
=
@service
.
event_field
(
event
)
-
if
field
%p
=
form
.
text_field
field
[
:name
],
class:
"form-control"
,
placeholder:
field
[
:placeholder
]
%p
.light
=
service_event_description
(
event
)
-
@service
.
fields
.
each
do
|
field
|
-
@service
.
global_
fields
.
each
do
|
field
|
-
type
=
field
[
:type
]
-
type
=
field
[
:type
]
-
if
type
==
'fieldset'
-
if
type
==
'fieldset'
...
...
doc/integration/slack.md
View file @
323d796a
...
@@ -26,7 +26,7 @@ After Slack is ready we need to setup GitLab. Here are the steps to achieve this
...
@@ -26,7 +26,7 @@ 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 and respective channel
(#general
by default).
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
...
...
doc/project_services/img/slack_configuration.png
View replaced file @
ede048b9
View file @
323d796a
65.8 KB
|
W:
|
H:
70.4 KB
|
W:
|
H:
2-up
Swipe
Onion skin
doc/project_services/slack.md
View file @
323d796a
...
@@ -10,8 +10,8 @@ Go to your project's **Settings > Services > Slack** and you will see a checkbox
...
@@ -10,8 +10,8 @@ Go to your project's **Settings > Services > Slack** and you will see a checkbox
*
Build
*
Build
*
Wiki page
*
Wiki page
Bel
low each of these event checkboxes you will have a
input to insert which Slack channel do you want to send that event message,
Bel
ow each of these event checkboxes you will have an
input to insert which Slack channel do you want to send that event message,
#general
channel is default.
`#general`
channel is default.
![
Slack configuration
](
img/slack_configuration.png
)
![
Slack configuration
](
img/slack_configuration.png
)
...
...
spec/features/projects/slack_service/slack_service_spec.rb
0 → 100644
View file @
323d796a
require
'spec_helper'
feature
'Projects > Slack service > Setup events'
,
feature:
true
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
{
SlackService
.
new
}
let
(
:project
)
{
create
(
:project
,
slack_service:
service
)
}
background
do
service
.
fields
service
.
update_attributes
(
push_channel:
1
,
issue_channel:
2
,
merge_request_channel:
3
,
note_channel:
4
,
tag_push_channel:
5
,
build_channel:
6
,
wiki_page_channel:
7
)
project
.
team
<<
[
user
,
:master
]
login_as
(
user
)
end
scenario
'user can filter events by channel'
do
visit
edit_namespace_project_service_path
(
project
.
namespace
,
project
,
service
)
expect
(
page
.
find_field
(
"service_push_channel"
).
value
).
to
have_content
'1'
expect
(
page
.
find_field
(
"service_issue_channel"
).
value
).
to
have_content
'2'
expect
(
page
.
find_field
(
"service_merge_request_channel"
).
value
).
to
have_content
'3'
expect
(
page
.
find_field
(
"service_note_channel"
).
value
).
to
have_content
'4'
expect
(
page
.
find_field
(
"service_tag_push_channel"
).
value
).
to
have_content
'5'
expect
(
page
.
find_field
(
"service_build_channel"
).
value
).
to
have_content
'6'
expect
(
page
.
find_field
(
"service_wiki_page_channel"
).
value
).
to
have_content
'7'
end
end
spec/models/project_services/slack_service_spec.rb
View file @
323d796a
...
@@ -139,7 +139,7 @@ describe SlackService, models: true do
...
@@ -139,7 +139,7 @@ describe SlackService, models: true do
end
end
context
"event channels"
do
context
"event channels"
do
it
"
should user
the right channel for push event"
do
it
"
uses
the right channel for push event"
do
slack
.
update_attributes
(
push_channel:
"random"
)
slack
.
update_attributes
(
push_channel:
"random"
)
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
...
@@ -151,7 +151,7 @@ describe SlackService, models: true do
...
@@ -151,7 +151,7 @@ describe SlackService, models: true do
slack
.
execute
(
push_sample_data
)
slack
.
execute
(
push_sample_data
)
end
end
it
"
should use
the right channel for merge request event"
do
it
"
uses
the right channel for merge request event"
do
slack
.
update_attributes
(
merge_request_channel:
"random"
)
slack
.
update_attributes
(
merge_request_channel:
"random"
)
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
...
@@ -163,7 +163,7 @@ describe SlackService, models: true do
...
@@ -163,7 +163,7 @@ describe SlackService, models: true do
slack
.
execute
(
@merge_sample_data
)
slack
.
execute
(
@merge_sample_data
)
end
end
it
"
should use
the right channel for issue event"
do
it
"
uses
the right channel for issue event"
do
slack
.
update_attributes
(
issue_channel:
"random"
)
slack
.
update_attributes
(
issue_channel:
"random"
)
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
...
@@ -175,7 +175,7 @@ describe SlackService, models: true do
...
@@ -175,7 +175,7 @@ describe SlackService, models: true do
slack
.
execute
(
@issues_sample_data
)
slack
.
execute
(
@issues_sample_data
)
end
end
it
"
should use
the right channel for wiki event"
do
it
"
uses
the right channel for wiki event"
do
slack
.
update_attributes
(
wiki_page_channel:
"random"
)
slack
.
update_attributes
(
wiki_page_channel:
"random"
)
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
...
@@ -192,7 +192,7 @@ describe SlackService, models: true do
...
@@ -192,7 +192,7 @@ describe SlackService, models: true do
create
(
:note_on_issue
,
project:
project
,
note:
"issue note"
)
create
(
:note_on_issue
,
project:
project
,
note:
"issue note"
)
end
end
it
"
should use
the right channel"
do
it
"
uses
the right channel"
do
slack
.
update_attributes
(
note_channel:
"random"
)
slack
.
update_attributes
(
note_channel:
"random"
)
note_data
=
Gitlab
::
NoteDataBuilder
.
build
(
issue_note
,
user
)
note_data
=
Gitlab
::
NoteDataBuilder
.
build
(
issue_note
,
user
)
...
...
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