Class: Lazylead::Issue

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(issue, jira) ⇒ Issue

Returns a new instance of Issue.



166
167
168
169
# File 'lib/lazylead/system/jira.rb', line 166

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

Instance Method Details

#[](name) ⇒ Object



216
217
218
219
# File 'lib/lazylead/system/jira.rb', line 216

def [](name)
  return "" if fields[name].nil? || fields[name].blank?
  fields[name]
end

#add_label(label, *more) ⇒ Object



264
265
266
267
268
269
270
# File 'lib/lazylead/system/jira.rb', line 264

def add_label(label, *more)
  lbl = labels
  lbl = [] if lbl.nil?
  lbl << label
  lbl += more if more.size.positive?
  labels! lbl
end

#assigneeObject



204
205
206
# File 'lib/lazylead/system/jira.rb', line 204

def assignee
  Lazylead::User.new(@issue.assignee.attrs)
end

#attachmentsObject



260
261
262
# File 'lib/lazylead/system/jira.rb', line 260

def attachments
  @issue.attachments
end

#commentsObject



233
234
235
236
237
238
# File 'lib/lazylead/system/jira.rb', line 233

def comments
  return @comments if defined? @comments
  @comments = @jira.Issue.find(@issue.id, expand: "comments", fields: "")
                   .comments
                   .map { |c| Comment.new(c) }
end

#componentsObject



221
222
223
224
225
# File 'lib/lazylead/system/jira.rb', line 221

def components
  return [] unless @issue.respond_to? :components
  return [] if @issue.components.nil?
  @issue.components.map(&:name)
end

#descriptionObject



179
180
181
182
# File 'lib/lazylead/system/jira.rb', line 179

def description
  return "" if @issue.description.nil?
  @issue.description
end

#duedateObject



192
193
194
# File 'lib/lazylead/system/jira.rb', line 192

def duedate
  @issue.fields["duedate"]
end

#fieldsObject



208
209
210
211
212
213
214
# File 'lib/lazylead/system/jira.rb', line 208

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

#historyObject



227
228
229
230
231
# File 'lib/lazylead/system/jira.rb', line 227

def history
  return [] unless @issue.respond_to? :changelog
  return [] if @issue.changelog == nil? || @issue.changelog.empty?
  @issue.changelog["histories"]
end

#idObject



171
172
173
# File 'lib/lazylead/system/jira.rb', line 171

def id
  @issue.id
end

#inspectObject



244
245
246
# File 'lib/lazylead/system/jira.rb', line 244

def inspect
  to_s
end

#keyObject



175
176
177
# File 'lib/lazylead/system/jira.rb', line 175

def key
  @issue.key
end

#labelsObject

Get the labels for a particular issue



273
274
275
# File 'lib/lazylead/system/jira.rb', line 273

def labels
  fields["labels"]
end

#labels!(lbl) ⇒ Object

Update the labels for a particular issue



278
279
280
# File 'lib/lazylead/system/jira.rb', line 278

def labels!(lbl)
  save!("fields" => { "labels" => lbl.uniq }) unless lbl.empty?
end

#post(markdown) ⇒ Object



252
253
254
# File 'lib/lazylead/system/jira.rb', line 252

def post(markdown)
  @issue.comments.build.save!(body: markdown)
end

#priorityObject



196
197
198
# File 'lib/lazylead/system/jira.rb', line 196

def priority
  fields["priority"]["name"]
end


256
257
258
# File 'lib/lazylead/system/jira.rb', line 256

def remote_links
  @issue.remotelink.all
end

#reporterObject



200
201
202
# File 'lib/lazylead/system/jira.rb', line 200

def reporter
  Lazylead::User.new(fields["reporter"])
end

#save!(opts) ⇒ Object



282
283
284
# File 'lib/lazylead/system/jira.rb', line 282

def save!(opts)
  @issue.save(opts)
end

#sprint(field = "customfield_10480") ⇒ Object



286
287
288
289
290
291
292
# File 'lib/lazylead/system/jira.rb', line 286

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

#statusObject



248
249
250
# File 'lib/lazylead/system/jira.rb', line 248

def status
  @issue.status.attrs["name"]
end

#summaryObject



184
185
186
# File 'lib/lazylead/system/jira.rb', line 184

def summary
  fields["summary"]
end

#to_sObject



240
241
242
# File 'lib/lazylead/system/jira.rb', line 240

def to_s
  "#{key} #{summary}"
end

#urlObject



188
189
190
# File 'lib/lazylead/system/jira.rb', line 188

def url
  "#{@issue.attrs['self'].split('/rest/api/').first}/browse/#{key}"
end