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
841960f8
Unverified
Commit
841960f8
authored
Dec 20, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix flow
parent
34295036
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
28 deletions
+51
-28
mattermosts_controller.rb
app/controllers/projects/mattermosts_controller.rb
+1
-0
mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+4
-7
client.rb
lib/mattermost/client.rb
+39
-0
command.rb
lib/mattermost/command.rb
+4
-10
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
def
teams
@teams
||=
@service
.
list_teams
(
current_user
)
rescue
=>
e
@teams
=
[]
flash
[
:alert
]
=
e
.
message
end
...
...
app/models/project_services/mattermost_slash_commands_service.rb
View file @
841960f8
...
...
@@ -25,18 +25,15 @@ class MattermostSlashCommandsService < ChatService
]
end
def
configure!
(
current_user
,
params
)
token
=
Mattermost
::
Session
.
new
(
current_user
).
with_session
do
|
session
|
Mattermost
::
Command
.
create
(
session
,
command
(
params
))
end
def
configure!
(
user
,
params
)
token
=
Mattermost
::
Command
.
new
(
user
).
create
(
command
(
params
))
update!
(
active:
true
,
token:
token
)
end
def
list_teams
(
user
)
Mattermost
::
Session
.
new
(
user
).
with_session
do
|
session
|
Mattermost
::
Team
.
all
(
session
)
end
Mattermost
::
Team
.
new
(
user
).
all
end
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
class
Command
def
self
.
create
(
session
,
params
)
response
=
session
.
post
(
"/api/v3/teams/
#{
params
[
:team_id
]
}
/commands/create"
,
class
Command
<
Client
def
create
(
params
)
response
=
json_
post
(
"/api/v3/teams/
#{
params
[
:team_id
]
}
/commands/create"
,
body:
params
.
to_json
)
if
response
.
success?
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
response
[
'token'
]
end
end
end
lib/mattermost/team.rb
View file @
841960f8
module
Mattermost
class
Team
def
self
.
all
(
session
)
response
=
session
.
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
class
Team
<
Client
def
all
json_get
(
'/api/v3/teams/all'
)
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