whois_slacking 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -2
- data/lib/whois_slacking.rb +30 -14
- data/lib/whois_slacking/version.rb +1 -1
- data/spec/client_spec.rb +29 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c12a90fd78ffc81ec00d90aa15e50c61bb53041
|
4
|
+
data.tar.gz: 95ae875b987913537d79c40de5676a8ea3df0392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b343af7a6be9858de23f6285a7a9d33729c7b16982580155d871493fb978d4221c52bc5ed2e0b84db0ab52ce28b4a8fe8bcd964ddacd572613af6a495a66e2d6
|
7
|
+
data.tar.gz: 4d4e91bc2a20bedff2b746a9335371034f17b94ff64998932eb2b19bec54e87dc9548631d6c8625d438fa373b80959bab328776b8dc92a6c566d2432aa025cd7
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -21,9 +21,10 @@ gem install whois_slacking
|
|
21
21
|
```
|
22
22
|
Update the .env file with the proper tokens
|
23
23
|
|
24
|
-
|
24
|
+
Call the slackcron.rb file in the base directory (or create your own cronscript).
|
25
|
+
Create a cronjob that calls the script e.g.:
|
25
26
|
```
|
26
|
-
|
27
|
+
0 8 * * * /bin/bash -l -c 'rvm use 2.1.5 ; . $HOME/path-to-env/.env ; ruby $HOME/path-to-cronscript/slackcron.rb > /tmp/slackcron.log'
|
27
28
|
```
|
28
29
|
|
29
30
|
## Contribution
|
data/lib/whois_slacking.rb
CHANGED
@@ -61,7 +61,7 @@ module WhoIsSlacking
|
|
61
61
|
task.current_state != 'unestimated' &&
|
62
62
|
task.current_state != 'unscheduled' &&
|
63
63
|
task.current_state != 'accepted'
|
64
|
-
WhoIsSlacking::DataTools.save_task(project_object.name, task.id, task.name, task.owned_by, task.current_state, task.accepted_at )
|
64
|
+
WhoIsSlacking::DataTools.save_task(project_object.name, task.id, task.name, task.owned_by, task.current_state, task.accepted_at, task.url )
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -124,17 +124,18 @@ module WhoIsSlacking
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
def self.save_task(project, task_id, task, user, current_state, accepted_at, options={})
|
127
|
+
def self.save_task(project, task_id, task, user, current_state, accepted_at, url, options={})
|
128
128
|
|
129
129
|
# dont use accepted_at
|
130
130
|
accepted_at = accepted_at
|
131
|
+
url = url
|
131
132
|
created_dt = DateTime.now.to_s
|
132
133
|
start_dt = DateTime.now.to_s
|
133
134
|
updated_dt = created_dt
|
134
135
|
current_state = current_state
|
135
136
|
active = true
|
136
137
|
message = nil
|
137
|
-
task_entity = {project: project, task_id: task_id, task: task, user: user, current_state: current_state, active: active, start_dt: start_dt, created_dt: created_dt, accepted_at: accepted_at, updated_dt: updated_dt}
|
138
|
+
task_entity = {project: project, task_id: task_id, task: task, user: user, current_state: current_state, url: url, active: active, start_dt: start_dt, created_dt: created_dt, accepted_at: accepted_at, updated_dt: updated_dt}
|
138
139
|
# initialize datastore type
|
139
140
|
store = whois_store
|
140
141
|
mutex = Moneta::Mutex.new(store, 'moneta')
|
@@ -143,7 +144,9 @@ module WhoIsSlacking
|
|
143
144
|
entity_exists = store[mkey]
|
144
145
|
|
145
146
|
if entity_exists &&
|
146
|
-
entity_exists[:current_state] != 'finished'
|
147
|
+
entity_exists[:current_state] != 'finished' &&
|
148
|
+
entity_exists[:current_state] != 'delivered' &&
|
149
|
+
entity_exists[:current_state] != 'accepted' # -- if task/username combo exists and is not delivered/finished in db
|
147
150
|
# -- calculate how long (realtime) the task has been worked on in days (.5, 1.5 etc)
|
148
151
|
# -- update time on task
|
149
152
|
# -- save who started task
|
@@ -152,45 +155,58 @@ module WhoIsSlacking
|
|
152
155
|
# keep created at date
|
153
156
|
|
154
157
|
start_dt = entity_exists[:start_dt].to_datetime
|
158
|
+
puts "start_dt in db was #{start_dt}"
|
155
159
|
|
156
160
|
days_worked = TimeDifference.between(DateTime.now, start_dt).in_days
|
157
161
|
if days_worked >= 1.0
|
158
|
-
message = "*#{user} has spent
|
162
|
+
message = "*#{user}* has spent *#{days_worked.to_i} days* working on <#{url}|#{task}>"
|
159
163
|
else # show hours instead
|
160
|
-
hours_worked = TimeDifference.between(DateTime.now, start_dt).in_hours
|
161
|
-
message = "*#{user} has spent #{hours_worked.to_i} hours working on #{task}*"
|
164
|
+
# hours_worked = TimeDifference.between(DateTime.now, start_dt).in_hours
|
165
|
+
# message = "*#{user} has spent #{hours_worked.to_i} hours working on #{task}*"
|
166
|
+
message = "*#{user}* has spent *less than a day* working on <#{url}|#{task}>"
|
162
167
|
end
|
163
168
|
# keep the created dt and start_dt
|
164
169
|
created_dt = entity_exists[:created_dt]
|
165
170
|
start_dt = entity_exists[:start_dt].to_datetime
|
166
171
|
task_entity["created_dt"] = created_dt
|
167
|
-
task_entity["start_dt"] = start_dt
|
172
|
+
task_entity["start_dt"] = start_dt.to_s
|
173
|
+
puts "start_dt in db will be #{start_dt}"
|
168
174
|
store[mkey] = task_entity
|
169
175
|
|
176
|
+
elsif entity_exists && entity_exists[:current_state] == 'delivered' && current_state == 'delivered'
|
177
|
+
start_dt = entity_exists[:start_dt].to_datetime
|
178
|
+
puts "start_dt in db for delivered state was #{start_dt}"
|
179
|
+
|
180
|
+
days_worked = TimeDifference.between(DateTime.now, start_dt).in_days
|
181
|
+
if days_worked >= 1.0
|
182
|
+
message = "Task <#{url}|#{task}> has been in a *delivered state for #{days_worked.to_i} days*"
|
183
|
+
else
|
184
|
+
message = "Task <#{url}|#{task}> has been in a *delivered state for less than a day*"
|
185
|
+
end
|
170
186
|
elsif entity_exists && entity_exists[:current_state] == 'finished'
|
171
|
-
# don't do anything
|
187
|
+
# don't do anything if entity already exists as delivered
|
172
188
|
else # -- if task/username combo does not exist in db
|
173
189
|
# -- save project/task/user
|
174
190
|
# -- save when task was started
|
175
191
|
# -- save who started task
|
176
192
|
store[mkey] = task_entity
|
177
193
|
|
178
|
-
if current_state != "finished" # -- if task is not-completed in pivotal
|
194
|
+
if current_state != "finished" && current_state != "delivered" # -- if task is not-completed in pivotal and is not in db
|
179
195
|
# -- save status as status not-completed
|
180
196
|
# -- publish message task/user started today
|
181
197
|
# -- "Today Johnny started 'As a user I should be able to log in'"
|
182
|
-
message = "
|
198
|
+
message = "Now tracking *#{user}* as doing <#{url}|#{task}>"
|
183
199
|
|
184
|
-
elsif current_state == "finished" # -- if task is completed in pivotal
|
200
|
+
elsif current_state == "finished" # -- if task is completed in pivotal and is not in db
|
185
201
|
# -- save status as status completed
|
186
202
|
# -- publish message task/user started today
|
187
203
|
# -- "Today Johnny completed 'As a user I should be able to log in'"
|
188
|
-
message = "
|
204
|
+
message = "Today *#{user} finished* <#{url}|#{task}> and it is *waiting to be delivered*"
|
189
205
|
elsif current_state == "delivered" # -- if task is completed in pivotal
|
190
206
|
# -- save status as status completed
|
191
207
|
# -- publish message task/user started today
|
192
208
|
# -- "Today Johnny completed 'As a user I should be able to log in'"
|
193
|
-
message = "
|
209
|
+
message = "Today *#{user} delivered* <#{url}|#{task}> and it is *waiting to be accepted*"
|
194
210
|
end
|
195
211
|
|
196
212
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -51,6 +51,10 @@ describe "json client" do
|
|
51
51
|
def current_state
|
52
52
|
'started'
|
53
53
|
end
|
54
|
+
|
55
|
+
def url
|
56
|
+
'https://www.pivotaltracker.com/story/show/98984232'
|
57
|
+
end
|
54
58
|
|
55
59
|
def accepted_dt
|
56
60
|
DateTime.now
|
@@ -88,7 +92,7 @@ describe "json client" do
|
|
88
92
|
end
|
89
93
|
|
90
94
|
it "should save a project task" do
|
91
|
-
WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)
|
95
|
+
WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt, url)
|
92
96
|
expect(@store.key?(whois_key)).to eql true
|
93
97
|
end
|
94
98
|
|
@@ -101,17 +105,22 @@ describe "json client" do
|
|
101
105
|
expect(WhoIsSlacking::SlackWrapper.post_to_slack(message)["ok"]).to eql true
|
102
106
|
end
|
103
107
|
|
104
|
-
it "should post to slack '
|
105
|
-
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)
|
106
|
-
.fetch("message", nil).fetch("text", nil)) .to eql "*
|
108
|
+
it "should post to slack 'Now tracking xx as doing xxx' when a non completed task exists in pivotal but not in the db" do
|
109
|
+
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt, url)
|
110
|
+
.fetch("message", nil).fetch("text", nil)) .to eql "Now tracking *user* as doing <https://www.pivotaltracker.com/story/show/98984232|task>"
|
107
111
|
end
|
108
112
|
|
109
113
|
it "should post to slack 'Today xx completed xxx' when a completed task exists in pivotal but not in the db" do
|
110
114
|
current_state = 'finished'
|
111
|
-
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)
|
112
|
-
.fetch("message", nil).fetch("text", nil)) .to eql "
|
115
|
+
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt, url)
|
116
|
+
.fetch("message", nil).fetch("text", nil)) .to eql "Today *user finished* <https://www.pivotaltracker.com/story/show/98984232|task> and it is *waiting to be delivered*"
|
113
117
|
end
|
114
118
|
|
119
|
+
it "should post to slack 'Today xx delivered xxx' when a delivered task exists in pivotal but not in the db" do
|
120
|
+
current_state = 'delivered'
|
121
|
+
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt, url)
|
122
|
+
.fetch("message", nil).fetch("text", nil)) .to eql "Today *user delivered* <https://www.pivotaltracker.com/story/show/98984232|task> and it is *waiting to be accepted*"
|
123
|
+
end
|
115
124
|
|
116
125
|
def direct_save(start_dt = (DateTime.now - 1), cstate = current_state)
|
117
126
|
accepted_at = accepted_at
|
@@ -131,21 +140,30 @@ describe "json client" do
|
|
131
140
|
it "should not post to slack when a finished task exists in pivotal *and* in the db" do
|
132
141
|
accepted_dt = DateTime.now - 1
|
133
142
|
direct_save(accepted_dt, 'finished')
|
134
|
-
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)).to eql nil
|
143
|
+
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt, url)).to eql nil
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should post to slack when a delivered task exists in pivotal *and* is still in the db" do
|
147
|
+
accepted_dt = DateTime.now - 1
|
148
|
+
current_state = 'delivered'
|
149
|
+
puts current_state
|
150
|
+
direct_save(accepted_dt, 'delivered')
|
151
|
+
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt, url)
|
152
|
+
.fetch("message", nil).fetch("text", nil)) .to eql "Task <https://www.pivotaltracker.com/story/show/98984232|task> has been in a *delivered state for 1 days*"
|
135
153
|
end
|
136
154
|
|
137
155
|
it "should post to slack 'xx has spent xx days working on xxx' when a non completed task exists in pivotal and in the db" do
|
138
156
|
accepted_dt = DateTime.now - 1
|
139
157
|
direct_save
|
140
|
-
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)
|
141
|
-
.fetch("message", nil).fetch("text", nil)) .to eql "*user has spent 1 days working on task
|
158
|
+
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt, url)
|
159
|
+
.fetch("message", nil).fetch("text", nil)) .to eql "*user* has spent *1 days* working on <https://www.pivotaltracker.com/story/show/98984232|task>"
|
142
160
|
end
|
143
161
|
|
144
162
|
it "should post to slack 'xx has spent xx hours working on xxx' when a non completed task exists in pivotal and in the db and the days worked is less than 1" do
|
145
163
|
start_dt = DateTime.now - 0.5
|
146
164
|
direct_save(start_dt)
|
147
|
-
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)
|
148
|
-
.fetch("message", nil).fetch("text", nil)) .to eql "*user has spent
|
165
|
+
expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt, url)
|
166
|
+
.fetch("message", nil).fetch("text", nil)) .to eql "*user* has spent *less than a day* working on <https://www.pivotaltracker.com/story/show/98984232|task>"
|
149
167
|
end
|
150
168
|
|
151
169
|
it "should run through all tasks for a project, sending a message into slack for each of them" do
|