firespring_dev_commands 2.1.4 → 2.1.5.pre.alpha.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fce0dd484a49e3592b3f22529aa7a6ef2defb6c41c726723e110b7158407b4e
4
- data.tar.gz: 1eec4909f5334c7143cb781c60d257f0831b4821c03dc2f1ca4a355c546b4cf1
3
+ metadata.gz: dd4e9c404b454fa28f3c5f304650a0f01f239c431abe85564fe607a823831435
4
+ data.tar.gz: bec27dda7e74159eebabfbc887039b322719f3d67e7e6452b03330dca4f40423
5
5
  SHA512:
6
- metadata.gz: f1a4f4645dd0dcba99bd01ad567b08b8e10fddd1cfbdc67b6c65326bb1476eed6c98a40124d889d6b33b795aa8cc9419e067108fa0cbf165a3dbc5ea248e76bc
7
- data.tar.gz: e3f8f91c2769aba3b60053e5913c8955183f829c574a6b6e93cfd548ae9e1ead60b3bcaa500e53b5cfe22e1cfe9d76ce46fa9b45cb75433d49daee9629ade166
6
+ metadata.gz: 89627e72ff5bb6ceb2376c3ea8d6fcb1d0eea44282625aac659c61768b3df02b578eedca4cfff4ccfe87479a06e93962623689d3e03441236aa312f96662c672
7
+ data.tar.gz: 30b9d89762dcdeb8f781675eb2a5cdbf06047b2266920f1a59209c62030304e16919bc3311ee187d26e4f414d64d72a04ecd912649a8042cfca316e16cdd4324
@@ -0,0 +1,13 @@
1
+ require 'pry'
2
+
3
+ module Dev
4
+ class Jira
5
+ class Histories
6
+ def self.populate(data)
7
+ return nil unless data.attrs.key?('changelog')
8
+
9
+ data.changelog['histories'].map { |it| Jira::History.new(it) }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'date'
2
+
3
+ module Dev
4
+ class Jira
5
+ class History
6
+ attr_accessor :date, :id, :author, :created, :items
7
+
8
+ def initialize(data)
9
+ @data = data
10
+ @id = data['id']
11
+ @author = data['author']
12
+ @items = data['items']
13
+ @created = Time.parse(data['created'])
14
+ end
15
+ end
16
+ end
17
+ end
@@ -5,7 +5,7 @@ module Dev
5
5
  # Issue subtypes which do not map to a story type
6
6
  NON_STORY_TYPES = ['review', 'sub-task', 'code review sub-task', 'pre-deploy sub-task', 'deploy sub-task', 'devops sub-task'].freeze
7
7
 
8
- attr_accessor :data, :project, :id, :title, :points, :assignee, :resolved_date
8
+ attr_accessor :data, :project, :id, :title, :points, :assignee, :resolved_date, :histories, :in_progress_history, :in_review_history, :closed_history
9
9
 
10
10
  def initialize(data)
11
11
  @data = data
@@ -15,10 +15,71 @@ module Dev
15
15
  @points = calculate_points(data)
16
16
  @assignee = Jira::User.lookup(data.assignee&.accountId)
17
17
  @resolved_date = data.resolutiondate
18
+ @histories = Jira::Histories.populate(data)
19
+ @in_progress_history = nil
20
+ @in_review_history = nil
21
+ @closed_history = nil
22
+ end
23
+
24
+ def cycle_time
25
+ # Calculate the difference and convert to days
26
+ ((last_closed_history.created - first_in_progress_history.created) / 60 / 60 / 24).round(2)
27
+ end
28
+
29
+ def in_progress_cycle_time
30
+ # Calculate the difference and convert to days
31
+ ((first_in_review_history.created - first_in_progress_history.created) / 60 / 60 / 24).round(2)
32
+ end
33
+
34
+ def in_review_cycle_time
35
+ # Calculate the difference and convert to days
36
+ ((last_closed_history.created - first_in_review_history.created) / 60 / 60 / 24).round(2)
37
+ end
38
+
39
+ private def first_in_progress_history
40
+ raise 'you must expand the changelog field to calculate cycle time' if histories.nil?
41
+
42
+ # Find the first instance in the histoy where the status moved to "In Progress"
43
+ @in_progress_history ||= histories.select do |history|
44
+ history.items.find do |item|
45
+ item['fieldId'] == 'status' && item['toString'] == 'In Progress'
46
+ end
47
+ end.min_by(&:created)
48
+ raise 'unable to find "In Progress" history entry needed to calculate cycle time' unless @in_progress_history
49
+
50
+ @in_progress_history
51
+ end
52
+
53
+ private def first_in_review_history
54
+ raise 'you must expand the changelog field to calculate cycle time' if histories.nil?
55
+
56
+ # Find the first instance in the histoy where the status moved to "In Review"
57
+ @in_review_history ||= histories.select do |history|
58
+ history.items.find do |item|
59
+ item['fieldId'] == 'status' && item['toString'] == 'In Review'
60
+ end
61
+ end.min_by(&:created)
62
+ raise 'unable to find "In Review" history entry needed to calculate cycle time' unless @in_review_history
63
+
64
+ @in_review_history
65
+ end
66
+
67
+ private def last_closed_history
68
+ raise 'you must expand the changelog field to calculate cycle time' if histories.nil?
69
+
70
+ # Find the last instance in the histoy where the status moved to "Closed"
71
+ @closed_history ||= histories.select do |history|
72
+ history.items.find do |item|
73
+ item['fieldId'] == 'status' && item['toString'] == 'Closed'
74
+ end
75
+ end.max_by(&:created)
76
+ raise 'unable to find "Closed" history entry needed to calculate cycle time' unless @closed_history
77
+
78
+ @closed_history
18
79
  end
19
80
 
20
81
  # Returns the value of the jira points field or 0 if the field is not found
21
- def calculate_points(data)
82
+ private def calculate_points(data)
22
83
  return data.send(Dev::Jira.config.points_field_name).to_i if Dev::Jira.config.points_field_name && data.respond_to?(Dev::Jira.config.points_field_name)
23
84
 
24
85
  0
@@ -9,15 +9,16 @@ module Dev
9
9
  # "user_lookup_list" should be an array of Jira::User objects representing the usernames, ids, etc for all jira users
10
10
  # This is a bit clumsy but currently the jira api only returns the user id with issues
11
11
  # and there is no way to query this information from Jira directly.
12
- Config = Struct.new(:username, :token, :url, :points_field_name, :user_lookup_list, :read_timeout, :http_debug) do
12
+ Config = Struct.new(:username, :token, :url, :points_field_name, :expand, :user_lookup_list, :read_timeout, :http_debug) do
13
13
  def initialize
14
14
  self.username = nil
15
15
  self.token = nil
16
16
  self.url = nil
17
17
  self.points_field_name = nil
18
+ self.expand = []
18
19
  self.user_lookup_list = []
19
20
  self.read_timeout = 120
20
- self.http_debug = false
21
+ self.http_debug = true
21
22
  end
22
23
  end
23
24
 
@@ -62,15 +63,16 @@ module Dev
62
63
  def issues(jql, &)
63
64
  start_at = 0
64
65
  max_results = 100
66
+ expand = self.class.config.expand
65
67
 
66
68
  # Query Jira and yield all issues it returns
67
- issues = @client.Issue.jql(jql, start_at:, max_results:)
69
+ issues = @client.Issue.jql(jql, start_at:, max_results:, expand:)
68
70
  issues.map { |data| Issue.new(data) }.each(&)
69
71
 
70
72
  # If we returned the max_results then there may be more - add the max results to where we start at and query again
71
73
  while issues.length >= max_results
72
74
  start_at += max_results
73
- issues = @client.Issue.jql(jql, start_at:, max_results:)
75
+ issues = @client.Issue.jql(jql, start_at:, max_results:, expand:)
74
76
  issues.map { |data| Issue.new(data) }.each(&)
75
77
  end
76
78
  end
@@ -6,6 +6,6 @@ module Dev
6
6
  # Use 'v.v.v.pre.alpha.v' for pre-release vesions
7
7
  # Use 'v.v.v.beta.v for beta versions
8
8
  # Use semantic versioning for any releases (https://semver.org/)
9
- VERSION = '2.1.4'.freeze
9
+ VERSION = '2.1.5.pre.alpha.1'.freeze
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firespring_dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5.pre.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
@@ -284,6 +284,8 @@ files:
284
284
  - lib/firespring_dev_commands/git.rb
285
285
  - lib/firespring_dev_commands/git/info.rb
286
286
  - lib/firespring_dev_commands/jira.rb
287
+ - lib/firespring_dev_commands/jira/histories.rb
288
+ - lib/firespring_dev_commands/jira/history.rb
287
289
  - lib/firespring_dev_commands/jira/issue.rb
288
290
  - lib/firespring_dev_commands/jira/project.rb
289
291
  - lib/firespring_dev_commands/jira/user.rb
@@ -331,9 +333,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
331
333
  version: '3.1'
332
334
  required_rubygems_version: !ruby/object:Gem::Requirement
333
335
  requirements:
334
- - - ">="
336
+ - - ">"
335
337
  - !ruby/object:Gem::Version
336
- version: '0'
338
+ version: 1.3.1
337
339
  requirements: []
338
340
  rubygems_version: 3.4.10
339
341
  signing_key: