Class: Lazylead::Issue
- Inherits:
-
Object
- Object
- Lazylead::Issue
- Defined in:
- lib/lazylead/system/jira.rb
Overview
An issue from Jira
- Author
-
Yurii Dubinka ([email protected])
- Copyright
-
Copyright © 2019-2020 Yurii Dubinka
- License
-
MIT
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add_label(label, *more) ⇒ Object
- #assignee ⇒ Object
- #attachments ⇒ Object
- #comments ⇒ Object
- #components ⇒ Object
- #description ⇒ Object
- #duedate ⇒ Object
- #fields ⇒ Object
- #history ⇒ Object
- #id ⇒ Object
-
#initialize(issue, jira) ⇒ Issue
constructor
A new instance of Issue.
- #inspect ⇒ Object
- #key ⇒ Object
-
#labels ⇒ Object
Get the labels for a particular issue.
-
#labels!(lbl) ⇒ Object
Update the labels for a particular issue.
- #post(markdown) ⇒ Object
- #priority ⇒ Object
- #remote_links ⇒ Object
- #reporter ⇒ Object
- #save!(opts) ⇒ Object
- #sprint(field = "customfield_10480") ⇒ Object
- #status ⇒ Object
- #summary ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(issue, jira) ⇒ Issue
Returns a new instance of Issue.
143 144 145 146 |
# File 'lib/lazylead/system/jira.rb', line 143 def initialize(issue, jira) @issue = issue @jira = jira end |
Instance Method Details
#[](name) ⇒ Object
193 194 195 196 |
# File 'lib/lazylead/system/jira.rb', line 193 def [](name) return "" if fields[name].nil? || fields[name].blank? fields[name] end |
#add_label(label, *more) ⇒ Object
241 242 243 244 245 246 247 |
# File 'lib/lazylead/system/jira.rb', line 241 def add_label(label, *more) lbl = labels lbl = [] if lbl.nil? lbl << label lbl += more if more.size.positive? labels! lbl end |
#assignee ⇒ Object
181 182 183 |
# File 'lib/lazylead/system/jira.rb', line 181 def assignee Lazylead::User.new(@issue.assignee.attrs) end |
#attachments ⇒ Object
237 238 239 |
# File 'lib/lazylead/system/jira.rb', line 237 def @issue. end |
#comments ⇒ Object
210 211 212 213 214 215 |
# File 'lib/lazylead/system/jira.rb', line 210 def comments return @comments if defined? @comments @comments = @jira.Issue.find(@issue.id, expand: "comments", fields: "") .comments .map { |c| Comment.new(c) } end |
#components ⇒ Object
198 199 200 201 202 |
# File 'lib/lazylead/system/jira.rb', line 198 def components return [] unless @issue.respond_to? :components return [] if @issue.components.nil? @issue.components.map(&:name) end |
#description ⇒ Object
156 157 158 159 |
# File 'lib/lazylead/system/jira.rb', line 156 def description return "" if @issue.description.nil? @issue.description end |
#duedate ⇒ Object
169 170 171 |
# File 'lib/lazylead/system/jira.rb', line 169 def duedate @issue.fields["duedate"] end |
#fields ⇒ Object
185 186 187 188 189 190 191 |
# File 'lib/lazylead/system/jira.rb', line 185 def fields return {} if @issue.nil? return {} unless @issue.respond_to? :fields return {} if @issue.fields.nil? return {} unless @issue.fields.respond_to? :[] @issue.fields end |
#history ⇒ Object
204 205 206 207 208 |
# File 'lib/lazylead/system/jira.rb', line 204 def history return [] unless @issue.respond_to? :changelog return [] if @issue.changelog == nil? || @issue.changelog.empty? @issue.changelog["histories"] end |
#id ⇒ Object
148 149 150 |
# File 'lib/lazylead/system/jira.rb', line 148 def id @issue.id end |
#inspect ⇒ Object
221 222 223 |
# File 'lib/lazylead/system/jira.rb', line 221 def inspect to_s end |
#key ⇒ Object
152 153 154 |
# File 'lib/lazylead/system/jira.rb', line 152 def key @issue.key end |
#labels ⇒ Object
Get the labels for a particular issue
250 251 252 |
# File 'lib/lazylead/system/jira.rb', line 250 def labels fields["labels"] end |
#labels!(lbl) ⇒ Object
Update the labels for a particular issue
255 256 257 |
# File 'lib/lazylead/system/jira.rb', line 255 def labels!(lbl) save!("fields" => { "labels" => lbl.uniq }) unless lbl.empty? end |
#post(markdown) ⇒ Object
229 230 231 |
# File 'lib/lazylead/system/jira.rb', line 229 def post(markdown) @issue.comments.build.save!(body: markdown) end |
#priority ⇒ Object
173 174 175 |
# File 'lib/lazylead/system/jira.rb', line 173 def priority fields["priority"]["name"] end |
#remote_links ⇒ Object
233 234 235 |
# File 'lib/lazylead/system/jira.rb', line 233 def remote_links @issue.remotelink.all end |
#reporter ⇒ Object
177 178 179 |
# File 'lib/lazylead/system/jira.rb', line 177 def reporter Lazylead::User.new(fields["reporter"]) end |
#save!(opts) ⇒ Object
259 260 261 |
# File 'lib/lazylead/system/jira.rb', line 259 def save!(opts) @issue.save(opts) end |
#sprint(field = "customfield_10480") ⇒ Object
263 264 265 266 267 268 269 |
# File 'lib/lazylead/system/jira.rb', line 263 def sprint(field = "customfield_10480") @sprint ||= if fields[field].nil? || fields[field].empty? "" else fields[field].first.split(",").find { |text| text.starts_with? "name=" }[5..] end end |
#status ⇒ Object
225 226 227 |
# File 'lib/lazylead/system/jira.rb', line 225 def status @issue.status.attrs["name"] end |
#summary ⇒ Object
161 162 163 |
# File 'lib/lazylead/system/jira.rb', line 161 def summary fields["summary"] end |
#to_s ⇒ Object
217 218 219 |
# File 'lib/lazylead/system/jira.rb', line 217 def to_s "#{key} #{summary}" end |
#url ⇒ Object
165 166 167 |
# File 'lib/lazylead/system/jira.rb', line 165 def url "#{@issue.attrs['self'].split('/rest/api/').first}/browse/#{key}" end |