# lita-jira plugin module Lita # Because we can. 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 include ::JiraHelper::Issue include ::JiraHelper::Misc include ::JiraHelper::Regex route( /^jira\s#{ISSUE_PATTERN}$/, :summary, command: true, help: { t('help.summary.syntax') => t('help.summary.desc') } ) route( /^jira\sdetails\s#{ISSUE_PATTERN}$/, :details, command: true, help: { t('help.details.syntax') => t('help.details.desc') } ) route( /^jira\scomment\son\s#{ISSUE_PATTERN}\s"(?.+)"$/, :comment, command: true, help: { t('help.comment.syntax') => t('help.comment.desc') } ) def summary(response) issue = fetch_issue(response.match_data['issue']) return response.reply(t('error.request')) unless issue response.reply("#{issue.key}: #{issue.summary}") end def details(response) issue = fetch_issue(response.match_data['issue']) return response.reply(t('error.request')) unless issue response.reply(format_issue(issue)) end def comment(response) issue = fetch_issue(response.match_data['issue']) return response.reply(t('error.request')) unless issue comment = issue.comments.build comment.save!(body: response.match_data['comment']) response.reply(t('comment.added', issue: issue.key)) end end Lita.register_handler(Jira) end end