Class: BenderBot

Inherits:
Object
  • Object
show all
Includes:
Bot::Plugin
Defined in:
lib/bender/bot.rb

Constant Summary collapse

JARO =
FuzzyStringMatch::JaroWinkler.create :native
SHOW_FIELDS =
{
  'summary' => 'Summary',
  'description' => 'Description',
  'customfield_11250' => 'Severity',
  'customfield_11251' => 'Impact Started',
  'customfield_11252' => 'Impact Ended',
  'customfield_11253' => 'Reported By',
  'customfield_11254' => 'Services Affected',
  'customfield_11255' => 'Cause',
  'status' => 'Status',
  'created' => 'Created',
  'updated' => 'Updated'
}

Instance Method Summary collapse

Instance Method Details

#handle(time, sender, message) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/bender/bot.rb', line 46

def handle time, sender, message
  case message


  when /^\s*\?opts\s*$/
    reply options.inspect

  when /^\s*\?whoami\s*$/
    u = user_where name: sender
    reply '%s: %s (%s)' % [ u[:nick], u[:name], u[:email] ]

  when /^\s*\?lookup\s+(.+)\s*$/
    u = user_where(name: $1) || user_where(nick: $1)
    reply '%s: %s (%s)' % [ u[:nick], u[:name], u[:email] ]

  when /^\s*\?inc\s*$/
    reply [
      '?inc - This help text',
      '/inc - List open incidents',
      '/inc NUM - Show incident details',
      '/inc close NUM - Close an indident',
      '/inc SEVERITY SUMMARY - File a new incident',
      '/inc summary - Summarize recent indicents'
    ].join("\n")

  when /^\s*\/inc\s*$/
    refresh_incidents

    is = store['incidents'].map do |i|
      '%s: %s' % [ i['num'], i['fields']['summary'] ]
    end.join("\n")

    reply is

  when /^\s*\/inc\s+summary\s*$/
    # TODO
    reply "Sorry, I haven't been programmed for that yet!"

  when /^\s*\/inc\s+(\d+)\s*$/
    refresh_incidents
    incident = store['incidents'].select { |i| i['num'] == $1 }.first

    fields = SHOW_FIELDS.keys - %w[ summary ]

    i = fields.map do |f|
      val = incident['fields'][f]
      if val
        key = SHOW_FIELDS[f]
        val = normalize_value val
        '%s: %s' % [ key, val ]
      end
    end.compact

    reply "%s: %s\n%s" % [
      incident['key'],
      incident['fields']['summary'],
      i.join("\n")
    ]

  when /^\s*\/inc\s+close\s+(\d+)\s*$/
    # TODO
    reply "Sorry, I haven't been programmed for that yet!"

  when /^\s*\/inc\s+(\d+)\s+(.*?)\s*$/
    refresh_incidents
    incident = store['incidents'].select { |i| i['num'] == $1 }.first
    val = incident['fields'][$2]
    val = val.is_a?(Hash) ? val['name'] : val
    reply val

  when /^\s*\/inc\s+(.*?)\s*$/
    user = user_where name: sender
    data = {
      fields: {
        project: { key: options.jira_project },
        issuetype: { name: options.jira_type },
        reporter: { name: user[:nick] },
        summary: $1
      }
    }

    reply file_incident(data)
  end

  return true
end