jira_reporting 0.0.1

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
+ SHA256:
3
+ metadata.gz: 96f28872982653389eae5e488073432a7817c47997cd6256ff4f566bdfe4eab4
4
+ data.tar.gz: 9c79b7de84d007aa6f1d526ffdcb920f74659d09ae297bf0215455350fc41115
5
+ SHA512:
6
+ metadata.gz: 4a647d10943dad71c2942c2f501714102e9b905966742abde7845c5c2b1028957898fc22879c20c834541ea9c2d57aa16fe3436b84ff938b0f02949e2ce35d8d
7
+ data.tar.gz: 13ee60cf5e54864d8724dc3f73d124601f2b0453a0716739be7cb092402d5039cb3820e623073eb61a862bd9a4df96a0d01e252b9069f30a03d5d678f11b6a6c
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ auth.yml
19
+ .DS_Store
20
+ .byebug_history
21
+ _issues.select(&:bug?)
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jira_reporting.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joshua Szmajda
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # JiraReporting
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+ ```
9
+ gem 'jira_reporting'
10
+ ```
11
+ And then execute:
12
+ ```
13
+ $ bundle
14
+ ```
15
+ Or install it yourself as:
16
+ ```
17
+ $ gem install jira_reporting
18
+ ```
19
+ ## Additional Usage
20
+
21
+ If the right fields are created within Jira, this gem can be used to set and track Jira issue SLA due times, SLA overdue statuses, and SLA warnings for issues that are almost due.
22
+
23
+ #TODO - add walkthrough for the above
24
+
25
+ A cron job can be made for the bin/sla_warning script to be run in order to achieve this. On an OSX laptop with rbenv managing ruby versions, the crontab job looks like this:
26
+
27
+ ```
28
+ */5 * * * * bash -lc "cd /Users/gabo/Documents/code/on_production/jira_reporting && bin/sla_warning"
29
+ ```
30
+ The environment setup for the bin/sla_warning script to run as a crontab job on Ubuntu using RVM looks like this:
31
+ ```
32
+ #sm start rvm
33
+ PATH="/home/gabo/.rvm/gems/ruby-2.3.0/bin:/home/gabo/.rvm/gems/ruby-2.3.0@global/bin:/usr/share/rvm/rubies/ru$
34
+ GEM_HOME='/home/gabo/.rvm/gems/ruby-2.3.0'
35
+ GEM_PATH='/home/gabo/.rvm/gems/ruby-2.3.0:/home/gabo/.rvm/gems/ruby-2.3.0@global'
36
+ MY_RUBY_HOME='/usr/share/rvm/rubies/ruby-2.3.0'
37
+ IRBRC='/usr/share/rvm/rubies/ruby-2.3.0/.irbrc'
38
+ RUBY_VERSION='ruby-2.3.0'
39
+
40
+ */5 * * * * ~/Documents/code/on_production/jira_reporting/bin/sla_warning
41
+ ```
42
+ ## Usage
43
+
44
+ TODO: Write usage instructions here
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( http://github.com/<my-github-username>/jira_reporting/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/auth.yml.example ADDED
@@ -0,0 +1,10 @@
1
+ jira:
2
+ username: xxx
3
+ password: xxx
4
+
5
+ code_climate:
6
+ api_token: xxx
7
+
8
+ github:
9
+ api_token: xxx
10
+
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'thor/group'
5
+ require 'jira_reporting'
6
+
7
+ def connect_to_jira!
8
+ user = ENV['jira_user']
9
+ pass = ENV['jira_pass']
10
+ unless user && pass
11
+ STDERR.puts "ENV needs jira_user and jira_pass!"
12
+ exit 1
13
+ end
14
+ JiraReporting.connect!(user, pass)
15
+ end
16
+
17
+ module CLI
18
+ class ThorSubCommandTemplate < Thor
19
+ class << self
20
+ def subcommand_setup(name, usage, desc)
21
+ namespace :"#{name}"
22
+ @subcommand_usage = usage
23
+ @subcommand_desc = desc
24
+ end
25
+
26
+ def banner(task, namespace = nil, subcommand = false)
27
+ "#{basename} #{task.formatted_usage(self, true, true)}"
28
+ end
29
+
30
+ def register_to(klass)
31
+ klass.register(self, @namespace, @subcommand_usage, @subcommand_desc)
32
+ end
33
+ end
34
+ end
35
+
36
+ class Reporting < ThorSubCommandTemplate
37
+ subcommand_setup "reporting", "reporting [TASK]", "Execute a reporting task"
38
+ desc "sla", "Shows the SLA report"
39
+ def sla
40
+ connect_to_jira!
41
+ JiraReporting::SLAReport.show_report
42
+ end
43
+ end
44
+
45
+ class CLI < Thor
46
+ Reporting.register_to self
47
+ end
48
+ end
49
+
50
+ CLI::CLI.start
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ PROJECT_ROOT = "#{File.dirname(__FILE__)}/../"
4
+
5
+ $:.unshift "#{File.dirname(__FILE__)}/../lib"
6
+ require 'jira_reporting'
7
+ require 'pry-byebug'
8
+ require 'active_support'
9
+ require 'yaml'
10
+
11
+ auth = YAML.load_file(File.join(PROJECT_ROOT,'auth.yml'))
12
+ jira_username = auth["jira"]["username"]
13
+ jira_password = auth["jira"]["password"]
14
+ JiraReporting.connect! jira_username, jira_password
15
+
16
+ # Closed TS issues
17
+ start_date = (ARGV[0] && Date.parse(ARGV[0]))
18
+ end_date = (ARGV[1] && Date.parse(ARGV[1]))
19
+
20
+ start_date = start_date.strftime("%Y-%m-%d")
21
+ end_date = end_date.strftime("%Y-%m-%d")
22
+
23
+ puts "Updating SLA due time and SLA status on all TS issues from: #{start_date} to: #{end_date}"
24
+
25
+ query = %Q{
26
+ project = "Tech Support"
27
+ AND created >= '#{start_date}'
28
+ AND created < '#{end_date}'
29
+ AND status not in ("Not Accepted", "Can't Reproduce")
30
+ AND type != Epic
31
+ }
32
+
33
+ ts_issues = JiraIssue.find(query)
34
+
35
+ total_ts_issues = ts_issues.count
36
+
37
+ update_start_time = Time.now
38
+
39
+ puts "The time is #{update_start_time}. There are #{total_ts_issues} issues in the query. Each issue takes about five seconds to update. The estimated amount of time this update will take is #{total_ts_issues*5/60} minutes to complete -- expected end time: #{update_start_time+total_ts_issues*5}"
40
+
41
+ ts_issues.each do |issue|
42
+ issue.set_sla_due_time! if issue.sla_due_time.nil?
43
+ issue.set_sla_triaged_at! if issue.sla_triaged_at.nil?
44
+ issue.set_over_triage_sla! if issue.over_triage_sla.nil?
45
+ issue.set_sla_closed_at! if issue.sla_closed_at.nil?
46
+ issue.set_sla_due_warning! if issue.sla_due_warning.nil?
47
+ issue.set_over_sla! if issue.over_sla.nil?
48
+ # issue.set_total_time_over_sla! if issue.total_time_over_sla.nil?
49
+
50
+ puts "#{issue.over_sla?} #{issue.sla_target}
51
+ #{issue.priority} #{issue.key} #{issue.summary}"
52
+ end
53
+
54
+ puts "SLA update completed at #{Time.now}."
data/bin/kpi_report ADDED
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/env ruby
2
+ PROJECT_ROOT = "#{File.dirname(__FILE__)}/../"
3
+
4
+ $:.unshift "#{File.dirname(__FILE__)}/../lib"
5
+ require 'jira_reporting'
6
+ require 'pry-byebug'
7
+ require 'active_support'
8
+ require 'yaml'
9
+ require 'code_climate'
10
+ require 'auto_hash'
11
+ require 'pull_request'
12
+ require 'os'
13
+
14
+ report = AutoHash.new
15
+
16
+ auth = YAML.load_file(File.join(PROJECT_ROOT,'auth.yml'))
17
+ jira_username = auth["jira"]["username"]
18
+ jira_password = auth["jira"]["password"]
19
+ JiraReporting.connect! jira_username, jira_password
20
+
21
+ github_token = auth["github"]["api_token"]
22
+ PullRequest.connect(github_token)
23
+
24
+ end_date = (ARGV[0] && Date.parse(ARGV[0]) - 1.day) || 1.day.ago
25
+ start_date = (ARGV[1] && Date.parse(ARGV[1])) || end_date - 6.days
26
+
27
+ start_date = start_date.strftime("%Y-%m-%d")
28
+ end_date = end_date.strftime("%Y-%m-%d")
29
+
30
+ puts "Start: #{start_date} END: #{end_date}"
31
+
32
+ # All tickets closed last week in all dev projects (not DO?)
33
+ # * TS SLA hit-rates (% completed in SLA)
34
+ # * Sum of story points
35
+ # * % of tickets with story points set (estimated)
36
+ # * Count of active sprints (teams)
37
+
38
+ # Closed issues that had a status change in the last week
39
+ query = %Q{
40
+ project in (TS, TECH, OT, BLINQ, DT, BULQ)
41
+ AND status changed
42
+ TO ("Not Accepted", "Can't Reproduce", "Requester Review", Deploy, Merged, MERGED_ST, "On Production", Completed, Resolved)
43
+ DURING ('#{start_date}', '#{end_date}')
44
+ }
45
+
46
+ issues = JiraIssue.find(query)
47
+
48
+ ts_issues, non_ts_issues = issues.partition { |issue| issue.project == "TS" }
49
+
50
+ total_points = non_ts_issues.map{|issue| issue.story_points.to_s.to_f}.sum
51
+ count_pointed = non_ts_issues.count{|issue| issue.story_points}
52
+
53
+ ts_issue_count = ts_issues.count
54
+ ts_bug_count = ts_issues.select(&:bug?).count
55
+ ts_ops_count = ts_issues.reject(&:bug?).count
56
+
57
+ non_ts_issue_count = non_ts_issues.count
58
+ total_issue_count = issues.count
59
+
60
+ ts_bugs = ts_issues.select(&:bug?)
61
+ ts_bugs_triage_hours = ts_bugs.map { |issue| issue.status_ages["Triaged"] }.compact.sum
62
+
63
+ report[:week] = {
64
+ issue_count: total_issue_count,
65
+ ts_count: ts_issue_count,
66
+ non_ts_count: issues.count - ts_issue_count,
67
+ story_points: total_points,
68
+ pointed_rate: (count_pointed.to_f / non_ts_issue_count * 100).round(2),
69
+ bug_rate: (ts_bug_count.to_f / total_issue_count * 100).round(2),
70
+ ops_rate: (ts_ops_count.to_f / total_issue_count * 100).round(2),
71
+ ts_rate: (ts_issue_count.to_f / total_issue_count * 100).round(2),
72
+ ts_bugs_triage_speed: (ts_bugs_triage_hours / ts_bugs.count).round(2)
73
+ }
74
+
75
+ prios = ts_issues.group_by(&:priority)
76
+
77
+ hour = 60 * 60.0
78
+ ideal_times = {
79
+ p1: 2 * hour,
80
+ p2: 24 * hour,
81
+ p3: (24 * hour) * 3, # 3 business days
82
+ p4: (24 * hour) * 5, # 5 business days
83
+ p5: (24 * hour) * 30, # 30 business days
84
+ }
85
+
86
+ [:p1,:p2,:p3,:p4,:p5].each do |priority|
87
+ closed = prios[priority] || []
88
+ trend_time = closed.inject(0){|s,t| s + t.sla_diff } / closed.length.to_f
89
+
90
+
91
+ trend_resolution_time = ""
92
+ if closed.any?
93
+ mm, ss = trend_time.divmod(60)
94
+ hh, mm = mm.divmod(60)
95
+ dd, hh = hh.divmod(24)
96
+ trend_resolution_time = "#{dd}d #{hh.to_i}h #{mm.to_i}m #{ss.to_i}s"
97
+ end
98
+
99
+ ideal_time = ideal_times[priority]
100
+ multiple_off_ideal = trend_time.to_f / ideal_time
101
+
102
+ trend_hit = 1.0
103
+ trend_hit = closed.select{|t| t.sla_diff <= 0 }.length / closed.length.to_f if closed.any?
104
+
105
+ report[:sla][priority] = {
106
+ closed_tickets: closed.count,
107
+ avg_sla_diff: trend_resolution_time,
108
+ avg_sla_multiple: (multiple_off_ideal || 0).round(2),
109
+ avg_hit_rate: (trend_hit * 100).round(2),
110
+ }
111
+
112
+ puts "#{priority.to_s.upcase}:"
113
+ puts "Closed Tickets: #{closed.count}"
114
+ puts "Avg Diff to SLA: #{trend_resolution_time}"
115
+ puts "Avg SLA Multiple: #{multiple_off_ideal.round(2)}x" unless priority == :p4
116
+ puts "Avg Hit Rate: #{(trend_hit * 100).round(2)}%"
117
+ puts ""
118
+ end
119
+
120
+ puts ""
121
+ puts "Issues over the SLA:"
122
+ ts_issues.sort_by(&:priority).each do |ts|
123
+ if ts.sla_diff < 0
124
+ puts "#{ts.priority}\t#{ts.key}"
125
+ end
126
+ end
127
+
128
+ overall_hit = ts_issues.select{|t| t.sla_diff <= 0 }.length / ts_issues.length.to_f
129
+ report[:sla][:overall][:avg_hit_rate] = (overall_hit * 100).round(2)
130
+ puts ""
131
+ puts "Overall Avg Hit Rate: #{(overall_hit * 100).round(2)}%"
132
+ puts
133
+
134
+ code_climate = CodeClimate.new(auth["code_climate"]["api_token"])
135
+
136
+ ["inventory", "blinq", "bulq"].each do |repo_name|
137
+ puts "CodeClimate Repo #{repo_name}"
138
+ cc_snapshot = code_climate.repo_details_by_name(repo_name)["last_snapshot"]
139
+
140
+ report[:codeclimate][repo_name.to_sym][:gpa] = cc_snapshot["gpa"]
141
+ report[:codeclimate][repo_name.to_sym][:coverage] = cc_snapshot["covered_percent"] || 0
142
+ puts "GPA: #{cc_snapshot["gpa"]}"
143
+ puts "Coverage: #{cc_snapshot["covered_percent"] || 0}%"
144
+ puts
145
+ end
146
+
147
+ report[:codeclimate][:overall][:coverage] = (
148
+ report[:codeclimate][:inventory][:coverage] + report[:codeclimate][:blinq][:coverage]
149
+ ) / 2.0
150
+
151
+ # # Temporarily disabled to test functionality
152
+ # # Github PR info
153
+ # prs = PullRequest.get_prs('inventory')
154
+ # today = Time.now.to_date
155
+ # pr_ages = prs.map{|pr| (today - pr.created.to_datetime).to_i}
156
+ # report[:pr][:avg_age_days] = (pr_ages.sum.to_f / pr_ages.count).round(2)
157
+ # report[:pr][:open_count] = prs.count
158
+
159
+ # closed_prs = PullRequest.get_prs('inventory', state: "closed")
160
+
161
+ def copy_paste_string(report)
162
+ [
163
+ report[:sla][:overall][:avg_hit_rate].to_s+'%', # TS combined SLA
164
+ report[:sla][:p1][:avg_hit_rate].to_s+'%', # TS P1 SLA
165
+ report[:sla][:p2][:avg_hit_rate].to_s+'%', # TS P2 SLA
166
+ report[:sla][:p3][:avg_hit_rate].to_s+'%', # TS P3 SLA
167
+ report[:sla][:p4][:avg_hit_rate].to_s+'%', # TS P4 SLA
168
+ report[:week][:ts_count], # Weighted TS tickets closed
169
+ report[:week][:bug_rate].to_s + '%', # Bug / Fires %
170
+ report[:week][:ops_rate].to_s + '%', # Operational Requests %
171
+ report[:codeclimate][:overall][:coverage].to_s + '%', # Test Coverage (combined)
172
+ report[:codeclimate][:inventory][:coverage].to_s + '%', # Test Coverage - OT
173
+ report[:codeclimate][:blinq][:coverage].to_s + '%', # Test Coverage - BLINQ
174
+ report[:codeclimate][:inventory][:gpa], # CodeClimage GPA - OT
175
+ report[:codeclimate][:blinq][:gpa], # CodeClimage GPA - BLINQ
176
+ report[:codeclimate][:bulq][:gpa], # CodeClimage GPA - BLINQ
177
+ report[:pr][:avg_age_days], # Average age of PRs
178
+ report[:week][:ts_bugs_triage_speed], # Triage speed
179
+ ].join("\n")
180
+ end
181
+
182
+ # puts "Full report:"
183
+ # puts report.inspect
184
+
185
+ # Copy/pasteable
186
+ puts "Copy/paste:\n----------"
187
+ puts copy_paste_string(report)
188
+ puts "-----------"
189
+
190
+ # Works on either?
191
+ case
192
+ when OS.linux? == true
193
+ IO.popen("xclip -selection clipboard", "r+") do |xclip|
194
+ xclip.puts copy_paste_string(report)
195
+ end
196
+ when OS.mac? == true
197
+ IO.popen("pbcopy", "r+") do |pbcopy|
198
+ pbcopy.puts copy_paste_string(report)
199
+ end
200
+ else
201
+ puts "Please manually copy and paste the output into the KPI spreadsheet"
202
+ end
203
+
204
+ # issues.map{|i| Hash[i.status_changes.group_by{|s| s["fromString"]}.map{|k,v| [k => v.inject(0.0) {|n,x| n + x["age_hours"]}]}]}