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
efe2d96a
Commit
efe2d96a
authored
Apr 03, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds initial microsoft teams integration
parent
d4349ba6
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
137 additions
and
5 deletions
+137
-5
app/models/project.rb
app/models/project.rb
+1
-0
app/models/project_services/chat_message/note_message.rb
app/models/project_services/chat_message/note_message.rb
+1
-1
app/models/project_services/chat_message/push_message.rb
app/models/project_services/chat_message/push_message.rb
+28
-3
app/models/project_services/chat_notification_service.rb
app/models/project_services/chat_notification_service.rb
+2
-1
app/models/project_services/microsoft_teams_service.rb
app/models/project_services/microsoft_teams_service.rb
+66
-0
app/models/service.rb
app/models/service.rb
+1
-0
lib/microsoft_teams/notifier.rb
lib/microsoft_teams/notifier.rb
+37
-0
spec/lib/gitlab/import_export/all_models.yml
spec/lib/gitlab/import_export/all_models.yml
+1
-0
No files found.
app/models/project.rb
View file @
efe2d96a
...
...
@@ -116,6 +116,7 @@ class Project < ActiveRecord::Base
has_one
:mock_ci_service
,
dependent: :destroy
has_one
:mock_deployment_service
,
dependent: :destroy
has_one
:mock_monitoring_service
,
dependent: :destroy
has_one
:microsoft_teams_service
,
dependent: :destroy
has_one
:forked_project_link
,
dependent: :destroy
,
foreign_key:
"forked_to_project_id"
has_one
:forked_from_project
,
through: :forked_project_link
...
...
app/models/project_services/chat_message/note_message.rb
View file @
efe2d96a
...
...
@@ -10,6 +10,7 @@ module ChatMessage
def
initialize
(
params
)
params
=
HashWithIndifferentAccess
.
new
(
params
)
@user_name
=
params
[
:user
][
:username
]
@user_avatar
=
params
[
:user
][
:avatar
]
@project_name
=
params
[
:project_name
]
@project_url
=
params
[
:project_url
]
...
...
@@ -18,7 +19,6 @@ module ChatMessage
@note
=
obj_attr
[
:note
]
@note_url
=
obj_attr
[
:url
]
noteable_type
=
obj_attr
[
:noteable_type
]
case
noteable_type
when
"Commit"
create_commit_note
(
HashWithIndifferentAccess
.
new
(
params
[
:commit
]))
...
...
app/models/project_services/chat_message/push_message.rb
View file @
efe2d96a
...
...
@@ -8,6 +8,7 @@ module ChatMessage
attr_reader
:ref
attr_reader
:ref_type
attr_reader
:user_name
attr_reader
:user_avatar
def
initialize
(
params
)
@after
=
params
[
:after
]
...
...
@@ -18,16 +19,27 @@ module ChatMessage
@ref_type
=
Gitlab
::
Git
.
tag_ref?
(
params
[
:ref
])
?
'tag'
:
'branch'
@ref
=
Gitlab
::
Git
.
ref_name
(
params
[
:ref
])
@user_name
=
params
[
:user_name
]
@user_avatar
=
params
[
:user_avatar
]
@format
=
params
[
:format
]
end
def
activity
{
title:
activity_title
,
subtitle:
"to:
#{
project_link
}
"
,
text:
compare_link
,
image:
params
[
:user_avatar
]
}
end
def
pretext
format
(
message
)
@format
?
format
(
message
)
:
message
end
def
attachments
return
[]
if
new_branch?
||
removed_branch?
commit_message_attachment
s
@format
?
commit_message_attachments
:
commit_message
s
end
private
...
...
@@ -59,7 +71,7 @@ module ChatMessage
end
def
commit_messages
commits
.
map
{
|
commit
|
compose_commit_message
(
commit
)
}.
join
(
"
\n
"
)
commits
.
map
{
|
commit
|
compose_commit_message
(
commit
)
}.
join
(
"
\n
\n
"
)
end
def
commit_message_attachments
...
...
@@ -103,6 +115,19 @@ module ChatMessage
"[Compare changes](
#{
compare_url
}
)"
end
def
activity_title
action
=
if
new_branch?
"created"
elsif
removed_branch?
"removed"
else
"pushed to"
end
"
#{
user_name
}
#{
action
}
#{
ref_type
}
"
end
def
attachment_color
'#345'
end
...
...
app/models/project_services/chat_notification_service.rb
View file @
efe2d96a
...
...
@@ -51,7 +51,8 @@ class ChatNotificationService < Service
data
=
data
.
merge
(
project_url:
project_url
,
project_name:
project_name
project_name:
project_name
,
format:
true
)
# WebHook events often have an 'update' event that follows a 'open' or
...
...
app/models/project_services/microsoft_teams_service.rb
0 → 100644
View file @
efe2d96a
class
MicrosoftTeamsService
<
ChatNotificationService
def
title
'Microsoft Teams Notification'
end
def
description
'Receive event notifications in Microsoft Team'
end
def
self
.
to_param
'microsoft_teams'
end
#TODO: Setup the description accordingly
def
help
'This service sends notifications about projects events to Microsoft Teams channels.<br />
To set up this service:
<ol>
<li><a href="https://msdn.microsoft.com/en-us/microsoft-teams/connectors">Getting started with 365 Office Connectors For Microsoft Teams</a>.</li>
<li>Paste the <strong>Webhook URL</strong> into the field below.</li>
<li>Select events below to enable notifications.</li>
</ol>'
end
def
default_channel_placeholder
"Channel name (e.g. general)"
end
def
webhook_placeholder
'https://outlook.office.com/webhook/…'
end
def
event_field
(
event
)
end
def
default_fields
[
{
type:
'text'
,
name:
'webhook'
,
placeholder:
"e.g.
#{
webhook_placeholder
}
"
},
{
type:
'checkbox'
,
name:
'notify_only_broken_pipelines'
},
{
type:
'checkbox'
,
name:
'notify_only_default_branch'
},
]
end
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
webhook
.
present?
object_kind
=
data
[
:object_kind
]
data
=
data
.
merge
(
project_url:
project_url
,
project_name:
project_name
,
format:
false
)
message
=
get_message
(
object_kind
,
data
)
return
false
unless
message
MicrosoftTeams
::
Notifier
.
new
(
webhook
).
ping
({
title:
message
.
project_name
,
activity:
message
.
activity
,
attachments:
message
.
attachments
,
})
end
end
app/models/service.rb
View file @
efe2d96a
...
...
@@ -237,6 +237,7 @@ class Service < ActiveRecord::Base
slack_slash_commands
slack
teamcity
microsoft_teams
]
if
Rails
.
env
.
development?
service_names
+=
%w[mock_ci mock_deployment mock_monitoring]
...
...
lib/microsoft_teams/notifier.rb
0 → 100644
View file @
efe2d96a
module
MicrosoftTeams
class
Notifier
def
initialize
(
webhook
)
@webhook
=
webhook
end
def
ping
(
options
=
{})
HTTParty
.
post
(
@webhook
.
to_str
,
headers:
{
'Content-type'
=>
'application/json'
},
body:
body
(
options
)
)
end
private
def
body
(
options
=
{})
result
=
{
'sections'
=>
[]
}
result
[
'title'
]
=
options
[
:title
]
if
options
[
:title
]
result
[
'summary'
]
=
options
[
:activity
][
:title
]
result
[
'sections'
]
<<
{
'activityTitle'
=>
options
[
:activity
][
:title
],
'activitySubtitle'
=>
options
[
:activity
][
:subtitle
],
'activityText'
=>
options
[
:activity
][
:text
],
'activityImage'
=>
options
[
:activity
][
:image
]
}
result
[
'sections'
]
<<
{
'title'
=>
'Details'
,
'facts'
=>
attachments
(
options
[
:attachments
])
}
if
options
[
:attachments
]
result
.
to_json
end
def
attachments
(
content
)
[{
'name'
=>
'Attachments'
,
'value'
=>
content
}]
end
end
end
spec/lib/gitlab/import_export/all_models.yml
View file @
efe2d96a
...
...
@@ -143,6 +143,7 @@ project:
-
asana_service
-
gemnasium_service
-
slack_service
-
microsoft_teams_service
-
mattermost_service
-
buildkite_service
-
bamboo_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