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.



146
147
148
149
# File 'lib/lazylead/system/jira.rb', line 146

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

Instance Method Details

#[](name) ⇒ Object



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

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

#add_label(label, *more) ⇒ Object



244
245
246
247
248
249
250
# File 'lib/lazylead/system/jira.rb', line 244

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

#assigneeObject



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

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

#attachmentsObject



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

def attachments
  @issue.attachments
end

#commentsObject



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

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

#componentsObject



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

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

#descriptionObject



159
160
161
162
# File 'lib/lazylead/system/jira.rb', line 159

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

#duedateObject



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

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

#fieldsObject



188
189
190
191
192
193
194
# File 'lib/lazylead/system/jira.rb', line 188

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



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

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

#idObject



151
152
153
# File 'lib/lazylead/system/jira.rb', line 151

def id
  @issue.id
end

#inspectObject



224
225
226
# File 'lib/lazylead/system/jira.rb', line 224

def inspect
  to_s
end

#keyObject



155
156
157
# File 'lib/lazylead/system/jira.rb', line 155

def key
  @issue.key
end

#labelsObject

Get the labels for a particular issue



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

def labels
  fields["labels"]
end

#labels!(lbl) ⇒ Object

Update the labels for a particular issue



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

def labels!(lbl)
  return if lbl.nil? || lbl.empty?
  save!("fields" => { "labels" => lbl.uniq })
end

#post(markdown) ⇒ Object



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

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

#priorityObject



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

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


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

def remote_links
  @issue.remotelink.all
end

#reporterObject



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

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

#save!(opts) ⇒ Object



263
264
265
# File 'lib/lazylead/system/jira.rb', line 263

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

#statusObject



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

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

#summaryObject



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

def summary
  fields["summary"]
end

#to_sObject



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

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

#urlObject



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

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