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
Jérome Perrin
gitlab-ce
Commits
00459967
Commit
00459967
authored
Dec 15, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add auto configure of commands
parent
99d8d6f0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
33 deletions
+50
-33
app/controllers/projects/mattermost_controller.rb
app/controllers/projects/mattermost_controller.rb
+8
-11
app/models/project_services/mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+0
-4
app/models/service.rb
app/models/service.rb
+0
-4
lib/mattermost/command.rb
lib/mattermost/command.rb
+9
-7
lib/mattermost/session.rb
lib/mattermost/session.rb
+1
-1
lib/mattermost/team.rb
lib/mattermost/team.rb
+13
-6
spec/lib/mattermost/team_spec.rb
spec/lib/mattermost/team_spec.rb
+19
-0
No files found.
app/controllers/projects/mattermost_controller.rb
View file @
00459967
...
@@ -32,16 +32,13 @@ class Projects::MattermostController < Projects::ApplicationController
...
@@ -32,16 +32,13 @@ class Projects::MattermostController < Projects::ApplicationController
end
end
def
teams
def
teams
# Mocking for frontend development
@teams
=
@teams
=
[{
"id"
=>
"qz8gdr1fopncueb8n9on8ohk3h"
,
"create_at"
=>
1479992105904
,
"update_at"
=>
1479992105904
,
"delete_at"
=>
0
,
"display_name"
=>
"chatops"
,
"name"
=>
"chatops"
,
"email"
=>
"admin@example.com"
,
"type"
=>
"O"
,
"company_name"
=>
""
,
"allowed_domains"
=>
""
,
"invite_id"
=>
"gthxi47gj7rxtcx6zama63zd1w"
,
"allow_open_invite"
=>
false
}]
begin
Mattermost
::
Mattermost
.
new
(
Gitlab
.
config
.
mattermost
.
host
,
current_user
).
with_session
do
# @teams =
Mattermost
::
Team
.
team_admin
# begin
end
# Mattermost::Mattermost.new(Gitlab.config.mattermost.host, current_user).with_session do
rescue
Mattermost
::
NoSessionError
# Mattermost::Team.all
[]
# end
end
# rescue Mattermost::NoSessionError
# @teams = []
# end
end
end
end
end
app/models/project_services/mattermost_slash_commands_service.rb
View file @
00459967
...
@@ -25,10 +25,6 @@ class MattermostSlashCommandsService < ChatService
...
@@ -25,10 +25,6 @@ class MattermostSlashCommandsService < ChatService
]
]
end
end
def
auto_config?
Gitlab
.
config
.
mattermost
.
enabled
end
def
configure
(
host
,
current_user
,
params
)
def
configure
(
host
,
current_user
,
params
)
token
=
Mattermost
::
Mattermost
.
new
(
host
,
current_user
).
with_session
do
token
=
Mattermost
::
Mattermost
.
new
(
host
,
current_user
).
with_session
do
Mattermost
::
Commands
.
create
(
params
[
:team_id
],
Mattermost
::
Commands
.
create
(
params
[
:team_id
],
...
...
app/models/service.rb
View file @
00459967
...
@@ -54,10 +54,6 @@ class Service < ActiveRecord::Base
...
@@ -54,10 +54,6 @@ class Service < ActiveRecord::Base
template
template
end
end
def
auto_config?
false
end
def
category
def
category
read_attribute
(
:category
).
to_sym
read_attribute
(
:category
).
to_sym
end
end
...
...
lib/mattermost/command.rb
View file @
00459967
module
Mattermost
module
Mattermost
class
Command
class
Command
<
Session
def
self
.
all
(
team_id
)
def
self
.
all
(
team_id
)
Mattermost
::
Mattermost
.
get
(
"/teams/
#{
team_id
}
/commands/list_team_commands"
)
get
(
"/teams/
#{
team_id
}
/commands/list_team_commands"
).
parsed_response
end
end
# params should be a hash, which supplies _at least_:
# params should be a hash, which supplies _at least_:
...
@@ -9,18 +9,20 @@ module Mattermost
...
@@ -9,18 +9,20 @@ module Mattermost
# - url => What is the URL to trigger here?
# - url => What is the URL to trigger here?
# - icon_url => Supply a link to the icon
# - icon_url => Supply a link to the icon
def
self
.
create
(
team_id
,
params
)
def
self
.
create
(
team_id
,
params
)
params
=
{
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'
,
method:
'P'
,
method:
'P'
,
user_name:
'GitLab'
user_name:
'GitLab'
,
}
..
merge
(
params
)
trigger:
'gitlab'
,
}.
merge
(
params
)
Mattermost
::
Mattermost
.
post
(
"/teams/
#{
team_id
}
/commands/create"
,
params
.
to_json
).
response
=
post
(
"/teams/
#{
team_id
}
/commands/create"
,
body:
command
.
to_json
)
parsed_response
[
'token'
]
response
.
parsed_response
[
'token'
]
end
end
end
end
end
end
lib/mattermost/session.rb
View file @
00459967
...
@@ -65,6 +65,7 @@ module Mattermost
...
@@ -65,6 +65,7 @@ module Mattermost
return
unless
token_uri
return
unless
token_uri
self
.
class
.
headers
(
"Cookie"
=>
"MMAUTHTOKEN=
#{
request_token
}
"
)
self
.
class
.
headers
(
"Cookie"
=>
"MMAUTHTOKEN=
#{
request_token
}
"
)
self
.
class
.
headers
(
"X-Requested-With"
=>
'XMLHttpRequest'
)
request_token
request_token
end
end
...
@@ -106,7 +107,6 @@ module Mattermost
...
@@ -106,7 +107,6 @@ module Mattermost
def
normalize_uri
(
uri
)
def
normalize_uri
(
uri
)
uri
<<
'/'
unless
uri
.
end_with?
(
'/'
)
uri
<<
'/'
unless
uri
.
end_with?
(
'/'
)
uri
<<
'api/v3'
uri
<<
'api/v3'
end
end
end
end
...
...
lib/mattermost/team.rb
View file @
00459967
module
Mattermost
module
Mattermost
class
Team
<
Mattermost
class
Team
<
Session
# After normalization this returns an array of hashes
def
self
.
team_admin
#
body
=
get
(
'/users/initial_load'
).
parsed_response
# [{"id"=>"paf573pj9t81urupw3fanozeda", "display_name"=>"my team", <snip>}]
def
self
.
all
return
[]
unless
body
[
'team_members'
]
@all_teams
||=
get
(
'/teams/all'
).
parsed_response
.
values
team_ids
=
body
[
'team_members'
].
map
do
|
team
|
team
[
'team_id'
]
if
team
[
'roles'
].
split
.
include?
(
'team_admin'
)
end
.
compact
body
[
'teams'
].
select
do
|
team
|
team_ids
.
include?
(
team
[
'id'
])
end
end
end
end
end
end
end
spec/lib/mattermost/team_spec.rb
0 → 100644
View file @
00459967
require
'spec_helper'
describe
Mattermost
::
Team
do
let
(
:session
)
{
Mattermost
::
Session
.
new
(
'http://localhost:8065/'
,
nil
)
}
describe
'.all'
do
let
(
:result
)
{
{
id:
'abc'
,
display_name:
'team'
}
}
before
do
WebMock
.
stub_request
(
:get
,
'http://localhost:8065/api/v3/teams/all'
).
and_return
({
abc:
result
}.
to_json
)
end
xit
'gets the teams'
do
allow
(
session
).
to
receive
(
:with_session
)
{
yield
}
expect
(
described_class
.
all
).
to
eq
(
result
)
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