Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 0fdc77d

Browse files
committed
Merge pull request #301 from gabeguz/master
Simple good/bad tracking for sprint retrospective
2 parents 32d7f21 + 167c9a6 commit 0fdc77d

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

src/scripts/goodbad.coffee

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Allows good and bad things to be added to Hubot for sprint retrospective
2+
# Based on tasks.coffee
3+
#
4+
# good <good thing> - Add something good that happened this sprint
5+
# bad <bad thing> - Add something bad that happened this sprint
6+
# goodlist - List all good things that happened
7+
# badlist - List all bad things that happened
8+
# gooddel - Delete all good things that happened
9+
# baddel - Delete all bad things that happened
10+
11+
class GoodBad
12+
constructor: (@robot) ->
13+
@goodcache = []
14+
@badcache = []
15+
@robot.brain.on 'loaded', =>
16+
if @robot.brain.data.good
17+
@goodcache = @robot.brain.data.good
18+
if @robot.brain.data.bad
19+
@badcache = @robot.brain.data.bad
20+
21+
nextGoodNum: ->
22+
maxGoodNum = if @goodcache.length then Math.max.apply(Math,@goodcache.map (n) -> n.num) else 0
23+
maxGoodNum++
24+
maxGoodNum
25+
nextBadNum: ->
26+
maxBadNum = if @badcache.length then Math.max.apply(Math,@badcache.map (n) -> n.num) else 0
27+
maxBadNum++
28+
maxBadNum
29+
goodlist: -> @goodcache
30+
badlist: -> @badcache
31+
good: (goodString) ->
32+
goodthing = {num: @nextGoodNum(), good: goodString}
33+
@goodcache.push goodthing
34+
@robot.brain.data.good = @goodcache
35+
goodthing
36+
bad: (badString) ->
37+
badthing = {num: @nextBadNum(), bad: badString}
38+
@badcache.push badthing
39+
@robot.brain.data.bad = @badcache
40+
badthing
41+
gooddel: ->
42+
@goodcache = []
43+
@robot.brain.data.good = @goodcache
44+
baddel: ->
45+
@badcache = []
46+
@robot.brain.data.bad = @badcache
47+
48+
module.exports = (robot) ->
49+
goodbad = new GoodBad robot
50+
51+
robot.respond /(good) (.+?)$/i, (msg) ->
52+
good = goodbad.good msg.match[2]
53+
msg.send "The sprint is thriving!"
54+
55+
robot.respond /(bad) (.+?)$/i, (msg) ->
56+
bad = goodbad.bad msg.match[2]
57+
msg.send "The sprint is festering..."
58+
59+
robot.respond /(goodlist)/i, (msg) ->
60+
if goodbad.goodlist().length > 0
61+
response = ""
62+
for good, num in goodbad.goodlist()
63+
response += "##{good.num} - #{good.good}\n"
64+
msg.send response
65+
else
66+
msg.send "Nothing good happened."
67+
68+
robot.respond /(badlist)/i, (msg) ->
69+
if goodbad.badlist().length > 0
70+
response = ""
71+
for bad, num in goodbad.badlist()
72+
response += "##{bad.num} - #{bad.bad}\n"
73+
msg.send response
74+
else
75+
msg.send "Nothing bad happened."
76+
77+
robot.respond /(gooddel)/i, (msg) ->
78+
goodbad.gooddel()
79+
msg.send "Good things deleted."
80+
81+
robot.respond /(baddel)/i, (msg) ->
82+
goodbad.baddel()
83+
msg.send "Bad things deleted."

0 commit comments

Comments
 (0)