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.



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

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

Instance Method Details

#[](name) ⇒ Object



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

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

#add_label(label, *more) ⇒ Object



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

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

#assigneeObject



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

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

#attachmentsObject



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

def attachments
  @issue.attachments
end

#commentsObject



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

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

#componentsObject



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

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

#descriptionObject



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

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

#duedateObject



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

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

#fieldsObject



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

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



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

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

#idObject



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

def id
  @issue.id
end

#inspectObject



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

def inspect
  to_s
end

#keyObject



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

def key
  @issue.key
end

#labelsObject

Get the labels for a particular issue



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

def labels
  fields["labels"]
end

#labels!(lbl) ⇒ Object

Update the labels for a particular issue



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

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

#post(markdown) ⇒ Object



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

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

#priorityObject



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

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


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

def remote_links
  @issue.remotelink.all
end

#reporterObject



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

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

#save!(opts) ⇒ Object



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

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

#statusObject



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

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

#summaryObject



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

def summary
  fields["summary"]
end

#to_sObject



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

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

#urlObject



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

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