whois_slacking 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1ea56df88cdfbb8f1bb627c138c1f4d6f80a66d
4
+ data.tar.gz: d4aabbf4abd835b3b3251f8d5616fc951fec3159
5
+ SHA512:
6
+ metadata.gz: 7dd08ec36b9f0d57bad5f1b10a0ebcf5ffa8638c8787193a0e6ab7688003d1302f55504e709ad8328aeff989dc10ad8ae3db6527ccf3069a236ef7870990d380
7
+ data.tar.gz: 066746188fdb4e17d99dfbae8e3fe76d1fa0b5c5af8aad51a37bbf9a10ed01853a3cef38ee6ce601fefaa81232aaaef01be5840dae17529aa98ae9bb65f3a4ce
@@ -0,0 +1,6 @@
1
+ export WHOIS_DATA_STORE=
2
+ export PIVOTAL_TOKEN="MYPIVOTALTOKEN"
3
+ export PIVOTAL_TIMEOUT=50
4
+ export PIVOTAL_PROJECT_NAME="MYPROJECTNAME"
5
+ export SLACK_CHANNEL="MYSLACKCHANNEL"
6
+ export SLACK_TOKEN="MYSLACKTOKEN"
@@ -0,0 +1,35 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # br operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ *.rbc
8
+ *.sassc
9
+ .sass-cache
10
+ capybara-*.html
11
+ .rspec
12
+ /.bundle
13
+ /vendor/bundle
14
+ /vendor/*
15
+ /log/*
16
+ /tmp/*
17
+ /db/*.sqlite3
18
+ /public/system/*
19
+ /coverage/
20
+ /spec/tmp/*
21
+ **.orig
22
+ rerun.txt
23
+ pickle-email-*.html
24
+ *_Store
25
+ /.rvmrc
26
+ /.ruby-gemset
27
+ coverage
28
+ config/database.yml
29
+ /public/uploads
30
+ .*.swp
31
+ .*.swo
32
+ .env
33
+ *.gem
34
+ /spec/vcr_cassettes/*
35
+ /tags
@@ -0,0 +1 @@
1
+ 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,140 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ whois_slacking (0.0.1)
5
+ dotenv (~> 2.0.2)
6
+ moneta (~> 0.8.0)
7
+ multi_xml (~> 0.5)
8
+ nokogiri (~> 1.6)
9
+ pivotal-tracker (~> 0.5.13)
10
+ slack-api (~> 1.1.6)
11
+ time_difference (~> 0.4.2)
12
+ typhoeus (= 0.3.3)
13
+
14
+ GEM
15
+ remote: http://rubygems.org/
16
+ specs:
17
+ activesupport (4.2.3)
18
+ i18n (~> 0.7)
19
+ json (~> 1.7, >= 1.7.7)
20
+ minitest (~> 5.1)
21
+ thread_safe (~> 0.3, >= 0.3.4)
22
+ tzinfo (~> 1.1)
23
+ builder (3.2.2)
24
+ byebug (5.0.0)
25
+ columnize (= 0.9.0)
26
+ coderay (1.1.0)
27
+ columnize (0.9.0)
28
+ crack (0.4.2)
29
+ safe_yaml (~> 1.0.0)
30
+ diff-lcs (1.2.5)
31
+ domain_name (0.5.24)
32
+ unf (>= 0.0.5, < 1.0.0)
33
+ dotenv (2.0.2)
34
+ eventmachine (1.0.7)
35
+ faraday (0.9.1)
36
+ multipart-post (>= 1.2, < 3)
37
+ faraday_middleware (0.10.0)
38
+ faraday (>= 0.7.4, < 0.10)
39
+ faye-websocket (0.9.2)
40
+ eventmachine (>= 0.12.0)
41
+ websocket-driver (>= 0.5.1)
42
+ ffi (1.9.10)
43
+ formatador (0.2.5)
44
+ guard (2.12.8)
45
+ formatador (>= 0.2.4)
46
+ listen (>= 2.7, <= 4.0)
47
+ lumberjack (~> 1.0)
48
+ nenv (~> 0.1)
49
+ notiffany (~> 0.0)
50
+ pry (>= 0.9.12)
51
+ shellany (~> 0.0)
52
+ thor (>= 0.18.1)
53
+ guard-compat (1.2.1)
54
+ guard-rspec (4.6.1)
55
+ guard (~> 2.1)
56
+ guard-compat (~> 1.1)
57
+ rspec (>= 2.99.0, < 4.0)
58
+ http-cookie (1.0.2)
59
+ domain_name (~> 0.5)
60
+ i18n (0.7.0)
61
+ json (1.8.3)
62
+ listen (3.0.2)
63
+ rb-fsevent (>= 0.9.3)
64
+ rb-inotify (>= 0.9)
65
+ lumberjack (1.0.9)
66
+ method_source (0.8.2)
67
+ mime-types (2.6.1)
68
+ mini_portile (0.6.2)
69
+ minitest (5.7.0)
70
+ moneta (0.8.0)
71
+ multi_json (1.11.2)
72
+ multi_xml (0.5.5)
73
+ multipart-post (2.0.0)
74
+ nenv (0.2.0)
75
+ netrc (0.10.3)
76
+ nokogiri (1.6.6.2)
77
+ mini_portile (~> 0.6.0)
78
+ nokogiri-happymapper (0.5.9)
79
+ nokogiri (~> 1.5)
80
+ notiffany (0.0.6)
81
+ nenv (~> 0.1)
82
+ shellany (~> 0.0)
83
+ pivotal-tracker (0.5.13)
84
+ builder
85
+ crack
86
+ nokogiri (>= 1.5.5)
87
+ nokogiri-happymapper (>= 0.5.4)
88
+ rest-client (>= 1.8.0)
89
+ pry (0.10.1)
90
+ coderay (~> 1.1.0)
91
+ method_source (~> 0.8.1)
92
+ slop (~> 3.4)
93
+ rb-fsevent (0.9.5)
94
+ rb-inotify (0.9.5)
95
+ ffi (>= 0.5.0)
96
+ rest-client (1.8.0)
97
+ http-cookie (>= 1.0.2, < 2.0)
98
+ mime-types (>= 1.16, < 3.0)
99
+ netrc (~> 0.7)
100
+ rspec (2.99.0)
101
+ rspec-core (~> 2.99.0)
102
+ rspec-expectations (~> 2.99.0)
103
+ rspec-mocks (~> 2.99.0)
104
+ rspec-core (2.99.2)
105
+ rspec-expectations (2.99.2)
106
+ diff-lcs (>= 1.1.3, < 2.0)
107
+ rspec-mocks (2.99.4)
108
+ safe_yaml (1.0.4)
109
+ shellany (0.0.1)
110
+ slack-api (1.1.6)
111
+ faraday (>= 0.7, < 0.10)
112
+ faraday_middleware (~> 0.8)
113
+ faye-websocket (~> 0.9.2)
114
+ multi_json (~> 1.0, >= 1.0.3)
115
+ slop (3.6.0)
116
+ thor (0.19.1)
117
+ thread_safe (0.3.5)
118
+ time_difference (0.4.2)
119
+ activesupport
120
+ typhoeus (0.3.3)
121
+ mime-types
122
+ tzinfo (1.2.2)
123
+ thread_safe (~> 0.1)
124
+ unf (0.1.4)
125
+ unf_ext
126
+ unf_ext (0.0.7.1)
127
+ vcr (2.9.3)
128
+ websocket-driver (0.6.0)
129
+ websocket-extensions (>= 0.1.0)
130
+ websocket-extensions (0.1.2)
131
+
132
+ PLATFORMS
133
+ ruby
134
+
135
+ DEPENDENCIES
136
+ byebug
137
+ guard-rspec (~> 4.2)
138
+ rspec (~> 2.13)
139
+ vcr (~> 2.4)
140
+ whois_slacking!
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cmd: "bundle exec rspec" do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+ ---------------------
3
+
4
+ Copyright © 2014 Vulk <wolfpack@vulk.co>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ Whois Slacking.
2
+ =================
3
+
4
+ This is a ruby library that integrates Pivotal Tracker and Slack.
5
+ The library will send a message into a slack channel for every uncompleted task in pivotal, saying how long
6
+ a user has spent on that task.
7
+ This library is meant to be run once a day, to assist with morning standups.
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ gem install whois_slacking
13
+ ```
14
+ Update the .env file with the proper tokens
15
+
16
+ Make the following call in a ruby file and call it in cron job that runs daily:
17
+ ```
18
+ WhoIsSlacking::Start.now
19
+ ```
20
+
21
+ ## Contribution
22
+
23
+ Installation for contributors
24
+
25
+ 1. Ensure all tests pass by running ```rspec spec```
26
+ 2. Submit a pull request with your changes
27
+
28
+ Please write tests for any changes you make or we will have our way with you
29
+
30
+ ## License
31
+
32
+ [The MIT License (MIT)](http://vulk.mit-license.org)
33
+
34
+ Copyright (c) 2014 Vulk <[wolfpack@vulk.co](mailto:wolfpack@vulk.co)>
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,194 @@
1
+ # Require the necessary files
2
+ %w[
3
+ rubygems
4
+ pivotal-tracker
5
+ slack
6
+ time_difference
7
+ byebug
8
+ typhoeus
9
+ multi_xml
10
+ ].each { |r| require r }
11
+
12
+ module WhoIsSlacking
13
+
14
+ MultiXml.parser = :nokogiri
15
+
16
+ class Start
17
+ # whois-slacking
18
+ # -- get project name
19
+ # -- get slack channel
20
+ # -- get all users for the project
21
+ # -- save tasks
22
+ # -- retrieve all tasks from pivotal for the project
23
+ # -- loop through tasks
24
+ # -- if task/username combo does not exist in db
25
+ # -- save project/task/user
26
+ # -- save when task was started
27
+ # -- save who started task
28
+ # -- if task is not-completed in pivotal
29
+ # -- save status as status not-completed
30
+ # -- publish message task/user started today
31
+ # -- "Today Johnny started 'As a user I should be able to log in'"
32
+ # -- if task is completed in pivotal
33
+ # -- save status as status completed
34
+ # -- publish message task/user started today
35
+ # -- "Today Johnny completed 'As a user I should be able to log in'"
36
+ # -- if task/username combo exists and is not completed in db
37
+ # -- calculate how long (realtime) the task has been worked on in days (.5, 1.5 etc)
38
+ # -- update time on task
39
+ # -- save who started task
40
+ # -- publish message task/user/how long to slack
41
+ # -- "Johnny has spent 2 days working on 'As a user I should be able to log in'"
42
+ # -- pruning
43
+ # -- retrieve all tasks from db for the project
44
+ # -- retrieve all tasks from pivotal for the project
45
+ # -- loop through all tasks from db
46
+ # -- if task/user name combo does not exist in pivotal
47
+ # -- mark task/user name combo in db as deleted
48
+ # -- "Today Johnny gave up working on 'As a user I should be able to log in'"
49
+ # -- if task/user name combo is completed in pivotal but not completed in db
50
+ # -- mark task/user name combo in db as completed
51
+ # -- "Today Johnny completed 'As a user I should be able to log in'"
52
+ def self.now
53
+ WhoIsSlacking::Pivotal.connect_to_pivotal
54
+ project_object = WhoIsSlacking::Pivotal
55
+ .pivotal_project( WhoIsSlacking::Pivotal.project_name)
56
+ tasks = WhoIsSlacking::Pivotal.project_stories(project_object)
57
+ tasks.each do |task|
58
+ if task.current_state != 'unstarted' && task.owned_by &&
59
+ task.current_state != 'accepted'
60
+ WhoIsSlacking::DataTools.save_task(project_object.name, task.id, task.name, task.owned_by, task.current_state, task.accepted_at )
61
+ end
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ class Pivotal
68
+ def self.connect_to_pivotal
69
+ PivotalTracker::Client.token = ENV["PIVOTAL_TOKEN"]
70
+ PivotalTracker::Client.timeout = ENV["PIVOTAL_TIMEOUT"].to_i
71
+ end
72
+
73
+ def self.project_name
74
+ ENV["PIVOTAL_PROJECT_NAME"]
75
+ end
76
+
77
+ def self.pivotal_project(single_project_name=project_name)
78
+ projects = PivotalTracker::Project.all
79
+ projects.find {|x| x.name == single_project_name}
80
+ end
81
+
82
+ def self.project_members(project_object)
83
+ project_object.memberships.all
84
+ end
85
+
86
+ def self.project_stories(project_object)
87
+ project_object.stories.all
88
+ end
89
+
90
+ def self.pivotal_users_by_project
91
+ end
92
+
93
+ end
94
+
95
+ class SlackWrapper
96
+ def self.slack_channel
97
+ ENV["SLACK_CHANNEL"]
98
+ end
99
+
100
+ def self.post_to_slack(message)
101
+ Slack.configure { |config| config.token = ENV["SLACK_TOKEN"] }
102
+ Slack.chat_postMessage channel: slack_channel, text: message
103
+ end
104
+ end
105
+
106
+ class DataTools;
107
+ attr_accessor :data_format
108
+ attr_accessor :apikey
109
+
110
+ def self.whois_store(store_type=nil)
111
+ t = store_type.nil? ? ENV["WHOIS_DATA_STORE"] : store_type.to_s
112
+
113
+ case t
114
+ when "redis"
115
+ url = ENV["REDISTOGO_URL"] || "redis://127.0.0.1:6379/"
116
+ uri = URI.parse url
117
+ store = Moneta.new(:Redis, host: uri.host, port: uri.port, password: uri.password)
118
+ else # also for "file"
119
+ store = Moneta.new(:File, :dir => 'moneta')
120
+ end
121
+ end
122
+
123
+ def self.save_task(project, task_id, task, user, current_state, accepted_at, options={})
124
+
125
+ # dont use accepted_at
126
+ accepted_at = accepted_at
127
+ created_dt = DateTime.now.to_s
128
+ start_dt = DateTime.now.to_s
129
+ updated_dt = created_dt
130
+ current_state = current_state
131
+ active = true
132
+ message = nil
133
+ 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}
134
+ # initialize datastore type
135
+ store = whois_store
136
+ mutex = Moneta::Mutex.new(store, 'moneta')
137
+ mutex.synchronize do
138
+ mkey = self.whois_key(project, task_id, user)
139
+ entity_exists = store[mkey]
140
+
141
+ if entity_exists # -- if task/username combo exists and is not completed in db
142
+ # -- calculate how long (realtime) the task has been worked on in days (.5, 1.5 etc)
143
+ # -- update time on task
144
+ # -- save who started task
145
+ # -- publish message task/user/how long to slack
146
+ # -- "Johnny has spent 2 days working on 'As a user I should be able to log in'"
147
+ # keep created at date
148
+
149
+ start_dt = entity_exists[:start_dt].to_datetime
150
+
151
+ days_worked = TimeDifference.between(DateTime.now, start_dt).in_days
152
+ if days_worked >= 1.0
153
+ message = "#{user} has spent #{days_worked.to_i} days working on #{task}"
154
+ else # show hours instead
155
+ hours_worked = TimeDifference.between(DateTime.now, start_dt).in_hours
156
+ message = "#{user} has spent #{hours_worked.to_i} hours working on #{task}"
157
+ end
158
+ # keep the created dt and start_dt
159
+ created_dt = entity_exists[:created_dt]
160
+ start_dt = entity_exists[:start_dt].to_datetime
161
+ task_entity["created_dt"] = created_dt
162
+ task_entity["start_dt"] = start_dt
163
+ store[mkey] = task_entity
164
+
165
+ else # -- if task/username combo does not exist in db
166
+ # -- save project/task/user
167
+ # -- save when task was started
168
+ # -- save who started task
169
+ store[mkey] = task_entity
170
+
171
+ if current_state != "finished" # -- if task is not-completed in pivotal
172
+ # -- save status as status not-completed
173
+ # -- publish message task/user started today
174
+ # -- "Today Johnny started 'As a user I should be able to log in'"
175
+ message = "Today #{user} started #{task}"
176
+
177
+ elsif current_state == "finished" # -- if task is completed in pivotal
178
+ # -- save status as status completed
179
+ # -- publish message task/user started today
180
+ # -- "Today Johnny completed 'As a user I should be able to log in'"
181
+ message = "Today #{user} finished #{task}"
182
+ end
183
+
184
+ end
185
+ end
186
+ WhoIsSlacking::SlackWrapper.post_to_slack(message) if message
187
+ end
188
+
189
+ def self.whois_key(project, task, user)
190
+ "#{project}-#{task}-#{user}"
191
+ end
192
+
193
+ end
194
+ end
@@ -0,0 +1,3 @@
1
+ module WhoIsSlacking
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,151 @@
1
+ # require 'whois_slacking/version'
2
+ require './lib/whois_slacking'
3
+ require 'spec_helper'
4
+ require 'moneta'
5
+ require 'date'
6
+ require 'byebug'
7
+
8
+ describe "json client" do
9
+
10
+
11
+ before do
12
+ @store = Moneta.new(:File, :dir => 'moneta')
13
+ end
14
+
15
+ after do
16
+ @store.delete(whois_key)
17
+ @store.clear
18
+ @store.close
19
+ @store = nil
20
+ end
21
+
22
+ # project-task_id-user
23
+ def whois_key
24
+ "#{ENV['PIVOTAL_PROJECT_NAME']}-task_id-user"
25
+ end
26
+
27
+ def project_name
28
+ ENV["PIVOTAL_PROJECT_NAME"]
29
+ end
30
+
31
+ def slack_channel
32
+ ENV["SLACK_CHANNEL"]
33
+ end
34
+
35
+ def project
36
+ ENV["PIVOTAL_PROJECT_NAME"]
37
+ end
38
+
39
+ def task_id
40
+ 'task_id'
41
+ end
42
+
43
+ def task
44
+ 'task'
45
+ end
46
+
47
+ def user
48
+ 'user'
49
+ end
50
+
51
+ def current_state
52
+ 'started'
53
+ end
54
+
55
+ def accepted_dt
56
+ DateTime.now
57
+ end
58
+
59
+ def start_dt
60
+ DateTime.now
61
+ end
62
+
63
+ it "should connect to pivotal" do
64
+ WhoIsSlacking::Pivotal.connect_to_pivotal
65
+ expect(PivotalTracker::Client.connection.timeout).to eql ENV["PIVOTAL_TIMEOUT"].to_i
66
+ end
67
+
68
+ it "should get a pivotal project" do
69
+ WhoIsSlacking::Pivotal.connect_to_pivotal
70
+ WhoIsSlacking::Pivotal.pivotal_project(project_name)
71
+ expect(WhoIsSlacking::Pivotal.pivotal_project(project_name).name).to eql project_name
72
+ end
73
+
74
+ it "should get a pivotal project members" do
75
+ WhoIsSlacking::Pivotal.connect_to_pivotal
76
+ project_object = WhoIsSlacking::Pivotal.pivotal_project(project_name)
77
+ expect(WhoIsSlacking::Pivotal.project_members(project_object).count).should be > 0
78
+ end
79
+
80
+ it "should get a pivotal project stories" do
81
+ WhoIsSlacking::Pivotal.connect_to_pivotal
82
+ project_object = WhoIsSlacking::Pivotal.pivotal_project(project_name)
83
+ expect(WhoIsSlacking::Pivotal.project_stories(project_object).count).to be > 0
84
+ end
85
+
86
+ it "should create a whois_slacking key" do
87
+ expect(WhoIsSlacking::DataTools.whois_key(project, task_id, user)).to eql whois_key
88
+ end
89
+
90
+ it "should save a project task" do
91
+ WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)
92
+ expect(@store.key?(whois_key)).to eql true
93
+ end
94
+
95
+ it "should know the proper slack channel" do
96
+ expect(WhoIsSlacking::SlackWrapper.slack_channel).to eql slack_channel
97
+ end
98
+
99
+ it "should be able to post to slack" do
100
+ message = "This channel is worthy for testing only"
101
+ expect(WhoIsSlacking::SlackWrapper.post_to_slack(message)["ok"]).to eql true
102
+ end
103
+
104
+ it "should post to slack 'Today xx started xxx' when a non completed task exists in pivotal but not in the db" do
105
+ expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)
106
+ .fetch("message", nil).fetch("text", nil)) .to eql "Today user started task"
107
+ end
108
+
109
+ it "should post to slack 'Today xx completed xxx' when a completed task exists in pivotal but not in the db" do
110
+ 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 "Today user finished task"
113
+ end
114
+
115
+ def direct_save(start_dt = (DateTime.now - 1))
116
+ accepted_at = accepted_at
117
+ created_dt = DateTime.now.to_s
118
+ updated_dt = created_dt
119
+ current_state = current_state
120
+ active = true
121
+ message = nil
122
+ 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}
123
+ store = WhoIsSlacking::DataTools.whois_store
124
+ mutex = Moneta::Mutex.new(store, 'moneta')
125
+ mutex.synchronize do
126
+ mkey = WhoIsSlacking::DataTools.whois_key(project, task_id, user)
127
+ store[mkey] = task_entity
128
+ end
129
+ end
130
+
131
+ 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
132
+ accepted_dt = DateTime.now - 1
133
+ direct_save
134
+ expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)
135
+ .fetch("message", nil).fetch("text", nil)) .to eql "user has spent 1 days working on task"
136
+ end
137
+
138
+ 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
139
+ start_dt = DateTime.now - 0.5
140
+ direct_save(start_dt)
141
+ expect(WhoIsSlacking::DataTools.save_task(project, task_id, task, user, current_state, accepted_dt)
142
+ .fetch("message", nil).fetch("text", nil)) .to eql "user has spent 12 hours working on task"
143
+ end
144
+
145
+ it "should run through all tasks for a project, sending a message into slack for each of them" do
146
+ WhoIsSlacking::Pivotal.connect_to_pivotal
147
+ project_object = WhoIsSlacking::Pivotal.pivotal_project(project_name)
148
+ expect(WhoIsSlacking::Start.now.count).to eql WhoIsSlacking::Pivotal.project_stories(project_object).count
149
+ end
150
+ end
151
+
@@ -0,0 +1,46 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require './lib/whois_slacking'
4
+ #require 'webmock/rspec'
5
+
6
+ VCR.configure do |c|
7
+ c.allow_http_connections_when_no_cassette = true
8
+ c.cassette_library_dir = 'spec/vcr_cassettes'
9
+ c.hook_into :typhoeus
10
+ c.filter_sensitive_data("<API_KEY>") { WhoIsSlacking.apikey }
11
+ end
12
+
13
+ RSpec.configure do |config|
14
+
15
+
16
+ config.mock_with :rspec
17
+
18
+ config.treat_symbols_as_metadata_keys_with_true_values = true
19
+ config.around(:each, :vcr) do |example|
20
+ #name = example.metadata[:full_description].split(/\s+/, 2).join("/").underscore.gsub(/[^\w\/]+/, "_")
21
+ name = example.metadata[:full_description].split(/\s+/, 2).join("/").downcase.gsub(/\s+/,"_")
22
+ #options = example.metadata.slice(:record, :match_requests_on).except(:example_group)
23
+ options = example.metadata.reduce({}){ |acc, x| [:record,:match_requests_on].include?(x[0]) ? acc.merge({x[0] => x[1]}) : acc }
24
+ VCR.use_cassette(name, options) { example.call }
25
+ #VCR.use_cassette(name) { example.call }
26
+ end
27
+
28
+ # Use color in STDOUT
29
+ config.color_enabled = true
30
+
31
+ # Use color not only in STDOUT but also in pagers and files
32
+ config.tty = true
33
+
34
+ # Use the specified formatter
35
+ config.formatter = :documentation # :progress, :html, :textmate
36
+
37
+ #WebMock.disable_net_connect!(:allow => 'coveralls.io')
38
+
39
+ #RSpec.configure do |config|
40
+ # config.expect_with :rspec do |c|
41
+ # c.syntax = :expect
42
+ # end
43
+ #end
44
+
45
+
46
+ end
@@ -0,0 +1,8 @@
1
+ VCR.configure do |c|
2
+ # temporarily allows calls to go directly to facebook
3
+ #c.ignore_hosts 'facebook.com', 'graph.facebook.com'
4
+
5
+ c.cassette_library_dir = Rails.root.join("spec", "vcr")
6
+ #c.hook_into :fakeweb
7
+ c.hook_into :typheous
8
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "whois_slacking/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'whois_slacking'
7
+ s.version = WhoIsSlacking::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.date = '2015-07-09'
10
+ s.summary = "whois_slacking for whois_slacking.com"
11
+ s.description = "Ruby Client for whois_slacking.com. Gives ip address and radius queries. Visit whois_slacking.com for more details"
12
+ s.authors = ["W Watson"]
13
+ s.email = 'wolfpack@vulk.com'
14
+ s.files = ["lib/whois_slacking.rb"]
15
+ s.homepage = 'http://github.com/vulk/whois_slacking'
16
+ s.license = 'MIT'
17
+ s.required_ruby_version = '>= 2.1.5'
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_development_dependency 'rspec', ["~> 2.13"]
24
+ s.add_development_dependency 'vcr',["~> 2.4"]
25
+ s.add_development_dependency 'guard-rspec', ["~> 4.2"]
26
+ s.add_development_dependency 'byebug'
27
+ # s.add_development_dependency 'debugger'
28
+
29
+ s.add_runtime_dependency "pivotal-tracker", ["~> 0.5.13"]
30
+ # s.add_runtime_dependency "slackr", ["~> 0.0.6"]
31
+ s.add_runtime_dependency 'slack-api', ["~> 1.1.6"]
32
+ s.add_runtime_dependency 'time_difference', ["~> 0.4.2"]
33
+ s.add_runtime_dependency 'moneta', ["~> 0.8.0"]
34
+ s.add_runtime_dependency "typhoeus", ["0.3.3"]
35
+ s.add_runtime_dependency "multi_xml", ["~> 0.5"]
36
+ s.add_runtime_dependency "nokogiri", ["~> 1.6"]
37
+ s.add_runtime_dependency "dotenv", ["~> 2.0.2"]
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whois_slacking
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - W Watson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vcr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pivotal-tracker
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.5.13
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.5.13
83
+ - !ruby/object:Gem::Dependency
84
+ name: slack-api
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.1.6
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.1.6
97
+ - !ruby/object:Gem::Dependency
98
+ name: time_difference
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.4.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.4.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: moneta
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.8.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.8.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: typhoeus
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 0.3.3
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 0.3.3
139
+ - !ruby/object:Gem::Dependency
140
+ name: multi_xml
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.5'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.5'
153
+ - !ruby/object:Gem::Dependency
154
+ name: nokogiri
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.6'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.6'
167
+ - !ruby/object:Gem::Dependency
168
+ name: dotenv
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 2.0.2
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 2.0.2
181
+ description: Ruby Client for whois_slacking.com. Gives ip address and radius queries. Visit
182
+ whois_slacking.com for more details
183
+ email: wolfpack@vulk.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".env_example"
189
+ - ".gitignore"
190
+ - ".ruby-version"
191
+ - Gemfile
192
+ - Gemfile.lock
193
+ - Guardfile
194
+ - LICENSE
195
+ - README.md
196
+ - lib/whois_slacking.rb
197
+ - lib/whois_slacking/version.rb
198
+ - spec/client_spec.rb
199
+ - spec/spec_helper.rb
200
+ - spec/support/vcr_setup.rb
201
+ - whois_slacking.gemspec
202
+ homepage: http://github.com/vulk/whois_slacking
203
+ licenses:
204
+ - MIT
205
+ metadata: {}
206
+ post_install_message:
207
+ rdoc_options: []
208
+ require_paths:
209
+ - lib
210
+ required_ruby_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: 2.1.5
215
+ required_rubygems_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ requirements: []
221
+ rubyforge_project:
222
+ rubygems_version: 2.4.3
223
+ signing_key:
224
+ specification_version: 4
225
+ summary: whois_slacking for whois_slacking.com
226
+ test_files: []