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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
70004f4e
Commit
70004f4e
authored
Oct 06, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'slack_integration' into 'master'
Slack integration See merge request !1151
parents
0fed1b58
eceef546
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
28 deletions
+57
-28
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
-11
db/migrate/20141006143943_move_slack_service_to_webhook.rb
db/migrate/20141006143943_move_slack_service_to_webhook.rb
+17
-0
db/schema.rb
db/schema.rb
+1
-1
features/steps/project/services.rb
features/steps/project/services.rb
+2
-6
spec/models/slack_service_spec.rb
spec/models/slack_service_spec.rb
+25
-9
No files found.
CHANGELOG
View file @
70004f4e
...
@@ -12,6 +12,7 @@ v 7.4.0
...
@@ -12,6 +12,7 @@ v 7.4.0
- API: Add support for forking a project via the API (Bernhard Kaindl)
- API: Add support for forking a project via the API (Bernhard Kaindl)
- API: filter project issues by milestone (Julien Bianchi)
- API: filter project issues by milestone (Julien Bianchi)
- Fail harder in the backup script
- Fail harder in the backup script
- Changes to Slack service structure, only webhook url needed
- Zen mode for wiki and milestones (Robert Schilling)
- Zen mode for wiki and milestones (Robert Schilling)
- Move Emoji parsing to html-pipeline-gitlab (Robert Schilling)
- Move Emoji parsing to html-pipeline-gitlab (Robert Schilling)
- Font Awesome 4.2 integration (Sullivan Senechal)
- Font Awesome 4.2 integration (Sullivan Senechal)
...
...
app/controllers/projects/services_controller.rb
View file @
70004f4e
...
@@ -40,7 +40,7 @@ class Projects::ServicesController < Projects::ApplicationController
...
@@ -40,7 +40,7 @@ class Projects::ServicesController < Projects::ApplicationController
def
service_params
def
service_params
params
.
require
(
:service
).
permit
(
params
.
require
(
:service
).
permit
(
:title
,
:token
,
:type
,
:active
,
:api_key
,
:subdomain
,
:title
,
:token
,
:type
,
:active
,
:api_key
,
:subdomain
,
:room
,
:recipients
,
:project_url
,
:room
,
:recipients
,
:project_url
,
:webhook
,
:user_key
,
:device
,
:priority
,
:sound
:user_key
,
:device
,
:priority
,
:sound
)
)
end
end
...
...
app/models/project_services/slack_service.rb
View file @
70004f4e
...
@@ -13,10 +13,8 @@
...
@@ -13,10 +13,8 @@
#
#
class
SlackService
<
Service
class
SlackService
<
Service
prop_accessor
:room
,
:subdomain
,
:token
prop_accessor
:webhook
validates
:room
,
presence:
true
,
if: :activated?
validates
:webhook
,
presence:
true
,
if: :activated?
validates
:subdomain
,
presence:
true
,
if: :activated?
validates
:token
,
presence:
true
,
if: :activated?
def
title
def
title
'Slack'
'Slack'
...
@@ -32,9 +30,7 @@ class SlackService < Service
...
@@ -32,9 +30,7 @@ class SlackService < Service
def
fields
def
fields
[
[
{
type:
'text'
,
name:
'subdomain'
,
placeholder:
''
},
{
type:
'text'
,
name:
'webhook'
,
placeholder:
''
}
{
type:
'text'
,
name:
'token'
,
placeholder:
''
},
{
type:
'text'
,
name:
'room'
,
placeholder:
'Ex. #general'
},
]
]
end
end
...
@@ -44,11 +40,14 @@ class SlackService < Service
...
@@ -44,11 +40,14 @@ class SlackService < Service
project_name:
project_name
project_name:
project_name
))
))
credentials
=
webhook
.
match
(
/(\w*).slack.com.*services\/(.*)/
)
if
credentials
.
present?
subdomain
=
credentials
[
1
]
token
=
credentials
[
2
].
split
(
"token="
).
last
notifier
=
Slack
::
Notifier
.
new
(
subdomain
,
token
)
notifier
=
Slack
::
Notifier
.
new
(
subdomain
,
token
)
notifier
.
channel
=
room
notifier
.
username
=
'GitLab'
notifier
.
ping
(
message
.
pretext
,
attachments:
message
.
attachments
)
notifier
.
ping
(
message
.
pretext
,
attachments:
message
.
attachments
)
end
end
end
private
private
...
...
db/migrate/20141006143943_move_slack_service_to_webhook.rb
0 → 100644
View file @
70004f4e
class
MoveSlackServiceToWebhook
<
ActiveRecord
::
Migration
def
change
SlackService
.
all
.
each
do
|
slack_service
|
if
[
"token"
,
"subdomain"
].
all?
{
|
property
|
slack_service
.
properties
.
key?
property
}
token
=
slack_service
.
properties
[
'token'
]
subdomain
=
slack_service
.
properties
[
'subdomain'
]
webhook
=
"https://
#{
subdomain
}
.slack.com/services/hooks/incoming-webhook?token=
#{
token
}
"
slack_service
.
properties
[
'webhook'
]
=
webhook
slack_service
.
properties
.
delete
(
'token'
)
slack_service
.
properties
.
delete
(
'subdomain'
)
# Room is configured on the Slack side
slack_service
.
properties
.
delete
(
'room'
)
slack_service
.
save!
end
end
end
end
db/schema.rb
View file @
70004f4e
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2014
0914173417
)
do
ActiveRecord
::
Schema
.
define
(
version:
2014
1006143943
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
...
features/steps/project/services.rb
View file @
70004f4e
...
@@ -108,16 +108,12 @@ class Spinach::Features::ProjectServices < Spinach::FeatureSteps
...
@@ -108,16 +108,12 @@ class Spinach::Features::ProjectServices < Spinach::FeatureSteps
step
'I fill Slack settings'
do
step
'I fill Slack settings'
do
check
'Active'
check
'Active'
fill_in
'Subdomain'
,
with:
'gitlab'
fill_in
'Webhook'
,
with:
'https://gitlabhq.slack.com/services/hooks?token=cdIj4r4LfXUOySDUjp0tk3OI'
fill_in
'Room'
,
with:
'#gitlab'
fill_in
'Token'
,
with:
'verySecret'
click_button
'Save'
click_button
'Save'
end
end
step
'I should see Slack service settings saved'
do
step
'I should see Slack service settings saved'
do
find_field
(
'Subdomain'
).
value
.
should
==
'gitlab'
find_field
(
'Webhook'
).
value
.
should
==
'https://gitlabhq.slack.com/services/hooks?token=cdIj4r4LfXUOySDUjp0tk3OI'
find_field
(
'Room'
).
value
.
should
==
'#gitlab'
find_field
(
'Token'
).
value
.
should
==
'verySecret'
end
end
step
'I click Pushover service link'
do
step
'I click Pushover service link'
do
...
...
spec/models/slack_service_spec.rb
View file @
70004f4e
...
@@ -26,31 +26,28 @@ describe SlackService do
...
@@ -26,31 +26,28 @@ describe SlackService do
subject
.
active
=
true
subject
.
active
=
true
end
end
it
{
should
validate_presence_of
:room
}
it
{
should
validate_presence_of
:webhook
}
it
{
should
validate_presence_of
:subdomain
}
it
{
should
validate_presence_of
:token
}
end
end
end
end
describe
"Execute"
do
describe
"Execute"
do
let
(
:slack
)
{
SlackService
.
new
}
let
(
:slack
)
{
SlackService
.
new
}
let
(
:slack_service
)
{
SlackService
.
new
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:sample_data
)
{
GitPushService
.
new
.
sample_data
(
project
,
user
)
}
let
(
:sample_data
)
{
GitPushService
.
new
.
sample_data
(
project
,
user
)
}
let
(
:
subdomain
)
{
'gitlab
'
}
let
(
:
webhook
)
{
'https://gitlabhq.slack.com/services/hooks?token=cdIj4r4LfXUOySDUjp0tk3OI
'
}
let
(
:
token
)
{
'verySecret
'
}
let
(
:
new_webhook
)
{
'https://hooks.gitlabhq.slack.com/services/cdIj4r4LfXUOySDUjp0tk3OI
'
}
let
(
:api_url
)
{
let
(
:api_url
)
{
"https://
#{
subdomain
}
.slack.com/services/hooks/incoming-webhook?token=
#{
token
}
"
'https://gitlabhq.slack.com/services/hooks/incoming-webhook?token=cdIj4r4LfXUOySDUjp0tk3OI'
}
}
before
do
before
do
slack
.
stub
(
slack
.
stub
(
project:
project
,
project:
project
,
project_id:
project
.
id
,
project_id:
project
.
id
,
room:
'#gitlab'
,
service_hook:
true
,
service_hook:
true
,
subdomain:
subdomain
,
webhook:
webhook
token:
token
)
)
WebMock
.
stub_request
(
:post
,
api_url
)
WebMock
.
stub_request
(
:post
,
api_url
)
...
@@ -61,5 +58,24 @@ describe SlackService do
...
@@ -61,5 +58,24 @@ describe SlackService do
WebMock
.
should
have_requested
(
:post
,
api_url
).
once
WebMock
.
should
have_requested
(
:post
,
api_url
).
once
end
end
context
'with new webhook syntax'
do
before
do
slack_service
.
stub
(
project:
project
,
project_id:
project
.
id
,
service_hook:
true
,
webhook:
new_webhook
)
WebMock
.
stub_request
(
:post
,
api_url
)
end
it
"should call Slack API"
do
slack_service
.
execute
(
sample_data
)
WebMock
.
should
have_requested
(
:post
,
api_url
).
once
end
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