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
d64196dd
Commit
d64196dd
authored
Jul 14, 2018
by
Kukovskii Vladimir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix couple of moments in HangoutsChatService and its spec
parent
6cfb0a9e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
23 deletions
+29
-23
app/models/project_services/hangouts_chat_service.rb
app/models/project_services/hangouts_chat_service.rb
+7
-5
changelogs/unreleased/hangouts_chat_integration.yml
changelogs/unreleased/hangouts_chat_integration.yml
+1
-1
spec/models/project_services/hangouts_chat_service_spec.rb
spec/models/project_services/hangouts_chat_service_spec.rb
+21
-17
No files found.
app/models/project_services/hangouts_chat_service.rb
View file @
d64196dd
...
@@ -44,20 +44,22 @@ class HangoutsChatService < ChatNotificationService
...
@@ -44,20 +44,22 @@ class HangoutsChatService < ChatNotificationService
private
private
def
notify
(
message
,
opts
)
def
notify
(
message
,
opts
)
simple_text
=
compose_simple
_message
(
message
)
simple_text
=
parse_simple_text
_message
(
message
)
HangoutsChat
::
Sender
.
new
(
webhook
).
simple
(
simple_text
)
HangoutsChat
::
Sender
.
new
(
webhook
).
simple
(
simple_text
)
end
end
def
compose_simple
_message
(
message
)
def
parse_simple_text
_message
(
message
)
header
=
message
.
pretext
header
=
message
.
pretext
return
header
if
message
.
attachments
.
empty?
return
header
if
message
.
attachments
.
empty?
title
=
fetch_attachment_title
(
message
.
attachments
.
first
)
attachment
=
message
.
attachments
.
first
body
=
message
.
attachments
.
first
[
:text
]
title
=
format_attachment_title
(
attachment
)
body
=
attachment
[
:text
]
[
header
,
title
,
body
].
compact
.
join
(
"
\n
"
)
[
header
,
title
,
body
].
compact
.
join
(
"
\n
"
)
end
end
def
f
etch
_attachment_title
(
attachment
)
def
f
ormat
_attachment_title
(
attachment
)
return
attachment
[
:title
]
unless
attachment
[
:title_link
]
return
attachment
[
:title
]
unless
attachment
[
:title_link
]
"<
#{
attachment
[
:title_link
]
}
|
#{
attachment
[
:title
]
}
>"
"<
#{
attachment
[
:title_link
]
}
|
#{
attachment
[
:title
]
}
>"
...
...
changelogs/unreleased/hangouts_chat_integration.yml
View file @
d64196dd
---
---
title
:
Add Hangouts Chat integration
title
:
Add Hangouts Chat integration
merge_request
:
merge_request
:
20290
author
:
Kukovskii Vladimir
author
:
Kukovskii Vladimir
type
:
added
type
:
added
spec/models/project_services/hangouts_chat_service_spec.rb
View file @
d64196dd
require
'spec_helper'
require
'spec_helper'
describe
HangoutsChatService
do
describe
HangoutsChatService
do
let
(
:chat_service
)
{
described_class
.
new
}
let
(
:webhook_url
)
{
'https://example.gitlab.com/'
}
describe
'Associations'
do
describe
'Associations'
do
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
have_one
:service_hook
}
it
{
is_expected
.
to
have_one
:service_hook
}
...
@@ -31,9 +28,10 @@ describe HangoutsChatService do
...
@@ -31,9 +28,10 @@ describe HangoutsChatService do
describe
'#execute'
do
describe
'#execute'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:webhook_url
)
{
'https://example.gitlab.com/'
}
before
do
before
do
allow
(
chat_service
).
to
receive_messages
(
allow
(
subject
).
to
receive_messages
(
project:
project
,
project:
project
,
project_id:
project
.
id
,
project_id:
project
.
id
,
service_hook:
true
,
service_hook:
true
,
...
@@ -45,7 +43,7 @@ describe HangoutsChatService do
...
@@ -45,7 +43,7 @@ describe HangoutsChatService do
shared_examples
'Hangouts Chat service'
do
shared_examples
'Hangouts Chat service'
do
it
'calls Hangouts Chat API'
do
it
'calls Hangouts Chat API'
do
chat_service
.
execute
(
sample_data
)
subject
.
execute
(
sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
...
@@ -61,22 +59,28 @@ describe HangoutsChatService do
...
@@ -61,22 +59,28 @@ describe HangoutsChatService do
it
'specifies the webhook when it is configured'
do
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
)
expect
(
HangoutsChat
::
Sender
).
to
receive
(
:new
).
with
(
webhook_url
).
and_return
(
double
(
:hangouts_chat_service
).
as_null_object
)
chat_service
.
execute
(
sample_data
)
subject
.
execute
(
sample_data
)
end
it
'sends the simple text message to the Hangouts Chat API'
do
subject
.
execute
(
sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
.
with
{
|
req
|
req
.
body
=~
/\A{"text":.+}\Z/
}
end
end
context
'with not default branch'
do
context
'with not default branch'
do
let
(
:sample_data
)
do
let
(
:sample_data
)
do
ref
=
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}
test"
Gitlab
::
DataBuilder
::
Push
.
build
(
project
,
user
,
nil
,
nil
,
'not-the-default-branch'
)
Gitlab
::
DataBuilder
::
Push
.
build
(
project
,
user
,
nil
,
nil
,
ref
,
[])
end
end
context
'when notify_only_default_branch enabled'
do
context
'when notify_only_default_branch enabled'
do
before
do
before
do
chat_service
.
notify_only_default_branch
=
true
subject
.
notify_only_default_branch
=
true
end
end
it
'does not call the Hangouts Chat API'
do
it
'does not call the Hangouts Chat API'
do
result
=
chat_service
.
execute
(
sample_data
)
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
expect
(
result
).
to
be_falsy
end
end
...
@@ -84,7 +88,7 @@ describe HangoutsChatService do
...
@@ -84,7 +88,7 @@ describe HangoutsChatService do
context
'when notify_only_default_branch disabled'
do
context
'when notify_only_default_branch disabled'
do
before
do
before
do
chat_service
.
notify_only_default_branch
=
false
subject
.
notify_only_default_branch
=
false
end
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
'Hangouts Chat service'
...
@@ -172,7 +176,7 @@ describe HangoutsChatService do
...
@@ -172,7 +176,7 @@ describe HangoutsChatService do
it_behaves_like
'Hangouts Chat service'
it_behaves_like
'Hangouts Chat service'
end
end
context
'wi
ht
snippet comment'
do
context
'wi
th
snippet comment'
do
let
(
:note
)
do
let
(
:note
)
do
create
(
:note_on_project_snippet
,
project:
project
,
create
(
:note_on_project_snippet
,
project:
project
,
note:
'snippet note'
)
note:
'snippet note'
)
...
@@ -201,7 +205,7 @@ describe HangoutsChatService do
...
@@ -201,7 +205,7 @@ describe HangoutsChatService do
context
'with default notify_only_broken_pipelines'
do
context
'with default notify_only_broken_pipelines'
do
it
'does not call Hangouts Chat API'
do
it
'does not call Hangouts Chat API'
do
result
=
chat_service
.
execute
(
sample_data
)
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
expect
(
result
).
to
be_falsy
end
end
...
@@ -209,7 +213,7 @@ describe HangoutsChatService do
...
@@ -209,7 +213,7 @@ describe HangoutsChatService do
context
'when notify_only_broken_pipelines is false'
do
context
'when notify_only_broken_pipelines is false'
do
before
do
before
do
chat_service
.
notify_only_broken_pipelines
=
false
subject
.
notify_only_broken_pipelines
=
false
end
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
'Hangouts Chat service'
...
@@ -223,11 +227,11 @@ describe HangoutsChatService do
...
@@ -223,11 +227,11 @@ describe HangoutsChatService do
context
'when notify_only_default_branch enabled'
do
context
'when notify_only_default_branch enabled'
do
before
do
before
do
chat_service
.
notify_only_default_branch
=
true
subject
.
notify_only_default_branch
=
true
end
end
it
'does not call the Hangouts Chat API'
do
it
'does not call the Hangouts Chat API'
do
result
=
chat_service
.
execute
(
sample_data
)
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
expect
(
result
).
to
be_falsy
end
end
...
@@ -235,7 +239,7 @@ describe HangoutsChatService do
...
@@ -235,7 +239,7 @@ describe HangoutsChatService do
context
'when notify_only_default_branch disabled'
do
context
'when notify_only_default_branch disabled'
do
before
do
before
do
chat_service
.
notify_only_default_branch
=
false
subject
.
notify_only_default_branch
=
false
end
end
it_behaves_like
'Hangouts Chat service'
it_behaves_like
'Hangouts Chat service'
...
...
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