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
f124b6fd
Commit
f124b6fd
authored
May 15, 2018
by
Harrison Healey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated Mattermost integration to use Mattermost API v4
parent
71dea693
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
49 additions
and
42 deletions
+49
-42
changelogs/unreleased/mattermost-api-v4.yml
changelogs/unreleased/mattermost-api-v4.yml
+5
-0
lib/mattermost/command.rb
lib/mattermost/command.rb
+1
-1
lib/mattermost/session.rb
lib/mattermost/session.rb
+2
-2
lib/mattermost/team.rb
lib/mattermost/team.rb
+3
-3
spec/lib/mattermost/command_spec.rb
spec/lib/mattermost/command_spec.rb
+5
-5
spec/lib/mattermost/session_spec.rb
spec/lib/mattermost/session_spec.rb
+3
-3
spec/lib/mattermost/team_spec.rb
spec/lib/mattermost/team_spec.rb
+25
-23
spec/models/project_services/mattermost_slash_commands_service_spec.rb
...roject_services/mattermost_slash_commands_service_spec.rb
+5
-5
No files found.
changelogs/unreleased/mattermost-api-v4.yml
0 → 100644
View file @
f124b6fd
---
title
:
Updated Mattermost integration to use API v4
merge_request
:
19043
author
:
Harrison Healey
type
:
changed
lib/mattermost/command.rb
View file @
f124b6fd
module
Mattermost
module
Mattermost
class
Command
<
Client
class
Command
<
Client
def
create
(
params
)
def
create
(
params
)
response
=
session_post
(
"/api/v3/teams/
#{
params
[
:team_id
]
}
/commands/create"
,
response
=
session_post
(
'/api/v4/commands'
,
body:
params
.
to_json
)
body:
params
.
to_json
)
response
[
'token'
]
response
[
'token'
]
...
...
lib/mattermost/session.rb
View file @
f124b6fd
...
@@ -112,7 +112,7 @@ module Mattermost
...
@@ -112,7 +112,7 @@ module Mattermost
end
end
def
destroy
def
destroy
post
(
'/api/v
3
/users/logout'
)
post
(
'/api/v
4
/users/logout'
)
end
end
def
oauth_uri
def
oauth_uri
...
@@ -120,7 +120,7 @@ module Mattermost
...
@@ -120,7 +120,7 @@ module Mattermost
@oauth_uri
=
nil
@oauth_uri
=
nil
response
=
get
(
"/api/v3/oauth/gitlab/login"
,
follow_redirects:
false
)
response
=
get
(
'/oauth/gitlab/login'
,
follow_redirects:
false
,
format:
'text/html'
)
return
unless
(
300
...
400
)
===
response
.
code
return
unless
(
300
...
400
)
===
response
.
code
redirect_uri
=
response
.
headers
[
'location'
]
redirect_uri
=
response
.
headers
[
'location'
]
...
...
lib/mattermost/team.rb
View file @
f124b6fd
module
Mattermost
module
Mattermost
class
Team
<
Client
class
Team
<
Client
# Returns
**all** teams for an admin
# Returns
all teams that the current user is a member of
def
all
def
all
session_get
(
'/api/v3/teams/all'
).
values
session_get
(
"/api/v4/users/me/teams"
)
end
end
# Creates a team on the linked Mattermost instance, the team admin will be the
# Creates a team on the linked Mattermost instance, the team admin will be the
# `current_user` passed to the Mattermost::Client instance
# `current_user` passed to the Mattermost::Client instance
def
create
(
name
:,
display_name
:,
type
:)
def
create
(
name
:,
display_name
:,
type
:)
session_post
(
'/api/v
3/teams/create
'
,
body:
{
session_post
(
'/api/v
4/teams
'
,
body:
{
name:
name
,
name:
name
,
display_name:
display_name
,
display_name:
display_name
,
type:
type
type:
type
...
...
spec/lib/mattermost/command_spec.rb
View file @
f124b6fd
...
@@ -21,13 +21,13 @@ describe Mattermost::Command do
...
@@ -21,13 +21,13 @@ describe Mattermost::Command do
context
'for valid trigger word'
do
context
'for valid trigger word'
do
before
do
before
do
stub_request
(
:post
,
'http://mattermost.example.com/api/v
3/teams/abc/commands/create
'
)
stub_request
(
:post
,
'http://mattermost.example.com/api/v
4/commands
'
)
.
with
(
body:
{
.
with
(
body:
{
team_id:
'abc'
,
team_id:
'abc'
,
trigger:
'gitlab'
trigger:
'gitlab'
}.
to_json
)
}.
to_json
)
.
to_return
(
.
to_return
(
status:
20
0
,
status:
20
1
,
headers:
{
'Content-Type'
=>
'application/json'
},
headers:
{
'Content-Type'
=>
'application/json'
},
body:
{
token:
'token'
}.
to_json
body:
{
token:
'token'
}.
to_json
)
)
...
@@ -40,16 +40,16 @@ describe Mattermost::Command do
...
@@ -40,16 +40,16 @@ describe Mattermost::Command do
context
'for error message'
do
context
'for error message'
do
before
do
before
do
stub_request
(
:post
,
'http://mattermost.example.com/api/v
3/teams/abc/commands/create
'
)
stub_request
(
:post
,
'http://mattermost.example.com/api/v
4/commands
'
)
.
to_return
(
.
to_return
(
status:
5
00
,
status:
4
00
,
headers:
{
'Content-Type'
=>
'application/json'
},
headers:
{
'Content-Type'
=>
'application/json'
},
body:
{
body:
{
id:
'api.command.duplicate_trigger.app_error'
,
id:
'api.command.duplicate_trigger.app_error'
,
message:
'This trigger word is already in use. Please choose another word.'
,
message:
'This trigger word is already in use. Please choose another word.'
,
detailed_error:
''
,
detailed_error:
''
,
request_id:
'obc374man7bx5r3dbc1q5qhf3r'
,
request_id:
'obc374man7bx5r3dbc1q5qhf3r'
,
status_code:
5
00
status_code:
4
00
}.
to_json
}.
to_json
)
)
end
end
...
...
spec/lib/mattermost/session_spec.rb
View file @
f124b6fd
...
@@ -22,8 +22,8 @@ describe Mattermost::Session, type: :request do
...
@@ -22,8 +22,8 @@ describe Mattermost::Session, type: :request do
let
(
:location
)
{
'http://location.tld'
}
let
(
:location
)
{
'http://location.tld'
}
let
(
:cookie_header
)
{
'MMOAUTH=taskik8az7rq8k6rkpuas7htia; Path=/;'
}
let
(
:cookie_header
)
{
'MMOAUTH=taskik8az7rq8k6rkpuas7htia; Path=/;'
}
let!
(
:stub
)
do
let!
(
:stub
)
do
WebMock
.
stub_request
(
:get
,
"
#{
mattermost_url
}
/
api/v3/
oauth/gitlab/login"
)
WebMock
.
stub_request
(
:get
,
"
#{
mattermost_url
}
/oauth/gitlab/login"
)
.
to_return
(
headers:
{
'location'
=>
location
,
'Set-Cookie'
=>
cookie_header
},
status:
30
7
)
.
to_return
(
headers:
{
'location'
=>
location
,
'Set-Cookie'
=>
cookie_header
},
status:
30
2
)
end
end
context
'without oauth uri'
do
context
'without oauth uri'
do
...
@@ -76,7 +76,7 @@ describe Mattermost::Session, type: :request do
...
@@ -76,7 +76,7 @@ describe Mattermost::Session, type: :request do
end
end
end
end
WebMock
.
stub_request
(
:post
,
"
#{
mattermost_url
}
/api/v
3
/users/logout"
)
WebMock
.
stub_request
(
:post
,
"
#{
mattermost_url
}
/api/v
4
/users/logout"
)
.
to_return
(
headers:
{
Authorization
:
'token thisworksnow'
},
status:
200
)
.
to_return
(
headers:
{
Authorization
:
'token thisworksnow'
},
status:
200
)
end
end
...
...
spec/lib/mattermost/team_spec.rb
View file @
f124b6fd
...
@@ -12,26 +12,28 @@ describe Mattermost::Team do
...
@@ -12,26 +12,28 @@ describe Mattermost::Team do
describe
'#all'
do
describe
'#all'
do
subject
{
described_class
.
new
(
nil
).
all
}
subject
{
described_class
.
new
(
nil
).
all
}
let
(
:test_team
)
do
{
"id"
=>
"xiyro8huptfhdndadpz8r3wnbo"
,
"create_at"
=>
1482174222155
,
"update_at"
=>
1482174222155
,
"delete_at"
=>
0
,
"display_name"
=>
"chatops"
,
"name"
=>
"chatops"
,
"email"
=>
"admin@example.com"
,
"type"
=>
"O"
,
"company_name"
=>
""
,
"allowed_domains"
=>
""
,
"invite_id"
=>
"o4utakb9jtb7imctdfzbf9r5ro"
,
"allow_open_invite"
=>
false
}
end
context
'for valid request'
do
context
'for valid request'
do
let
(
:response
)
do
let
(
:response
)
{
[
test_team
]
}
{
"xiyro8huptfhdndadpz8r3wnbo"
=>
{
"id"
=>
"xiyro8huptfhdndadpz8r3wnbo"
,
"create_at"
=>
1482174222155
,
"update_at"
=>
1482174222155
,
"delete_at"
=>
0
,
"display_name"
=>
"chatops"
,
"name"
=>
"chatops"
,
"email"
=>
"admin@example.com"
,
"type"
=>
"O"
,
"company_name"
=>
""
,
"allowed_domains"
=>
""
,
"invite_id"
=>
"o4utakb9jtb7imctdfzbf9r5ro"
,
"allow_open_invite"
=>
false
}
}
end
before
do
before
do
stub_request
(
:get
,
'http://mattermost.example.com/api/v
3/teams/all
'
)
stub_request
(
:get
,
'http://mattermost.example.com/api/v
4/users/me/teams
'
)
.
to_return
(
.
to_return
(
status:
200
,
status:
200
,
headers:
{
'Content-Type'
=>
'application/json'
},
headers:
{
'Content-Type'
=>
'application/json'
},
...
@@ -39,14 +41,14 @@ describe Mattermost::Team do
...
@@ -39,14 +41,14 @@ describe Mattermost::Team do
)
)
end
end
it
'returns
a token
'
do
it
'returns
teams
'
do
is_expected
.
to
eq
(
response
.
values
)
is_expected
.
to
eq
(
response
)
end
end
end
end
context
'for error message'
do
context
'for error message'
do
before
do
before
do
stub_request
(
:get
,
'http://mattermost.example.com/api/v
3/teams/all
'
)
stub_request
(
:get
,
'http://mattermost.example.com/api/v
4/users/me/teams
'
)
.
to_return
(
.
to_return
(
status:
500
,
status:
500
,
headers:
{
'Content-Type'
=>
'application/json'
},
headers:
{
'Content-Type'
=>
'application/json'
},
...
@@ -89,9 +91,9 @@ describe Mattermost::Team do
...
@@ -89,9 +91,9 @@ describe Mattermost::Team do
end
end
before
do
before
do
stub_request
(
:post
,
"http://mattermost.example.com/api/v
3/teams/create
"
)
stub_request
(
:post
,
"http://mattermost.example.com/api/v
4/teams
"
)
.
to_return
(
.
to_return
(
status:
20
0
,
status:
20
1
,
body:
response
.
to_json
,
body:
response
.
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
headers:
{
'Content-Type'
=>
'application/json'
}
)
)
...
@@ -104,7 +106,7 @@ describe Mattermost::Team do
...
@@ -104,7 +106,7 @@ describe Mattermost::Team do
context
'for existing team'
do
context
'for existing team'
do
before
do
before
do
stub_request
(
:post
,
'http://mattermost.example.com/api/v
3/teams/create
'
)
stub_request
(
:post
,
'http://mattermost.example.com/api/v
4/teams
'
)
.
to_return
(
.
to_return
(
status:
400
,
status:
400
,
headers:
{
'Content-Type'
=>
'application/json'
},
headers:
{
'Content-Type'
=>
'application/json'
},
...
...
spec/models/project_services/mattermost_slash_commands_service_spec.rb
View file @
f124b6fd
...
@@ -25,7 +25,7 @@ describe MattermostSlashCommandsService do
...
@@ -25,7 +25,7 @@ describe MattermostSlashCommandsService do
context
'the requests succeeds'
do
context
'the requests succeeds'
do
before
do
before
do
stub_request
(
:post
,
'http://mattermost.example.com/api/v
3/teams/abc/commands/create
'
)
stub_request
(
:post
,
'http://mattermost.example.com/api/v
4/commands
'
)
.
with
(
body:
{
.
with
(
body:
{
team_id:
'abc'
,
team_id:
'abc'
,
trigger:
'gitlab'
,
trigger:
'gitlab'
,
...
@@ -59,7 +59,7 @@ describe MattermostSlashCommandsService do
...
@@ -59,7 +59,7 @@ describe MattermostSlashCommandsService do
context
'an error is received'
do
context
'an error is received'
do
before
do
before
do
stub_request
(
:post
,
'http://mattermost.example.com/api/v
3/teams/abc/commands/create
'
)
stub_request
(
:post
,
'http://mattermost.example.com/api/v
4/commands
'
)
.
to_return
(
.
to_return
(
status:
500
,
status:
500
,
headers:
{
'Content-Type'
=>
'application/json'
},
headers:
{
'Content-Type'
=>
'application/json'
},
...
@@ -89,11 +89,11 @@ describe MattermostSlashCommandsService do
...
@@ -89,11 +89,11 @@ describe MattermostSlashCommandsService do
context
'the requests succeeds'
do
context
'the requests succeeds'
do
before
do
before
do
stub_request
(
:get
,
'http://mattermost.example.com/api/v
3/teams/all
'
)
stub_request
(
:get
,
'http://mattermost.example.com/api/v
4/users/me/teams
'
)
.
to_return
(
.
to_return
(
status:
200
,
status:
200
,
headers:
{
'Content-Type'
=>
'application/json'
},
headers:
{
'Content-Type'
=>
'application/json'
},
body:
{
'list'
=>
true
}
.
to_json
body:
[{
id:
'test_team_id'
}]
.
to_json
)
)
end
end
...
@@ -104,7 +104,7 @@ describe MattermostSlashCommandsService do
...
@@ -104,7 +104,7 @@ describe MattermostSlashCommandsService do
context
'an error is received'
do
context
'an error is received'
do
before
do
before
do
stub_request
(
:get
,
'http://mattermost.example.com/api/v
3/teams/all
'
)
stub_request
(
:get
,
'http://mattermost.example.com/api/v
4/users/me/teams
'
)
.
to_return
(
.
to_return
(
status:
500
,
status:
500
,
headers:
{
'Content-Type'
=>
'application/json'
},
headers:
{
'Content-Type'
=>
'application/json'
},
...
...
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