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
Jérome Perrin
gitlab-ce
Commits
d2c85a68
Commit
d2c85a68
authored
Dec 28, 2014
by
Andrès Koetsier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow a user to specify a channel and username for the slack-webhook
parent
82a9a4c0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
4 deletions
+34
-4
CHANGELOG
CHANGELOG
+1
-0
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+1
-1
app/models/project_services/slack_service.rb
app/models/project_services/slack_service.rb
+10
-3
spec/models/project_services/slack_service_spec.rb
spec/models/project_services/slack_service_spec.rb
+22
-0
No files found.
CHANGELOG
View file @
d2c85a68
...
@@ -88,6 +88,7 @@ v 7.8.0
...
@@ -88,6 +88,7 @@ v 7.8.0
- Improve database performance for GitLab
- Improve database performance for GitLab
- Add Asana service (Jeremy Benoist)
- Add Asana service (Jeremy Benoist)
- Improve project web hooks with extra data
- Improve project web hooks with extra data
- Slack username and channel options
v 7.7.2
v 7.7.2
- Update GitLab Shell to version 2.4.2 that fixes a bug when developers can push to protected branch
- Update GitLab Shell to version 2.4.2 that fixes a bug when developers can push to protected branch
...
...
app/controllers/projects/services_controller.rb
View file @
d2c85a68
...
@@ -50,7 +50,7 @@ class Projects::ServicesController < Projects::ApplicationController
...
@@ -50,7 +50,7 @@ class Projects::ServicesController < Projects::ApplicationController
:room
,
:recipients
,
:project_url
,
:webhook
,
:room
,
:recipients
,
:project_url
,
:webhook
,
:user_key
,
:device
,
:priority
,
:sound
,
:bamboo_url
,
:username
,
:password
,
:user_key
,
:device
,
:priority
,
:sound
,
:bamboo_url
,
:username
,
:password
,
:build_key
,
:server
,
:teamcity_url
,
:build_type
,
:build_key
,
:server
,
:teamcity_url
,
:build_type
,
:description
,
:issues_url
,
:new_issue_url
,
:restrict_to_branch
:description
,
:issues_url
,
:new_issue_url
,
:restrict_to_branch
,
:channel
)
)
end
end
end
end
app/models/project_services/slack_service.rb
View file @
d2c85a68
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
#
#
class
SlackService
<
Service
class
SlackService
<
Service
prop_accessor
:webhook
prop_accessor
:webhook
,
:username
,
:channel
validates
:webhook
,
presence:
true
,
if: :activated?
validates
:webhook
,
presence:
true
,
if: :activated?
def
title
def
title
...
@@ -31,7 +31,10 @@ class SlackService < Service
...
@@ -31,7 +31,10 @@ class SlackService < Service
def
fields
def
fields
[
[
{
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:
'channel'
,
placeholder:
'#channel'
}
]
]
end
end
...
@@ -43,7 +46,11 @@ class SlackService < Service
...
@@ -43,7 +46,11 @@ class SlackService < Service
project_name:
project_name
project_name:
project_name
))
))
notifier
=
Slack
::
Notifier
.
new
(
webhook
)
opt
=
{}
opt
[
:channel
]
=
channel
if
channel
opt
[
:username
]
=
username
if
username
notifier
=
Slack
::
Notifier
.
new
(
webhook
,
opt
)
notifier
.
ping
(
message
.
pretext
,
attachments:
message
.
attachments
)
notifier
.
ping
(
message
.
pretext
,
attachments:
message
.
attachments
)
end
end
...
...
spec/models/project_services/slack_service_spec.rb
View file @
d2c85a68
...
@@ -36,6 +36,8 @@ describe SlackService do
...
@@ -36,6 +36,8 @@ describe SlackService do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:sample_data
)
{
Gitlab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
}
let
(
:sample_data
)
{
Gitlab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
}
let
(
:webhook_url
)
{
'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685'
}
let
(
:webhook_url
)
{
'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685'
}
let
(
:username
)
{
'slack_username'
}
let
(
:channel
)
{
'slack_channel'
}
before
do
before
do
slack
.
stub
(
slack
.
stub
(
...
@@ -53,5 +55,25 @@ describe SlackService do
...
@@ -53,5 +55,25 @@ describe SlackService do
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
it
'should use the username as an option for slack when configured'
do
slack
.
stub
(
username:
username
)
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
with
(
webhook_url
,
username:
username
).
and_return
(
double
(
:slack_service
).
as_null_object
)
slack
.
execute
(
sample_data
)
end
it
'should use the channel as an option when it is configured'
do
slack
.
stub
(
channel:
channel
)
expect
(
Slack
::
Notifier
).
to
receive
(
:new
).
with
(
webhook_url
,
channel:
channel
).
and_return
(
double
(
:slack_service
).
as_null_object
)
slack
.
execute
(
sample_data
)
end
end
end
end
end
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