39
40
41
42
43
44
45
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
|
# File 'lib/bender/bot.rb', line 39
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*\?incident\s*$/
reply [
'?icident - This help text',
'?incidents - List open incidents',
'?incident NUM - Show incident',
'?incident NUM FIELD - Show incident field',
'?incident SUMMARY - File a new incident'
].join("\n")
when /^\s*\?incidents\s*$/
refresh_incidents
is = store['incidents'].map do |i|
'%s: %s' % [ i['num'], i['fields']['summary'] ]
end.join("\n")
reply is
when /^\s*\?incident\s+(\d+)\s*$/
refresh_incidents
incident = store['incidents'].select { |i| i['num'] == $1 }.first
fields = SHOW_FIELDS - %w[ summary ]
i = fields.map do |f|
val = incident['fields'][f]
if val
val = val.is_a?(Hash) ? val['name'] : val
'%s: %s' % [ f, val ]
end
end.compact
reply "%s: %s\n%s" % [
incident['key'],
incident['fields']['summary'],
i.join("\n")
]
when /^\s*\?incident\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*\?incident\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
|