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
Tatuya Kamada
gitlab-ce
Commits
6d14a664
Commit
6d14a664
authored
Dec 19, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor adjustments API Mattermost
[ci skip]
parent
4213bd56
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
38 deletions
+31
-38
app/models/project_services/mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+2
-2
lib/mattermost/command.rb
lib/mattermost/command.rb
+3
-10
lib/mattermost/session.rb
lib/mattermost/session.rb
+3
-1
lib/mattermost/team.rb
lib/mattermost/team.rb
+8
-9
spec/fixtures/mattermost_new_command.json
spec/fixtures/mattermost_new_command.json
+0
-1
spec/lib/mattermost/command_spec.rb
spec/lib/mattermost/command_spec.rb
+5
-8
spec/lib/mattermost/session_spec.rb
spec/lib/mattermost/session_spec.rb
+1
-1
spec/lib/mattermost/team_spec.rb
spec/lib/mattermost/team_spec.rb
+9
-6
No files found.
app/models/project_services/mattermost_slash_commands_service.rb
View file @
6d14a664
...
...
@@ -26,8 +26,8 @@ class MattermostSlashCommandsService < ChatService
end
def
configure
(
host
,
current_user
,
params
)
new_token
=
Mattermost
::
Session
.
new
(
host
,
current_user
).
with_session
do
Mattermost
::
Command
.
create
(
params
[
:team_id
],
command
)
new_token
=
Mattermost
::
Session
.
new
(
current_user
).
with_session
do
|
session
|
Mattermost
::
Command
.
create
(
session
,
params
[
:team_id
],
command
)
end
update!
(
token:
new_token
,
active:
true
)
...
...
lib/mattermost/command.rb
View file @
6d14a664
module
Mattermost
class
Command
<
Session
def
self
.
create
(
team_id
,
trigger:
'gitlab'
,
url
:,
icon_url
:)
post_command
(
command
)[
'token'
]
end
private
def
post_command
(
command
)
post
(
"/teams/
#{
team_id
}
/commands/create"
,
body:
command
.
to_json
).
parsed_response
class
Command
def
self
.
create
(
session
,
team_id
,
command
)
session
.
post
(
"/api/v3/teams/
#{
team_id
}
/commands/create"
,
body:
command
.
to_json
)[
'token'
]
end
end
end
lib/mattermost/session.rb
View file @
6d14a664
...
...
@@ -30,6 +30,8 @@ module Mattermost
begin
yield
self
rescue
Errno
::
ECONNREFUSED
raise
NoSessionError
ensure
destroy
end
...
...
@@ -112,4 +114,4 @@ module Mattermost
end
end
end
end
\ No newline at end of file
end
lib/mattermost/team.rb
View file @
6d14a664
module
Mattermost
class
Team
<
Session
def
self
.
team_admin
return
[]
unless
initial_load
[
'team_members'
]
class
Team
def
self
.
team_admin
(
session
)
response_body
=
initial_load
(
session
)
return
[]
unless
response_body
[
'team_members'
]
team_ids
=
initial_load
[
'team_members'
].
map
do
|
team
|
team_ids
=
response_body
[
'team_members'
].
map
do
|
team
|
team
[
'team_id'
]
if
team
[
'roles'
].
split
.
include?
(
'team_admin'
)
end
.
compact
initial_load
[
'teams'
].
select
do
|
team
|
response_body
[
'teams'
].
select
do
|
team
|
team_ids
.
include?
(
team
[
'id'
])
end
end
private
def
initial_load
@initial_load
||=
get
(
'/users/initial_load'
).
parsed_response
def
self
.
initial_load
(
session
)
session
.
get
(
'/api/v3/users/initial_load'
).
parsed_response
end
end
end
spec/fixtures/mattermost_new_command.json
deleted
100644 → 0
View file @
4213bd56
{
"id"
:
"y8j1nexrdirj5nubq5uzdwwidr"
,
"token"
:
"pzajm5hfbtni3r49ujpt8betpc"
,
"create_at"
:
1481897117122
,
"update_at"
:
1481897117122
,
"delete_at"
:
0
,
"creator_id"
:
"78nm4euoc7dypergdc13ekxgpo"
,
"team_id"
:
"w59qt5a817f69jkxdz6xe7y4ir"
,
"trigger"
:
"display"
,
"method"
:
"P"
,
"username"
:
"GitLab"
,
"icon_url"
:
""
,
"auto_complete"
:
false
,
"auto_complete_desc"
:
""
,
"auto_complete_hint"
:
""
,
"display_name"
:
"Display name"
,
"description"
:
"the description"
,
"url"
:
"http://trigger.url/trigger"
}
spec/lib/mattermost/command_spec.rb
View file @
6d14a664
require
'spec_helper'
describe
Mattermost
::
Command
do
describe
'.create'
do
let
(
:new_command
)
do
JSON
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'spec/fixtures/'
,
'mattermost_new_command.json'
)))
end
let
(
:session
)
{
double
(
"session"
)
}
describe
'.create'
do
it
'gets the teams'
do
allow
(
described_class
).
to
receive
(
:post_command
).
and_return
(
new_command
)
token
=
described_class
.
create
(
'abc'
,
url:
'http://trigger.url/trigger'
,
icon_url:
'http://myicon.com/icon.png'
)
allow
(
session
).
to
receive
(
:post
).
and_return
(
'token'
=>
'token'
)
expect
(
session
).
to
receive
(
:post
)
expect
(
token
).
to
eq
(
'pzajm5hfbtni3r49ujpt8betpc
'
)
described_class
.
create
(
session
,
'abc'
,
url:
'http://trigger.com
'
)
end
end
end
spec/lib/mattermost/session_spec.rb
View file @
6d14a664
...
...
@@ -96,4 +96,4 @@ describe Mattermost::Session, type: :request do
end
end
end
end
\ No newline at end of file
end
spec/lib/mattermost/team_spec.rb
View file @
6d14a664
...
...
@@ -2,20 +2,23 @@ require 'spec_helper'
describe
Mattermost
::
Team
do
describe
'.team_admin'
do
let
(
:
init_load
)
do
JSON
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'spec/fixtures/'
,
'mattermost_initial_load.json'
)))
end
let
(
:
session
)
{
double
(
"session"
)
}
let
(
:json
)
{
File
.
read
(
Rails
.
root
.
join
(
'spec/fixtures/'
,
'mattermost_initial_load.json'
))
}
let
(
:parsed_response
)
{
JSON
.
parse
(
json
)
}
before
do
allow
(
described_class
).
to
receive
(
:initial_load
).
and_return
(
init_load
)
allow
(
session
).
to
receive
(
:get
).
with
(
'/api/v3/users/initial_load'
).
and_return
(
json
)
allow
(
json
).
to
receive
(
:parsed_response
).
and_return
(
parsed_response
)
end
it
'gets the teams'
do
expect
(
described_class
.
team_admin
.
count
).
to
be
(
2
)
expect
(
described_class
.
team_admin
(
session
)
.
count
).
to
be
(
2
)
end
it
'filters on being team admin'
do
ids
=
described_class
.
team_admin
.
map
{
|
team
|
team
[
'id'
]
}
ids
=
described_class
.
team_admin
(
session
).
map
{
|
team
|
team
[
'id'
]
}
expect
(
ids
).
to
include
(
"w59qt5a817f69jkxdz6xe7y4ir"
,
"my9oujxf5jy1zqdgu9rihd66do"
)
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