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.



157
158
159
160
# File 'lib/lazylead/system/jira.rb', line 157

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

Instance Method Details

#[](name) ⇒ Object



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

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

#add_label(label, *more) ⇒ Object



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

def add_label(label, *more)
  lbl = labels
  lbl = [] if lbl.nil?
  lbl << label
  lbl += more if more.size.positive?
  save!("fields" => { "labels" => lbl.uniq })
end

#assigneeObject



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

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

#attachmentsObject



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

def attachments
  @issue.attachments
end

#commentsObject



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

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

#componentsObject



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

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

#descriptionObject



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

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

#duedateObject



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

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

#fieldsObject



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

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



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

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

#idObject



162
163
164
# File 'lib/lazylead/system/jira.rb', line 162

def id
  @issue.id
end

#inspectObject



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

def inspect
  to_s
end

#keyObject



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

def key
  @issue.key
end

#labelsObject



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

def labels
  fields["labels"]
end

#post(markdown) ⇒ Object



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

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

#priorityObject



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

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


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

def remote_links
  @issue.remotelink.all
end

#reporterObject



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

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

#save!(opts) ⇒ Object



267
268
269
# File 'lib/lazylead/system/jira.rb', line 267

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

#statusObject



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

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

#summaryObject



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

def summary
  fields["summary"]
end

#to_sObject



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

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

#urlObject



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

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