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.



164
165
166
167
# File 'lib/lazylead/system/jira.rb', line 164

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

Instance Method Details

#[](name) ⇒ Object



214
215
216
217
# File 'lib/lazylead/system/jira.rb', line 214

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

#add_label(label, *more) ⇒ Object



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

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

#assigneeObject



202
203
204
# File 'lib/lazylead/system/jira.rb', line 202

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

#attachmentsObject



258
259
260
# File 'lib/lazylead/system/jira.rb', line 258

def attachments
  @issue.attachments
end

#commentsObject



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

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

#componentsObject



219
220
221
222
223
# File 'lib/lazylead/system/jira.rb', line 219

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

#descriptionObject



177
178
179
180
# File 'lib/lazylead/system/jira.rb', line 177

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

#duedateObject



190
191
192
# File 'lib/lazylead/system/jira.rb', line 190

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

#fieldsObject



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

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



225
226
227
228
229
# File 'lib/lazylead/system/jira.rb', line 225

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

#idObject



169
170
171
# File 'lib/lazylead/system/jira.rb', line 169

def id
  @issue.id
end

#inspectObject



242
243
244
# File 'lib/lazylead/system/jira.rb', line 242

def inspect
  to_s
end

#keyObject



173
174
175
# File 'lib/lazylead/system/jira.rb', line 173

def key
  @issue.key
end

#labelsObject

Get the labels for a particular issue



271
272
273
# File 'lib/lazylead/system/jira.rb', line 271

def labels
  fields["labels"]
end

#labels!(lbl) ⇒ Object

Update the labels for a particular issue



276
277
278
# File 'lib/lazylead/system/jira.rb', line 276

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

#post(markdown) ⇒ Object



250
251
252
# File 'lib/lazylead/system/jira.rb', line 250

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

#priorityObject



194
195
196
# File 'lib/lazylead/system/jira.rb', line 194

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


254
255
256
# File 'lib/lazylead/system/jira.rb', line 254

def remote_links
  @issue.remotelink.all
end

#reporterObject



198
199
200
# File 'lib/lazylead/system/jira.rb', line 198

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

#save!(opts) ⇒ Object



280
281
282
# File 'lib/lazylead/system/jira.rb', line 280

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

#sprint(field = "customfield_10480") ⇒ Object



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

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



246
247
248
# File 'lib/lazylead/system/jira.rb', line 246

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

#summaryObject



182
183
184
# File 'lib/lazylead/system/jira.rb', line 182

def summary
  fields["summary"]
end

#to_sObject



238
239
240
# File 'lib/lazylead/system/jira.rb', line 238

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

#urlObject



186
187
188
# File 'lib/lazylead/system/jira.rb', line 186

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