BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
475a4dc3
Commit
475a4dc3
authored
Dec 16, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'zj-mattermost-session' into zj-mattermost-slash-config
parents
00459967
166ae89d
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
31 deletions
+30
-31
mattermost_controller.rb
app/controllers/projects/mattermost_controller.rb
+7
-7
mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+7
-7
new.html.haml
app/views/projects/mattermost/new.html.haml
+2
-1
command.rb
lib/mattermost/command.rb
+6
-12
session.rb
lib/mattermost/session.rb
+7
-3
session_spec.rb
spec/lib/mattermost/session_spec.rb
+1
-1
No files found.
app/controllers/projects/mattermost_controller.rb
View file @
475a4dc3
...
@@ -8,15 +8,15 @@ class Projects::MattermostController < Projects::ApplicationController
...
@@ -8,15 +8,15 @@ class Projects::MattermostController < Projects::ApplicationController
end
end
def
configure
def
configure
@service
.
configure
(
host
,
current_user
,
params
)
@service
.
configure
(
host
,
current_user
,
configure_
params
)
redirect_to
(
redirect_to
(
new_namespace_project_
service_path
(
@project
.
namespace
,
@project
,
@service
.
to_param
),
new_namespace_project_
mattermost_path
(
@project
.
namespace
,
@project
),
notice:
'This service is now configured.'
notice:
'This service is now configured.'
)
)
rescue
Mattermost
::
NoSessionError
rescue
NoSessionError
redirect_to
(
redirect_to
(
edit_namespace_project_service_path
(
@project
.
namespace
,
@project
,
@service
.
to_param
),
new_namespace_project_mattermost_path
(
@project
.
namespace
,
@project
),
alert:
'No session could be set up, is Mattermost configured with Single Sign on?'
alert:
'No session could be set up, is Mattermost configured with Single Sign on?'
)
)
end
end
...
@@ -24,11 +24,11 @@ class Projects::MattermostController < Projects::ApplicationController
...
@@ -24,11 +24,11 @@ class Projects::MattermostController < Projects::ApplicationController
private
private
def
configure_params
def
configure_params
params
.
require
(
:configure_params
).
permit
(
:trigger
,
:team_id
)
params
.
permit
(
:trigger
,
:team_id
).
merge
(
url:
service_trigger_url
(
@service
),
icon_url:
asset_url
(
'gitlab_logo.png'
)
)
end
end
def
service
def
service
@service
||=
@project
.
services
.
find_by
(
type:
'MattermostSlashCommandsService
'
)
@service
||=
@project
.
find_or_initialize_service
(
'mattermost_slash_commands
'
)
end
end
def
teams
def
teams
...
@@ -37,7 +37,7 @@ class Projects::MattermostController < Projects::ApplicationController
...
@@ -37,7 +37,7 @@ class Projects::MattermostController < Projects::ApplicationController
Mattermost
::
Mattermost
.
new
(
Gitlab
.
config
.
mattermost
.
host
,
current_user
).
with_session
do
Mattermost
::
Mattermost
.
new
(
Gitlab
.
config
.
mattermost
.
host
,
current_user
).
with_session
do
Mattermost
::
Team
.
team_admin
Mattermost
::
Team
.
team_admin
end
end
rescue
Mattermost
::
NoSessionError
rescue
[]
[]
end
end
end
end
...
...
app/models/project_services/mattermost_slash_commands_service.rb
View file @
475a4dc3
...
@@ -25,15 +25,15 @@ class MattermostSlashCommandsService < ChatService
...
@@ -25,15 +25,15 @@ class MattermostSlashCommandsService < ChatService
]
]
end
end
def
configure
(
host
,
current_user
,
params
)
def
configure
(
host
,
current_user
,
team_id
:,
trigger
:,
url
:,
icon_url
:
)
token
=
Mattermost
::
Mattermost
.
new
(
host
,
current_user
).
with_session
do
new_token
=
Mattermost
::
Session
.
new
(
host
,
current_user
).
with_session
do
Mattermost
::
Command
s
.
create
(
params
[
:team_id
]
,
Mattermost
::
Command
.
create
(
team_id
,
trigger:
params
[
:trigger
]
||
@service
.
project
.
path
,
trigger:
trigger
||
@service
.
project
.
path
,
url:
service_trigger_url
(
@service
)
,
url:
url
,
icon_url:
asset_url
(
'gitlab_logo.png'
)
)
icon_url:
icon_url
)
end
end
update
_attributes
(
token:
token
)
update
!
(
token:
new_
token
)
end
end
def
trigger
(
params
)
def
trigger
(
params
)
...
...
app/views/projects/mattermost/new.html.haml
View file @
475a4dc3
=
"hello world"
=
"hello world"
=
form_for
(
:create
,
method: :post
,
url:
configure_namespace_project_mattermost_path
(
@project
.
namespace
,
@project
,
@service
.
to_param
))
do
|
f
|
=
@teams
=
form_for
(
:create
,
method: :post
,
url:
configure_namespace_project_mattermost_path
(
@project
.
namespace
,
@project
,
))
do
|
f
|
=
"Team ID"
=
"Team ID"
=
f
.
text_field
(
:team_id
)
=
f
.
text_field
(
:team_id
)
=
f
.
submit
'Configure'
,
class:
'btn btn-save'
=
f
.
submit
'Configure'
,
class:
'btn btn-save'
...
...
lib/mattermost/command.rb
View file @
475a4dc3
module
Mattermost
module
Mattermost
class
Command
<
Session
class
Command
<
Session
def
self
.
all
(
team_id
)
def
self
.
create
(
team_id
,
trigger:
'gitlab'
,
url
:,
icon_url
:)
get
(
"/teams/
#{
team_id
}
/commands/list_team_commands"
).
parsed_response
end
# params should be a hash, which supplies _at least_:
# - trigger => The slash command, no spaces, cannot start with a /
# - url => What is the URL to trigger here?
# - icon_url => Supply a link to the icon
def
self
.
create
(
team_id
,
params
)
command
=
{
command
=
{
auto_complete:
true
,
auto_complete:
true
,
auto_complete_desc:
'List all available commands'
,
auto_complete_desc:
'List all available commands'
,
auto_complete_hint:
'[help]'
,
auto_complete_hint:
'[help]'
,
description:
'Perform common operations on GitLab'
,
description:
'Perform common operations on GitLab'
,
display_name:
'GitLab'
,
display_name:
'GitLab
Slash Commands
'
,
method:
'P'
,
method:
'P'
,
user_name:
'GitLab'
,
user_name:
'GitLab'
,
trigger:
'gitlab'
,
trigger:
trigger
,
}.
merge
(
params
)
url:
url
,
icon_url:
icon_url
}
response
=
post
(
"/teams/
#{
team_id
}
/commands/create"
,
body:
command
.
to_json
)
response
=
post
(
"/teams/
#{
team_id
}
/commands/create"
,
body:
command
.
to_json
)
...
...
lib/mattermost/session.rb
View file @
475a4dc3
...
@@ -21,6 +21,8 @@ module Mattermost
...
@@ -21,6 +21,8 @@ module Mattermost
def
initialize
(
uri
,
current_user
)
def
initialize
(
uri
,
current_user
)
uri
=
normalize_uri
(
uri
)
uri
=
normalize_uri
(
uri
)
# Sets the base uri for HTTParty, so we can use paths
self
.
class
.
base_uri
(
uri
)
self
.
class
.
base_uri
(
uri
)
@current_resource_owner
=
current_user
@current_resource_owner
=
current_user
...
@@ -28,12 +30,14 @@ module Mattermost
...
@@ -28,12 +30,14 @@ module Mattermost
def
with_session
def
with_session
raise
NoSessionError
unless
create
raise
NoSessionError
unless
create
result
=
yield
destroy
result
begin
yield
rescue
Errno
::
ECONNREFUSED
rescue
Errno
::
ECONNREFUSED
raise
NoSessionError
raise
NoSessionError
ensure
destroy
end
end
end
# Next methods are needed for Doorkeeper
# Next methods are needed for Doorkeeper
...
...
spec/lib/mattermost/session_spec.rb
View file @
475a4dc3
...
@@ -5,7 +5,7 @@ describe Mattermost::Session do
...
@@ -5,7 +5,7 @@ describe Mattermost::Session do
subject
{
described_class
.
new
(
'http://localhost:8065'
,
user
)
}
subject
{
described_class
.
new
(
'http://localhost:8065'
,
user
)
}
# Needed for door
man
to function
# Needed for door
keeper
to function
it
{
is_expected
.
to
respond_to
(
:current_resource_owner
)
}
it
{
is_expected
.
to
respond_to
(
:current_resource_owner
)
}
it
{
is_expected
.
to
respond_to
(
:request
)
}
it
{
is_expected
.
to
respond_to
(
:request
)
}
it
{
is_expected
.
to
respond_to
(
:authorization
)
}
it
{
is_expected
.
to
respond_to
(
:authorization
)
}
...
...
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