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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
61d09a7b
Commit
61d09a7b
authored
Dec 20, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
0cf23fde
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
49 deletions
+40
-49
app/controllers/projects/mattermosts_controller.rb
app/controllers/projects/mattermosts_controller.rb
+11
-10
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+0
-4
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+0
-8
app/models/project_services/mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+6
-2
lib/mattermost/client.rb
lib/mattermost/client.rb
+6
-6
lib/mattermost/session.rb
lib/mattermost/session.rb
+8
-8
spec/lib/mattermost/command_spec.rb
spec/lib/mattermost/command_spec.rb
+8
-10
spec/lib/mattermost/team_spec.rb
spec/lib/mattermost/team_spec.rb
+1
-1
No files found.
app/controllers/projects/mattermosts_controller.rb
View file @
61d09a7b
...
@@ -12,13 +12,17 @@ class Projects::MattermostsController < Projects::ApplicationController
...
@@ -12,13 +12,17 @@ class Projects::MattermostsController < Projects::ApplicationController
end
end
def
create
def
create
@service
.
configure!
(
current_user
,
configure_params
)
result
,
message
=
@service
.
configure
(
current_user
,
configure_params
)
flash
[
:notice
]
=
'This service is now configured'
if
result
redirect_to
edit_namespace_project_service_path
(
@project
.
namespace
,
@project
,
service
)
flash
[
:notice
]
=
'This service is now configured'
rescue
=>
e
redirect_to
edit_namespace_project_service_path
(
flash
[
:alert
]
=
e
.
message
@project
.
namespace
,
@project
,
service
)
redirect_to
new_namespace_project_mattermost_path
(
@project
.
namespace
,
@project
)
else
flash
[
:alert
]
=
message
||
'Failed to configure service'
redirect_to
new_namespace_project_mattermost_path
(
@project
.
namespace
,
@project
)
end
end
end
private
private
...
@@ -31,9 +35,6 @@ class Projects::MattermostsController < Projects::ApplicationController
...
@@ -31,9 +35,6 @@ class Projects::MattermostsController < Projects::ApplicationController
def
teams
def
teams
@teams
||=
@service
.
list_teams
(
current_user
)
@teams
||=
@service
.
list_teams
(
current_user
)
rescue
=>
e
@teams
=
[]
flash
[
:alert
]
=
e
.
message
end
end
def
service
def
service
...
...
app/helpers/application_helper.rb
View file @
61d09a7b
...
@@ -294,8 +294,4 @@ module ApplicationHelper
...
@@ -294,8 +294,4 @@ module ApplicationHelper
def
page_class
def
page_class
"issue-boards-page"
if
current_controller?
(
:boards
)
"issue-boards-page"
if
current_controller?
(
:boards
)
end
end
def
pretty_url
(
url
)
url
.
gsub
(
/\A.*?:\/\//
,
''
)
end
end
end
app/helpers/projects_helper.rb
View file @
61d09a7b
...
@@ -148,14 +148,6 @@ module ProjectsHelper
...
@@ -148,14 +148,6 @@ module ProjectsHelper
).
html_safe
).
html_safe
end
end
def
mattermost_teams_options
(
teams
)
teams_options
=
teams
.
map
do
|
id
,
options
|
[
options
[
'display_name'
]
||
options
[
'name'
],
id
]
end
teams_options
.
compact
.
unshift
([
'Select team...'
,
'0'
])
end
private
private
def
repo_children_classes
(
field
)
def
repo_children_classes
(
field
)
...
...
app/models/project_services/mattermost_slash_commands_service.rb
View file @
61d09a7b
...
@@ -19,15 +19,19 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
...
@@ -19,15 +19,19 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
'mattermost_slash_commands'
'mattermost_slash_commands'
end
end
def
configure
!
(
user
,
params
)
def
configure
(
user
,
params
)
token
=
Mattermost
::
Command
.
new
(
user
).
token
=
Mattermost
::
Command
.
new
(
user
).
create
(
command
(
params
))
create
(
command
(
params
))
update!
(
active:
true
,
token:
token
)
update
(
active:
true
,
token:
token
)
if
token
rescue
=>
Mattermost
::
Error
=>
e
false
,
e
.
message
end
end
def
list_teams
(
user
)
def
list_teams
(
user
)
Mattermost
::
Team
.
new
(
user
).
all
Mattermost
::
Team
.
new
(
user
).
all
rescue
=>
Mattermost
::
Error
=>
e
[]
end
end
private
private
...
...
lib/mattermost/client.rb
View file @
61d09a7b
...
@@ -29,13 +29,13 @@ module Mattermost
...
@@ -29,13 +29,13 @@ module Mattermost
def
json_response
(
response
)
def
json_response
(
response
)
json_response
=
JSON
.
parse
(
response
.
body
)
json_response
=
JSON
.
parse
(
response
.
body
)
if
response
.
success?
unless
response
.
success?
json_response
raise
ClientError
(
json_response
[
'message'
]
||
'Undefined error'
)
elsif
json_response
[
'message'
]
raise
ClientError
(
json_response
[
'message'
])
else
raise
ClientError
(
'Undefined error'
)
end
end
json_response
rescue
JSON
::
JSONError
=>
e
raise
ClientError
(
'Cannot parse response'
)
end
end
end
end
end
end
lib/mattermost/session.rb
View file @
61d09a7b
...
@@ -3,15 +3,11 @@ module Mattermost
...
@@ -3,15 +3,11 @@ module Mattermost
class
NoSessionError
<
Error
class
NoSessionError
<
Error
def
message
def
message
'No session could be set up, is Mattermost configured with Single Sign
o
n?'
'No session could be set up, is Mattermost configured with Single Sign
O
n?'
end
end
end
end
class
ConnectionError
<
Error
class
ConnectionError
<
Error
;
end
def
message
'Could not connect. Is Mattermost up?'
end
end
# This class' prime objective is to obtain a session token on a Mattermost
# This class' prime objective is to obtain a session token on a Mattermost
# instance with SSO configured where this GitLab instance is the provider.
# instance with SSO configured where this GitLab instance is the provider.
...
@@ -74,12 +70,16 @@ module Mattermost
...
@@ -74,12 +70,16 @@ module Mattermost
def
get
(
path
,
options
=
{})
def
get
(
path
,
options
=
{})
self
.
class
.
get
(
path
,
options
.
merge
(
headers:
@headers
))
self
.
class
.
get
(
path
,
options
.
merge
(
headers:
@headers
))
rescue
Errno
::
ECONNREFUSED
rescue
HTTParty
::
Error
=>
e
raise
ConnectionError
raise
ConnectionError
(
e
.
message
)
rescue
Errno
::
ECONNREFUSED
=>
e
raise
ConnectionError
(
e
.
message
)
end
end
def
post
(
path
,
options
=
{})
def
post
(
path
,
options
=
{})
self
.
class
.
post
(
path
,
options
.
merge
(
headers:
@headers
))
self
.
class
.
post
(
path
,
options
.
merge
(
headers:
@headers
))
rescue
HTTParty
::
Error
=>
e
raise
ConnectionError
(
e
.
message
)
rescue
Errno
::
ECONNREFUSED
rescue
Errno
::
ECONNREFUSED
raise
ConnectionError
raise
ConnectionError
end
end
...
...
spec/lib/mattermost/command_spec.rb
View file @
61d09a7b
require
'spec_helper'
require
'spec_helper'
describe
Mattermost
::
Command
do
describe
Mattermost
::
Command
do
let
(
:session
)
{
double
(
"session"
)
}
let
(
:hash
)
{
{
'token'
=>
'token'
}
}
let
(
:hash
)
{
{
'token'
=>
'token'
}
}
let
(
:user
)
{
create
(
:user
)
}
describe
'.create'
do
before
do
before
do
Mattermost
::
Session
.
base_uri
(
"http://mattermost.example.com"
)
allow
(
session
).
to
receive
(
:post
).
and_return
(
hash
)
end
allow
(
hash
).
to
receive
(
:parsed_response
).
and_return
(
hash
)
end
it
'gets the teams'
do
expect
(
session
).
to
receive
(
:post
)
described_class
.
create
(
session
,
'abc'
,
url:
'http://trigger.com'
)
describe
'#create'
do
it
'creates a command'
do
described_class
.
new
(
user
).
create
(
team_id:
'abc'
,
url:
'http://trigger.com'
)
end
end
end
end
end
end
spec/lib/mattermost/team_spec.rb
View file @
61d09a7b
require
'spec_helper'
require
'spec_helper'
describe
Mattermost
::
Team
do
describe
Mattermost
::
Team
do
describe
'
.team_admin
'
do
describe
'
#all
'
do
let
(
:session
)
{
double
(
"session"
)
}
let
(
:session
)
{
double
(
"session"
)
}
let
(
:response
)
do
let
(
:response
)
do
...
...
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