Class: TicketAbstractorClient::Jira::Ticket
Instance Attribute Summary
Attributes inherited from Base::Ticket
#changes, #communications_stack, #endpoint, #fields, #project, #status, #ticket_id
Class Method Summary
collapse
Instance Method Summary
collapse
#any_changes?, #reset_changes!, #to_hash, #to_json
Constructor Details
#initialize(opts) ⇒ Ticket
Returns a new instance of Ticket.
15
16
17
18
19
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 15
def initialize(opts)
super(opts)
@fields['project'] = @project if @project.present?
@status = @fields.delete('status')
end
|
Class Method Details
.fetch_by_id(opts) ⇒ Object
5
6
7
8
9
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 5
def self.fetch_by_id(opts)
opts[:fields] ||= []
opts[:fields] += %w(-attachment -comment)
fetch(:by_id, opts).first
end
|
.fetch_tickets_by_jql(opts) ⇒ Object
11
12
13
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 11
def self.fetch_tickets_by_jql(opts)
fetch(:by_jql, opts)
end
|
Instance Method Details
#add_attachment(attachment) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 21
def add_attachment(attachment)
@attachments ||= []
@attachments << Attachment.new(attachment.merge(ticket_id: @ticket_id, endpoint: @endpoint, project: @project))
@changes[:new_attachments] += 1
self
end
|
28
29
30
31
32
33
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 28
def ()
@comments ||= []
@comments << Comment.new(.merge(ticket_id: @ticket_id, endpoint: @endpoint, project: @project))
@changes[:new_comments] += 1
self
end
|
#attachments ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 35
def attachments
return @attachments if @attachments.present?
return [] if @ticket_id.blank? && @attachments.blank?
@attachments = Attachment.fetch(@ticket_id, @endpoint)
end
|
#available_statuses ⇒ Object
43
44
45
46
47
48
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 43
def available_statuses
raw_response = Client.new(@endpoint).transitions_list(@ticket_id)
raw_response['transitions'].each_with_object({}) do |transition, transitions_map|
transitions_map[transition['to']['name']] = transition['id']
end
end
|
50
51
52
53
54
55
56
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 50
def
return @comments if @comments.present?
return [] if @ticket_id.blank? && @comments.blank?
@comments = Comment.fetch(@ticket_id, @endpoint)
end
|
#reload! ⇒ Object
58
59
60
61
62
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 58
def reload!
ticket = Ticket.fetch_by_id(ticket_id: @ticket_id, project: @project, endpoint: @endpoint)
@fields = ticket.fields
@status = ticket.status
end
|
#sync! ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 64
def sync!
raise(Errors::TicketArgumentError, 'No changes to apply') unless self.any_changes?
return create_ticket if @changes[:create]
update_ticket if @changes[:update]
update_status if @changes[:new_status]
unless @changes[:new_comments].zero?
sync_attachments unless @changes[:new_attachments].zero?
self.reload!
self.reset_changes!
self
end
|
#updated_at ⇒ Object
79
80
81
|
# File 'lib/ticket_abstractor_client/jira/ticket.rb', line 79
def updated_at
@fields['updated']
end
|