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
76295946
Commit
76295946
authored
Nov 06, 2018
by
blackst0ne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY specs, fix typos in docs
parent
a7439b4a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
45 deletions
+35
-45
app/models/project_services/discord_service.rb
app/models/project_services/discord_service.rb
+1
-1
doc/user/project/integrations/discord_notifications.md
doc/user/project/integrations/discord_notifications.md
+1
-1
spec/models/project_services/discord_service_spec.rb
spec/models/project_services/discord_service_spec.rb
+12
-20
spec/models/project_services/hangouts_chat_service_spec.rb
spec/models/project_services/hangouts_chat_service_spec.rb
+12
-23
spec/support/shared_examples/models/project_services_spec.rb
spec/support/shared_examples/models/project_services_spec.rb
+9
-0
No files found.
app/models/project_services/discord_service.rb
View file @
76295946
...
...
@@ -16,7 +16,7 @@ class DiscordService < ChatNotificationService
end
def
help
"This service sends notifications about project
s
events to Discord channels.<br />
"This service sends notifications about project events to Discord channels.<br />
To set up this service:
<ol>
<li><a href='https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks'>Setup a custom Incoming Webhook</a>.</li>
...
...
doc/user/project/integrations/discord_notifications.md
View file @
76295946
...
...
@@ -4,7 +4,7 @@
The Discord Notifications service sends event notifications from GitLab to the channel for which the webhook was created.
To send GitLab event notifications to a Discord channel, create a webhook in Disco
urse
and configure it in GitLab.
To send GitLab event notifications to a Discord channel, create a webhook in Disco
rd
and configure it in GitLab.
## Create webhook
...
...
spec/models/project_services/discord_service_spec.rb
View file @
76295946
...
...
@@ -43,20 +43,12 @@ describe DiscordService do
WebMock
.
stub_request
(
:post
,
webhook_url
)
end
shared_examples
"Discord service"
do
it
"calls Discord Webhooks API"
do
subject
.
execute
(
sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
with
{
|
req
|
req
.
body
=~
/\A{"content":.+}\Z/
}.
once
end
end
context
"with push events"
do
let
(
:sample_data
)
do
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
user
)
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
it
"specifies the webhook when it is configured"
do
expect
(
Discordrb
::
Webhooks
::
Client
).
to
receive
(
:new
).
with
(
url:
webhook_url
).
and_return
(
double
(
:discord_service
).
as_null_object
)
...
...
@@ -86,7 +78,7 @@ describe DiscordService do
subject
.
notify_only_default_branch
=
false
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
end
end
...
...
@@ -99,7 +91,7 @@ describe DiscordService do
service
.
hook_data
(
issue
,
"open"
)
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
context
"with merge events"
do
...
...
@@ -122,7 +114,7 @@ describe DiscordService do
project
.
add_developer
(
user
)
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
context
"with wiki page events"
do
...
...
@@ -137,7 +129,7 @@ describe DiscordService do
let
(
:wiki_page
)
{
create
(
:wiki_page
,
wiki:
project
.
wiki
,
attrs:
opts
)
}
let
(
:sample_data
)
{
Gitlab
::
DataBuilder
::
WikiPage
.
build
(
wiki_page
,
user
,
"create"
)
}
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
context
"with note events"
do
...
...
@@ -152,7 +144,7 @@ describe DiscordService do
note:
"a comment on a commit"
)
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
context
"with merge request comment"
do
...
...
@@ -160,7 +152,7 @@ describe DiscordService do
create
(
:note_on_merge_request
,
project:
project
,
note:
"merge request note"
)
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
context
"with issue comment"
do
...
...
@@ -168,7 +160,7 @@ describe DiscordService do
create
(
:note_on_issue
,
project:
project
,
note:
"issue note"
)
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
context
"with snippet comment"
do
...
...
@@ -176,7 +168,7 @@ describe DiscordService do
create
(
:note_on_project_snippet
,
project:
project
,
note:
"snippet note"
)
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
end
...
...
@@ -191,7 +183,7 @@ describe DiscordService do
context
"with failed pipeline"
do
let
(
:status
)
{
"failed"
}
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
context
"with succeeded pipeline"
do
...
...
@@ -210,7 +202,7 @@ describe DiscordService do
subject
.
notify_only_broken_pipelines
=
false
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
end
...
...
@@ -236,7 +228,7 @@ describe DiscordService do
subject
.
notify_only_default_branch
=
false
end
it_behaves_like
"
Discord service"
it_behaves_like
"
Interacts with external service"
,
"Discord"
,
content_key: :content
end
end
end
...
...
spec/models/project_services/hangouts_chat_service_spec.rb
View file @
76295946
...
...
@@ -41,23 +41,12 @@ describe HangoutsChatService do
WebMock
.
stub_request
(
:post
,
webhook_url
)
end
shared_examples
'Hangouts Chat service'
do
it
'calls Hangouts Chat API'
do
subject
.
execute
(
sample_data
)
expect
(
WebMock
)
.
to
have_requested
(
:post
,
webhook_url
)
.
with
{
|
req
|
req
.
body
=~
/\A{"text":.+}\Z/
}
.
once
end
end
context
'with push events'
do
let
(
:sample_data
)
do
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
user
)
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
it
'specifies the webhook when it is configured'
do
expect
(
HangoutsChat
::
Sender
).
to
receive
(
:new
).
with
(
webhook_url
).
and_return
(
double
(
:hangouts_chat_service
).
as_null_object
)
...
...
@@ -87,7 +76,7 @@ describe HangoutsChatService do
subject
.
notify_only_default_branch
=
false
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
end
end
...
...
@@ -100,7 +89,7 @@ describe HangoutsChatService do
service
.
hook_data
(
issue
,
'open'
)
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
context
'with merge events'
do
...
...
@@ -123,7 +112,7 @@ describe HangoutsChatService do
project
.
add_developer
(
user
)
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
context
'with wiki page events'
do
...
...
@@ -138,7 +127,7 @@ describe HangoutsChatService do
let
(
:wiki_page
)
{
create
(
:wiki_page
,
wiki:
project
.
wiki
,
attrs:
opts
)
}
let
(
:sample_data
)
{
Gitlab
::
DataBuilder
::
WikiPage
.
build
(
wiki_page
,
user
,
'create'
)
}
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
context
'with note events'
do
...
...
@@ -152,7 +141,7 @@ describe HangoutsChatService do
note:
'a comment on a commit'
)
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
context
'with merge request comment'
do
...
...
@@ -161,7 +150,7 @@ describe HangoutsChatService do
note:
'merge request note'
)
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
context
'with issue comment'
do
...
...
@@ -169,7 +158,7 @@ describe HangoutsChatService do
create
(
:note_on_issue
,
project:
project
,
note:
'issue note'
)
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
context
'with snippet comment'
do
...
...
@@ -178,7 +167,7 @@ describe HangoutsChatService do
note:
'snippet note'
)
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
end
...
...
@@ -193,7 +182,7 @@ describe HangoutsChatService do
context
'with failed pipeline'
do
let
(
:status
)
{
'failed'
}
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
context
'with succeeded pipeline'
do
...
...
@@ -212,7 +201,7 @@ describe HangoutsChatService do
subject
.
notify_only_broken_pipelines
=
false
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
end
...
...
@@ -238,7 +227,7 @@ describe HangoutsChatService do
subject
.
notify_only_default_branch
=
false
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
"Interacts with external service"
,
"Hangouts Chat"
,
content_key: :text
end
end
end
...
...
spec/support/shared_examples/models/project_services_spec.rb
0 → 100644
View file @
76295946
require
"spec_helper"
shared_examples_for
"Interacts with external service"
do
|
service_name
,
content_key
:|
it
"calls
#{
service_name
}
Webhooks API"
do
subject
.
execute
(
sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
with
{
|
req
|
req
.
body
=~
/\A{"
#{
content_key
}
":.+}\Z/
}.
once
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