diff options
Diffstat (limited to 'lib/mattermost')
-rw-r--r-- | lib/mattermost/command.rb | 18 | ||||
-rw-r--r-- | lib/mattermost/session.rb | 14 |
2 files changed, 15 insertions, 17 deletions
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb index b6446935eb6..108a2a47a4b 100644 --- a/lib/mattermost/command.rb +++ b/lib/mattermost/command.rb @@ -1,24 +1,18 @@ module Mattermost class Command < Session - def self.all(team_id) - get("/teams/#{team_id}/commands/list_team_commands").parsed_response - end - - # params should be a hash, which supplies _at least_: - # - trigger => The slash command, no spaces, cannot start with a / - # - url => What is the URL to trigger here? - # - icon_url => Supply a link to the icon - def self.create(team_id, params) + def self.create(team_id, trigger: 'gitlab', url:, icon_url:) command = { auto_complete: true, auto_complete_desc: 'List all available commands', auto_complete_hint: '[help]', description: 'Perform common operations on GitLab', - display_name: 'GitLab', + display_name: 'GitLab Slash Commands', method: 'P', user_name: 'GitLab', - trigger: 'gitlab', - }.merge(params) + trigger: trigger, + url: url, + icon_url: icon_url + } response = post( "/teams/#{team_id}/commands/create", body: command.to_json) diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb index 15bf95a38c9..ee031541012 100644 --- a/lib/mattermost/session.rb +++ b/lib/mattermost/session.rb @@ -21,6 +21,8 @@ module Mattermost def initialize(uri, current_user) uri = normalize_uri(uri) + + # Sets the base uri for HTTParty, so we can use paths self.class.base_uri(uri) @current_resource_owner = current_user @@ -28,12 +30,14 @@ module Mattermost def with_session raise NoSessionError unless create - result = yield - destroy - result - rescue Errno::ECONNREFUSED - raise NoSessionError + begin + yield + rescue Errno::ECONNREFUSED + raise NoSessionError + ensure + destroy + end end # Next methods are needed for Doorkeeper |