Class: Lazylead::Labels

Inherits:
Object
  • Object
show all
Defined in:
lib/lazylead/task/accuracy/onlyll.rb

Overview

The ticket with grid labels

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(issue, opts) ⇒ Labels

Returns a new instance of Labels.



59
60
61
62
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 59

def initialize(issue, opts)
  @issue = issue
  @opts = opts
end

Instance Attribute Details

#issueObject (readonly)

Returns the value of attribute issue.



57
58
59
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 57

def issue
  @issue
end

Instance Method Details

#diff(record) ⇒ Object

Detect label diff in single history record from ticket’s history.



128
129
130
131
132
133
134
135
136
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 128

def diff(record)
  record["items"].select { |f| f["field"].eql? "labels" }
                 .reject { |f| f["toString"].nil? || f["toString"].blank? }
                 .map do |f|
    from = []
    from = f["fromString"].split unless f["fromString"].nil?
    f["toString"].split - from
  end
end

#exists?Boolean

Ensure that issue has evaluation labels for accuracy rules

Returns:

  • (Boolean)


65
66
67
68
69
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 65

def exists?
  return false if @issue.labels.nil? || @issue.labels.empty?
  return false unless @issue.labels.is_a? Array
  grid.any? { |g| @issue.labels.any? { |l| g.eql? l } }
end

#gridObject

Detect the percentage grid for tickets, by default its 0%, 10%, 20%, etc.



96
97
98
99
100
101
102
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 96

def grid
  @grid ||= if @opts.key? "grid"
              @opts.slice("grid", ",")
            else
              %w[0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%]
            end
end

#grid?(record) ⇒ Boolean

Ensure that history record has label change related to LL grid labels.

Returns:

  • (Boolean)

    true if LL grid labels added



123
124
125
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 123

def grid?(record)
  diff(record).any? { |d| d.find { |l| grid.any? { |g| l.eql? g } } }
end

#hacked(record) ⇒ Object

Hacked score by violator in ticket’s history.



139
140
141
142
143
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 139

def hacked(record)
  diff(record.first)
    .first
    .find { |l| grid.any? { |g| l.eql? g } }
end

#removeObject

Remove score labels from the ticket.



105
106
107
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 105

def remove
  @issue.labels!(@issue.labels - grid)
end

#scoreObject

Find expected ticket score evaluated by LL. If LL evaluated the same ticket several times (no matter why),

then the last score would be returned.


80
81
82
83
84
85
86
87
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 80

def score
  to_l(
    @issue.history
          .select { |h| h["author"]["key"].eql? @opts["author"] }
          .reverse
          .find { |h| to_l(h) }
  ).fetch("toString", "").split.find { |l| grid.any? { |g| l.eql? g } }
end

#to_l(history) ⇒ Object

Find history record with labels changes.



90
91
92
93
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 90

def to_l(history)
  return {} if history.nil? || history.empty?
  history["items"].find { |f| f["field"].eql? "labels" }
end

#valid?Boolean

Compare the score evaluated by LL and current ticket score.

Returns:

  • (Boolean)

    true if current score equal to LL evaluation



73
74
75
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 73

def valid?
  score.eql?(@issue.labels.sort.find { |l| grid.any? { |g| l.eql? g } })
end

#violatorsObject

Detect the violators with their changes.

.violators  => ["Tom Hhhh set 40%", "Bob Mmmm set 50%"]


111
112
113
114
115
116
117
118
119
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 111

def violators
  @issue.history
        .reject { |h| h["author"]["key"].eql? @opts["author"] }
        .select { |h| grid?(h) }
        .group_by { |h| h["author"]["key"] }
        .map do |a|
    "#{a.last.first['author']['displayName']} set #{hacked(a.last)}"
  end
end