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
Boxiang Sun
gitlab-ce
Commits
841960f8
Commit
841960f8
authored
Dec 20, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix flow
parent
34295036
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
28 deletions
+51
-28
app/controllers/projects/mattermosts_controller.rb
app/controllers/projects/mattermosts_controller.rb
+1
-0
app/models/project_services/mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+4
-7
lib/mattermost/client.rb
lib/mattermost/client.rb
+39
-0
lib/mattermost/command.rb
lib/mattermost/command.rb
+4
-10
lib/mattermost/team.rb
lib/mattermost/team.rb
+3
-11
No files found.
app/controllers/projects/mattermosts_controller.rb
View file @
841960f8
...
@@ -32,6 +32,7 @@ class Projects::MattermostsController < Projects::ApplicationController
...
@@ -32,6 +32,7 @@ class Projects::MattermostsController < Projects::ApplicationController
def
teams
def
teams
@teams
||=
@service
.
list_teams
(
current_user
)
@teams
||=
@service
.
list_teams
(
current_user
)
rescue
=>
e
rescue
=>
e
@teams
=
[]
flash
[
:alert
]
=
e
.
message
flash
[
:alert
]
=
e
.
message
end
end
...
...
app/models/project_services/mattermost_slash_commands_service.rb
View file @
841960f8
...
@@ -25,18 +25,15 @@ class MattermostSlashCommandsService < ChatService
...
@@ -25,18 +25,15 @@ class MattermostSlashCommandsService < ChatService
]
]
end
end
def
configure!
(
current_user
,
params
)
def
configure!
(
user
,
params
)
token
=
Mattermost
::
Session
.
new
(
current_user
).
with_session
do
|
session
|
token
=
Mattermost
::
Command
.
new
(
user
).
Mattermost
::
Command
.
create
(
session
,
command
(
params
))
create
(
command
(
params
))
end
update!
(
active:
true
,
token:
token
)
update!
(
active:
true
,
token:
token
)
end
end
def
list_teams
(
user
)
def
list_teams
(
user
)
Mattermost
::
Session
.
new
(
user
).
with_session
do
|
session
|
Mattermost
::
Team
.
new
(
user
).
all
Mattermost
::
Team
.
all
(
session
)
end
end
end
def
trigger
(
params
)
def
trigger
(
params
)
...
...
lib/mattermost/client.rb
0 → 100644
View file @
841960f8
module
Mattermost
class
Client
attr_reader
:user
def
initialize
(
user
)
@user
=
user
end
private
def
with_session
(
&
blk
)
Session
.
new
(
user
).
with_session
(
&
blk
)
end
def
json_get
(
path
,
options
=
{})
with_session
do
|
session
|
json_response
session
.
get
(
path
,
options
)
end
end
def
json_post
(
path
,
options
=
{})
with_session
do
|
session
|
json_response
session
.
post
(
path
,
options
)
end
end
def
json_response
(
response
)
json_response
=
JSON
.
parse
(
response
.
body
)
if
response
.
success?
json_response
elsif
json_response
[
'message'
]
raise
json_response
[
'message'
]
else
raise
'Undefined error'
end
end
end
end
lib/mattermost/command.rb
View file @
841960f8
module
Mattermost
module
Mattermost
class
Command
class
Command
<
Client
def
self
.
create
(
session
,
params
)
def
create
(
params
)
response
=
session
.
post
(
"/api/v3/teams/
#{
params
[
:team_id
]
}
/commands/create"
,
response
=
json_
post
(
"/api/v3/teams/
#{
params
[
:team_id
]
}
/commands/create"
,
body:
params
.
to_json
)
body:
params
.
to_json
)
if
response
.
success?
response
[
'token'
]
response
.
parsed_response
[
'token'
]
elsif
response
.
parsed_response
.
try
(
:has_key?
,
'message'
)
raise
response
.
parsed_response
[
'message'
]
else
raise
'Failed to create a new command'
end
end
end
end
end
end
end
lib/mattermost/team.rb
View file @
841960f8
module
Mattermost
module
Mattermost
class
Team
class
Team
<
Client
def
self
.
all
(
session
)
def
all
response
=
session
.
get
(
'/api/v3/teams/all'
)
json_get
(
'/api/v3/teams/all'
)
if
response
.
success?
response
.
parsed_response
elsif
response
.
parsed_response
.
try
(
:has_key?
,
'message'
)
raise
response
.
parsed_response
[
'message'
]
else
raise
'Failed to list teams'
end
end
end
end
end
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