lib/lita/handlers/jira.rb in lita-jira-0.8.0 vs lib/lita/handlers/jira.rb in lita-jira-0.8.1
- old
+ new
@@ -14,10 +14,11 @@
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
config :use_ssl, required: false, types: [TrueClass, FalseClass], default: true
+ config :points_field, required: false, type: String
include ::JiraHelper::Issue
include ::JiraHelper::Misc
include ::JiraHelper::Regex
include ::JiraHelper::Utility
@@ -65,10 +66,19 @@
help: {
t('help.todo.syntax') => t('help.todo.desc')
}
)
+ route(
+ /^jira\spoint\s#{ISSUE_PATTERN}\sas\s#{POINTS_PATTERN}$/,
+ :point,
+ command: true,
+ help: {
+ t('help.point.syntax') => t('help.point.desc')
+ }
+ )
+
# Detect ambient JIRA issues in non-command messages
route AMBIENT_PATTERN, :ambient, command: false
def summary(response)
issue = fetch_issue(response.match_data['issue'])
@@ -97,10 +107,17 @@
return response.reply(t('error.request')) unless issue
response.reply(t('issue.created', key: issue.key))
end
# rubocop:disable Metrics/AbcSize
+ def point(response)
+ return response.reply(t('error.field_undefined')) if config.points_field.blank?
+ issue = fetch_issue(response.match_data['issue'])
+ return response.reply(t('error.request')) unless issue
+ set_points_on_issue(issue, response)
+ end
+
def myissues(response)
return response.reply(t('error.not_identified')) unless user_stored?(response.user)
begin
issues = fetch_issues("assignee = '#{get_email(response.user)}' AND status not in (Closed)")
@@ -127,9 +144,19 @@
response.message.command? || !config.ambient || ignored?(response.user) || (config.rooms && !config.rooms.include?(response.message.source.room))
end
def ignored?(user)
config.ignore.include?(user.id) || config.ignore.include?(user.mention_name) || config.ignore.include?(user.name)
+ end
+
+ def set_points_on_issue(issue, response)
+ points = response.match_data['points']
+ begin
+ issue.save!(fields: { config.points_field.to_sym => points.to_i })
+ rescue
+ return response.reply(t('error.unable_to_point'))
+ end
+ response.reply(t('point.added', issue: issue.key, points: points))
end
# rubocop:enable Metrics/AbcSize
end
# rubocop:enable Metrics/ClassLength
Lita.register_handler(Jira)