fire_watch 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 48916752484ddabddd8c8fe0444173b0746fb3b0
4
+ data.tar.gz: 839961ba315d486a03d16e184f4ca66b94ee21a2
5
+ SHA512:
6
+ metadata.gz: 088196f7b5f0290b75521ee6678d3c5d02f2acf8072af0f58aed7963e00c87581fd59f1f9227872c4d5a4c9234be18dd36732b306dbcb5775fbbe95baf9b850b
7
+ data.tar.gz: ead16f0d9c9ed7c4e6bede5dbc05938ba715a60da7ed3c4cec0b06caf59ddf3ce4803ec61f9c7257d72e3465743aad09e786d59dcdfdf8c8edf18bf23e3d805f
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.csv
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at joew@samjoe.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fire_watch.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # FireWatch
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fire_watch`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+ $ gem install fire_watch
9
+
10
+ If you are using rbenv, retstart your terminal or run:
11
+ $ rbenv rehash
12
+
13
+ And then execute:
14
+
15
+ $ fire_watch
16
+
17
+ ## Usage
18
+
19
+ $ fire_watch
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To run the local development copy on your machine, run `$ ruby -Ilib ./exe/fire_watch`
26
+
27
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fire_watch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
32
+
33
+ ## Code of Conduct
34
+
35
+ Everyone interacting in the FireWatch project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fire_watch/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fire_watch"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/fire_watch ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fire_watch'
4
+ require 'fire_watch/runner'
5
+
6
+ FireWatch::Runner.invoke
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fire_watch/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fire_watch"
8
+ spec.version = FireWatch::VERSION
9
+ spec.authors = ["Joe Weakley"]
10
+ spec.email = ["joew@samjoe.com"]
11
+
12
+ spec.summary = %q{Wildland Project Time Management App}
13
+ spec.description = %q{Helps project managers view the health of a project}
14
+ spec.homepage = "https://github.com/wildland/fire_watch"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_runtime_dependency "harvested", "~> 3.1"
33
+ spec.add_runtime_dependency "highline", "~> 1.7"
34
+ spec.add_runtime_dependency "github_api", "~> 0.17"
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.15"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "minitest", "~> 5.0"
39
+ end
@@ -0,0 +1,226 @@
1
+ require 'highline'
2
+ require 'harvested'
3
+ require 'github_api'
4
+ require 'pry'
5
+
6
+ module FireWatch
7
+ class Runner
8
+ def self.invoke
9
+
10
+ cli = HighLine.new
11
+ # Github Client
12
+ github_login = cli.ask('Github Login: ')
13
+ github_password = cli.ask('Github Password: ') { |q| q.echo = false }
14
+ @github_client = Github.new(auto_pagination: true) do |config|
15
+ config.basic_auth = "#{github_login}:#{github_password}"
16
+ if cli.agree("Do you use Two-Factor authentication (non-sms)?")
17
+ config.connection_options = { headers: {"X-GitHub-OTP" => cli.ask('Two-Factor Code')} }
18
+ end
19
+ end
20
+
21
+ repos = @github_client.repos.list(org: 'wildland').sort_by{|r| r.name}
22
+ selected_repo = nil
23
+ cli.choose do |menu|
24
+ menu.prompt = "Select Github Repo:"
25
+ repos.each do |r|
26
+ menu.choice(r.name) do
27
+ selected_repo = r
28
+ end
29
+ end
30
+ end
31
+
32
+ milestones = @github_client.issues.milestones.list(user: 'wildland',repo: selected_repo.name, state: 'all').sort_by{|m| m.title}
33
+ selected_milestone = nil
34
+ cli.choose do |menu|
35
+ menu.prompt = "Select Milestone:"
36
+ milestones.each do |m|
37
+ menu.choice(m.title) do
38
+ selected_milestone = m
39
+ end
40
+ end
41
+ end
42
+
43
+ issues, pull_request_issues = @github_client.issues.list(user: 'wildland', repo: selected_repo.name, milestone: selected_milestone.number, state: 'all').partition{|i| i.pull_request == nil}
44
+
45
+ pull_requests = pull_request_issues.map do |i|
46
+ @github_client.pull_requests.get(user: 'wildland', repo: selected_repo.name, number: i.number).body
47
+ end
48
+
49
+ # Harvest Client
50
+ harvest_username = cli.ask('Harvest Username: ')
51
+ harvest_password = cli.ask('Harvest Password: ') { |q| q.echo = false }
52
+ @harvest_client = Harvest.client(username: harvest_username, password: harvest_password, subdomain: 'wildland')
53
+
54
+ projects = @harvest_client.projects.all.sort_by{|p| p.name}
55
+ selected_projects = []
56
+ done = false
57
+ loop do
58
+ cli.choose do |menu|
59
+ menu.prompt = "Add/Remove Project (#{selected_projects.map{|p| p.name}.join(', ')}): "
60
+ projects.each do |p|
61
+ menu.choice(p.name) do
62
+ if selected_projects.include? p
63
+ selected_projects.delete(p)
64
+ else
65
+ selected_projects.push(p)
66
+ end
67
+ end
68
+ end
69
+ menu.choice("Done Adding Projects") { done = true }
70
+ end
71
+ break if done
72
+ end
73
+
74
+ harvest_users = @harvest_client.users.all
75
+
76
+ time_entries = []
77
+
78
+ selected_projects.each do |project|
79
+ if project.starts_on.nil?
80
+ puts "No start date for #{project.name}"
81
+ next
82
+ end
83
+ time_entries += @harvest_client.reports.time_by_project(
84
+ project,
85
+ Time.parse(project.starts_on),
86
+ project.ends_on.nil? ? Time.now : Time.parse(project.ends_on)
87
+ )
88
+ end
89
+
90
+ #Process Data
91
+ csv_file_name = cli.ask('File name for report?').concat('.csv')
92
+
93
+ CSV.open(csv_file_name, "wb", force_quotes: true) do |csv|
94
+ csv << [
95
+ "Repo",
96
+ "Milestone",
97
+ "Issue Number",
98
+ "Issue Title",
99
+ "Project",
100
+ "Who",
101
+ "Scope Time",
102
+ "Actual Time",
103
+ "Status",
104
+ "Merged",
105
+ "Labels"
106
+ ]
107
+
108
+ issues.each do |issue|
109
+ relevant_time_entries, time_entries = time_entries.partition do |entry|
110
+ match_data = /.?#(?<issue_number>\d+)/.match(entry.notes)
111
+ if match_data.nil?
112
+ false
113
+ else
114
+ match_data["issue_number"].eql? issue.number.to_s
115
+ end
116
+ end
117
+
118
+ if relevant_time_entries.empty?
119
+ csv << [
120
+ selected_repo.name,
121
+ selected_milestone.title,
122
+ issue.number,
123
+ issue.title,
124
+ "",
125
+ "",
126
+ issue.labels.nil? || issue.labels.find{|l| l.name.include?"size:"}.nil? ? "" : issue.labels.find{|l| l.name.include?"size:"}.name,
127
+ "",
128
+ issue.state,
129
+ "",
130
+ issue.labels.nil? ? "" : issue.labels.compact.map{|l| l.name}.join(', ')
131
+ ]
132
+ else
133
+ relevant_time_entries.chunk{|i| i.user_id }.each do |user_id, user_time_entries|
134
+ user = harvest_users.find{|u| u.id == user_id}
135
+ csv << [
136
+ selected_repo.name,
137
+ selected_milestone.title,
138
+ issue.number,
139
+ issue.title,
140
+ projects.select{|p| user_time_entries.map(&:project_id).uniq.include? p.id}.map(&:name).join(', '),
141
+ "#{user.first_name} #{user.last_name}", # Who
142
+ issue.labels.nil? ? "" : issue.labels.find{|l| l.name.include?"size:"}.name,
143
+ user_time_entries.inject(0){|sum, e| sum + e.hours },
144
+ issue.state,
145
+ "",
146
+ issue.labels.nil? ? "" : issue.labels.map{|l| l.name}.join(', ')
147
+ ]
148
+ end
149
+ end
150
+ end
151
+
152
+ pull_requests.each do |pr|
153
+ relevant_time_entries, time_entries = time_entries.partition do |entry|
154
+ match_data = /.?#(?<issue_number>\d+)/.match(entry.notes)
155
+ if match_data.nil?
156
+ false
157
+ else
158
+ match_data["issue_number"].eql? pr.number.to_s
159
+ end
160
+ end
161
+ if relevant_time_entries.empty?
162
+ csv << [
163
+ selected_repo.name,
164
+ selected_milestone.title,
165
+ pr.number,
166
+ pr.title,
167
+ "",
168
+ "",
169
+ pr.labels.nil? ? "" : pr.labels.find{|l| l.name.include?"size:"}.name,
170
+ "",
171
+ pr.state,
172
+ pr.merged ? "Y" : "N",
173
+ pr.labels.nil? ? "" : pr.labels.map{|l| l.name}.join(', ')
174
+ ]
175
+ else
176
+ relevant_time_entries.chunk{|i| i.user_id }.each do |user_id, user_time_entries|
177
+ user = harvest_users.find{|u| u.id == user_id}
178
+ csv << [
179
+ selected_repo.name,
180
+ selected_milestone.title,
181
+ pr.number,
182
+ pr.title,
183
+ projects.select{|p| user_time_entries.map(&:project_id).uniq.include? p.id}.map(&:name).join(', '),
184
+ "#{user.first_name} #{user.last_name}", # Who
185
+ pr.labels.nil? ? "" : issue.labels.find{|l| l.name.include?"size:"}.name,
186
+ user_time_entries.inject(0){|sum, e| sum + e.hours },
187
+ pr.state,
188
+ pr.merged ? "Y" : "N",
189
+ pr.labels.nil? ? "" : issue.labels.map{|l| l.name}.join(', ')
190
+ ]
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ if time_entries.count > 0 && cli.agree("#{time_entries.count} Time entries not in this milestone. Create a list of them?")
197
+ time_entries_file_name = cli.ask('File name for report?').concat('.csv')
198
+ CSV.open(time_entries_file_name, "wb", force_quotes: true) do |csv|
199
+ csv << [
200
+ "Created At",
201
+ "Who",
202
+ "Hours",
203
+ "Notes"
204
+ ]
205
+ time_entries.each do |entry|
206
+ csv << [
207
+ entry.created_at,
208
+ "#{harvest_users.find{|u| u.id == entry.user_id}.first_name} #{harvest_users.find{|u| u.id == entry.user_id}.last_name}",
209
+ entry.hours,
210
+ entry.notes
211
+ ]
212
+ end
213
+ end
214
+ end
215
+
216
+ rescue Github::Error::GithubError => e
217
+ puts 'Github API Error'
218
+ puts e.to_s
219
+ rescue Harvest::AuthenticationFailed
220
+ puts 'Unable to authenticate to Harvest. Check username/password.'
221
+ rescue Harvest::HTTPError => e
222
+ puts 'Harvest API Error'
223
+ puts e.to_s
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,3 @@
1
+ module FireWatch
2
+ VERSION = "0.1.0"
3
+ end
data/lib/fire_watch.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "fire_watch/version"
2
+
3
+ module FireWatch
4
+ # Your code goes here...
5
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fire_watch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe Weakley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: harvested
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: github_api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.17'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ description: Helps project managers view the health of a project
98
+ email:
99
+ - joew@samjoe.com
100
+ executables:
101
+ - fire_watch
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - exe/fire_watch
114
+ - fire_watch.gemspec
115
+ - lib/fire_watch.rb
116
+ - lib/fire_watch/runner.rb
117
+ - lib/fire_watch/version.rb
118
+ homepage: https://github.com/wildland/fire_watch
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.5.1
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Wildland Project Time Management App
141
+ test_files: []