module Helpers
Constants
- DEFAULT_CONFIG
- QUOTES
Public Instance Methods
friendly_date(val)
click to toggle source
# File lib/bender/helpers.rb, line 121 def friendly_date val Time.parse(val).strftime('%Y-%m-%d %H:%M %Z') end
incident_link(incident)
click to toggle source
# File lib/bender/helpers.rb, line 152 def incident_link incident '<a href="%s">%s</a>' % [ incident_url(incident), incident['key'] ] end
incident_url(incident)
click to toggle source
# File lib/bender/helpers.rb, line 148 def incident_url incident config[:jira_site] + '/browse/' + incident['key'] end
normalize_date(val)
click to toggle source
# File lib/bender/helpers.rb, line 116 def normalize_date val Time.parse(val).utc.iso8601(0).sub(/Z$/, 'UTC') end
normalize_value(val)
click to toggle source
# File lib/bender/helpers.rb, line 102 def normalize_value val case val when Hash val['name'] || val['value'] || val when Array val.map { |v| v['value'] }.join(', ') when /^\d{4}\-\d{2}\-\d{2}/ '%s (%s)' % [ val, normalize_date(val) ] else val end end
one_day()
click to toggle source
# File lib/bender/helpers.rb, line 132 def one_day 24 * 60 * 60 # seconds/day end
recent_incident?(i)
click to toggle source
# File lib/bender/helpers.rb, line 126 def recent_incident? i it = Time.parse(i['fields']['created']) Time.now - it < one_day end
refresh_incidents(bot=self)
click to toggle source
# File lib/bender/helpers.rb, line 72 def refresh_incidents bot=self req_path = '/rest/api/2/search' req_params = QueryParams.encode \ jql: "project = #{config[:jira_project]} ORDER BY created ASC, priority DESC", fields: SHOW_FIELDS.keys.join(','), startAt: 0, maxResults: 1_000_000 uri = URI(config[:jira_site] + req_path + '?' + req_params) http = Net::HTTP.new uri.hostname, uri.port req = Net::HTTP::Get.new uri req.basic_auth config[:jira_user], config[:jira_pass] req['Content-Type'] = 'application/json' req['Accept'] = 'application/json' resp = http.request req begin issues = JSON.parse(resp.body)['issues'] rescue JSON::ParserError log.warn 'Could not refresh incidents!' return end bot.store['incidents'] = issues.map! do |i| i['num'] = i['key'].split('-', 2).last ; i end end
select_incident(num, refresh=true)
click to toggle source
# File lib/bender/helpers.rb, line 137 def select_incident num, refresh=true refresh_incidents if refresh store['incidents'].select { |i| i['num'] == num }.first end
short_severity(s)
click to toggle source
# File lib/bender/helpers.rb, line 143 def short_severity s s && s.include?(' - ') ? s.split(' - ', 2).first : s end