lib/lita/handlers/jira.rb in lita-jira-0.6.0 vs lib/lita/handlers/jira.rb in lita-jira-0.7.0
- old
+ new
@@ -4,14 +4,18 @@
module Handlers
# Main handler
class Jira < Handler
namespace 'Jira'
- config :username, required: true
- config :password, required: true
- config :site, required: true
- config :context, required: true
+ config :username, required: true, type: String
+ config :password, required: true, type: String
+ config :site, required: true, type: String
+ config :context, required: false, type: String, default: ''
+ config :format, required: false, type: String, default: 'verbose'
+ config :ambient, required: false, types: [TrueClass, FalseClass], default: false
+ config :ignore, required: false, type: Array, default: []
+ config :rooms, required: false, type: Array
include ::JiraHelper::Issue
include ::JiraHelper::Misc
include ::JiraHelper::Regex
include ::JiraHelper::Utility
@@ -59,10 +63,13 @@
help: {
t('help.todo.syntax') => t('help.todo.desc')
}
)
+ # Detect ambient JIRA issues in non-command messages
+ route ISSUE_PATTERN, :ambient, command: false
+
def summary(response)
issue = fetch_issue(response.match_data['issue'])
return response.reply(t('error.request')) unless issue
response.reply(t('issue.summary', key: issue.key, summary: issue.summary))
end
@@ -103,11 +110,22 @@
return response.reply(t('myissues.empty')) unless issues.size > 0
response.reply(format_issues(issues))
end
+
+ def ambient(response)
+ return if invalid_ambient(response)
+ issue = fetch_issue(response.match_data['issue'], false)
+ response.reply(format_issue(issue)) if issue
+ end
+
+ private
+
+ def invalid_ambient(response)
+ response.message.command? || !config.ambient || config.ignore.include?(response.user.name) || (config.rooms && !config.rooms.include?(response.message.source.room))
+ end
# rubocop:enable Metrics/AbcSize
end
-
Lita.register_handler(Jira)
end
end