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

Commit 34ef8cb

Browse files
committed
added script scrumnotes - take notes on a scrum daily meeting
1 parent a5c2d7b commit 34ef8cb

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

src/scripts/scrumnotes.coffee

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Description:
2+
# Take notes on scrum daily meetings
3+
#
4+
# Dependencies:
5+
# None
6+
#
7+
# Configuration:
8+
# HUBOT_SCRUMNOTES_PATH - if set, folder where daily notes should be saved as json files (otherwise they just stay on robot brain)
9+
#
10+
# Commands:
11+
# hubot take scrum notes - Starts taking notes from all users in the room (records all messages starting with yesterday, today, tomorrow, sun, mon, tue, wed, thu, fri, sat, blocking)
12+
# hubot stop taking notes - Stops taking scrum notes (if a path is configured saves day notes to a json file)
13+
# hubot scrum notes - shows scrum notes taken so far
14+
# hubot are you taking notes? - hubot indicates if he's currently taking notes
15+
#
16+
# Author:
17+
# benjamin eidelman
18+
19+
env = process.env
20+
fs = require('fs')
21+
22+
module.exports = (robot) ->
23+
24+
# rooms where hubot is hearing for notes
25+
hearingRooms = {}
26+
27+
getDate = ->
28+
today = new Date()
29+
dd = today.getDate()
30+
mm = today.getMonth()+1
31+
yyyy = today.getFullYear()
32+
if (dd<10)
33+
dd='0'+dd
34+
if (mm<10)
35+
mm='0'+mm
36+
return yyyy+'-'+mm+'-'+dd
37+
38+
listener = null
39+
40+
startHearing = ->
41+
42+
if (listener)
43+
return
44+
45+
listenersCount = robot.hear /^(yesterday|today|tomorrow|blocking|sun|mon|tue|wed|thu|fri|sat)[ :\-](.*)$/i, (msg) ->
46+
47+
if (!hearingRooms[msg.message.user.room])
48+
return
49+
50+
today = getDate()
51+
name = msg.message.user.name;
52+
53+
robot.brain.data.scrumNotes ?= {};
54+
notes = robot.brain.data.scrumNotes[today] ?= {};
55+
notes[name] ?= {};
56+
57+
key = msg.match[1].toLowerCase();
58+
59+
notes[name][key] ?= [];
60+
notes[name][key].push(msg.match[2]);
61+
62+
listener = robot.listeners[listenersCount - 1]
63+
64+
stopHearing = ->
65+
66+
if (!listener)
67+
return
68+
69+
listenerIndex = -1
70+
for list, i in robot.listeners
71+
if list is listener
72+
listenerIndex = i
73+
break
74+
if (listenerIndex >= 0)
75+
setTimeout ->
76+
robot.listeners.splice(i, 1)
77+
, 0
78+
listener = null
79+
80+
mkdir = (path, root) ->
81+
82+
dirs = path.split('/')
83+
dir = dirs.shift()
84+
root = (root||'')+dir+'/'
85+
86+
try
87+
fs.mkdirSync(root)
88+
catch e
89+
# dir wasn't made, something went wrong
90+
if (!fs.statSync(root).isDirectory())
91+
throw new Error(e)
92+
93+
return !dirs.length || mkdir(dirs.join('/'), root)
94+
95+
robot.respond /(?:show )?scrum notes/i, (msg) ->
96+
97+
today = getDate()
98+
99+
notes = robot.brain.data.scrumNotes?[today]
100+
101+
if !notes
102+
msg.reply('no notes so far');
103+
else
104+
msg.reply(JSON.stringify(robot.brain.data.scrumNotes?[today], null, 2));
105+
106+
robot.respond /take scrum notes/i, (msg) ->
107+
108+
startHearing()
109+
110+
hearingRooms[msg.message.user.room] = true
111+
112+
msg.reply('taking scrum notes, I hear you');
113+
114+
robot.respond /are you taking (scrum )?notes\?/i, (msg) ->
115+
116+
takingNotes = !!hearingRooms[msg.message.user.room]
117+
118+
msg.reply(if takingNotes then 'Yes, I\'m taking scrum notes' else 'No, I\'m not taking scrum notes')
119+
120+
robot.respond /stop taking (?:scrum )?notes/i, (msg) ->
121+
122+
delete hearingRooms[msg.message.user.room];
123+
124+
today = getDate()
125+
notes = robot.brain.data.scrumNotes?[today]
126+
count = if notes then Object.keys(notes).length else 0
127+
status = if count > 0 then "I got notes from #{count} user#{if count>1 then 's' else ''} today" else "I got no notes today"
128+
129+
msg.reply("not taking scrum notes anymore (#{status})");
130+
131+
if (Object.keys(hearingRooms).length < 1)
132+
stopHearing()
133+
134+
saveTo = process.env.HUBOT_SCRUMNOTES_PATH
135+
136+
if (saveTo)
137+
mkdir(saveTo + '/scrumnotes')
138+
fs.writeFileSync(saveTo + '/scrumnotes/' + today + '.json', JSON.stringify(notes, null, 2))
139+
msg.send('scrum notes saved at: /scrumnotes/' + today + '.json')
140+

0 commit comments

Comments
 (0)