Class: Lazylead::Task::Parent
- Inherits:
-
Object
- Object
- Lazylead::Task::Parent
- Defined in:
- lib/lazylead/task/propagate_down.rb
Overview
The parent ticket as a source for propagation to children.
Instance Method Summary collapse
-
#comment(diff) ⇒ Object
Build a jira comment in markdown(*.md) format with diff table.
-
#diff(expected, actual) ⇒ Object
Detect difference between fields in parent ticket and sub-task.
-
#fetch ⇒ Object
Take sub-tasks with their fields from external JIRA system.
-
#initialize(issue, sys, fields) ⇒ Parent
constructor
A new instance of Parent.
-
#propagate ⇒ Object
Fill pre-defined fields for sub-tasks from parent ticket and post comment to ticket with clarification.
-
#subtasks? ⇒ Boolean
Ensure that parent ticket has sub-tasks.
Constructor Details
#initialize(issue, sys, fields) ⇒ Parent
Returns a new instance of Parent.
68 69 70 71 72 |
# File 'lib/lazylead/task/propagate_down.rb', line 68 def initialize(issue, sys, fields) @issue = issue @sys = sys @fields = fields end |
Instance Method Details
#comment(diff) ⇒ Object
Build a jira comment in markdown(*.md) format with diff table.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/lazylead/task/propagate_down.rb', line 114 def comment(diff) markdown = [ "The following fields were propagated from #{@issue.key}:", "||Field||Value||" ] diff.each { |k, v| markdown << "|#{k}|#{v}|" } markdown << "Posted by [lazylead v#{Lazylead::VERSION}|" \ "https://bit.ly/2NjdndS]" markdown.join("\r\n") end |
#diff(expected, actual) ⇒ Object
Detect difference between fields in parent ticket and sub-task. The sub-tasks expected be updated by this diff.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/lazylead/task/propagate_down.rb', line 102 def diff(expected, actual) diff = {} actual.each_with_object(diff) do |a, d| k = a.first v = a.last d[k] = expected[k] if v.nil? || v.blank? next if v.nil? d[k] = "#{v},#{expected[k]}" unless v.to_s.include? expected[k] end end |
#fetch ⇒ Object
Take sub-tasks with their fields from external JIRA system.
80 81 82 83 84 85 |
# File 'lib/lazylead/task/propagate_down.rb', line 80 def fetch @subtasks = @issue.fields["subtasks"] .map do |sub| @sys.raw { |j| j.Issue.find(sub["id"]) } end end |
#propagate ⇒ Object
Fill pre-defined fields for sub-tasks from parent ticket
and post comment to ticket with clarification.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/lazylead/task/propagate_down.rb', line 89 def propagate expected = @fields.collect { |f| [f, @issue.fields[f]] }.to_h @subtasks.each do |subtask| actual = @fields.collect { |f| [f, subtask.fields[f]] }.to_h diff = diff(expected, actual) next if diff.empty? subtask.save(fields: diff) subtask.comments.build.save!(body: comment(diff)) end end |
#subtasks? ⇒ Boolean
Ensure that parent ticket has sub-tasks.
75 76 77 |
# File 'lib/lazylead/task/propagate_down.rb', line 75 def subtasks? !@issue.fields["subtasks"].empty? end |