class TicketAbstractorClient::Jira::Ticket
Public Class Methods
fetch_by_id(opts)
click to toggle source
# 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)
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 11 def self.fetch_tickets_by_jql(opts) fetch(:by_jql, opts) end
new(opts)
click to toggle source
Calls superclass method
TicketAbstractorClient::Base::Ticket::new
# 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
Private Class Methods
fetch(selektor, opts)
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 85 def self.fetch(selektor, opts) methods_map = { by_id: :get_ticket_by_id, by_jql: :get_tickets_by_jql } opts = opts.with_indifferent_access endpoint = opts.delete(:endpoint) raw_tickets = Client.new(endpoint).public_send(methods_map.fetch(selektor.to_sym), opts) raw_tickets = raw_tickets['issues'] if raw_tickets.key?('issues') Array.wrap(raw_tickets).map do |raw_ticket| ticket = new(ticket_id: raw_ticket['key'], endpoint: endpoint, fields: raw_ticket['fields']) filtered_ticket = filter_ticket(ticket) filtered_ticket.reset_changes! filtered_ticket end end
filter_ticket(raw_ticket)
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 100 def self.filter_ticket(raw_ticket) raw_ticket.fields.extract!('attachment', 'comment') tickets_filter_class = TicketAbstractorClient.configuration.jira_tickets_filter_class return raw_ticket if tickets_filter_class.blank? tickets_filter_class.new(raw_ticket).filter_ticket end
Public Instance Methods
add_attachment(attachment)
click to toggle source
# 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
add_comment(comment)
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 28 def add_comment(comment) @comments ||= [] @comments << Comment.new(comment.merge(ticket_id: @ticket_id, endpoint: @endpoint, project: @project)) @changes[:new_comments] += 1 self end
attachments()
click to toggle source
# 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()
click to toggle source
# 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
comments()
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 50 def comments return @comments if @comments.present? return [] if @ticket_id.blank? && @comments.blank? @comments = Comment.fetch(@ticket_id, @endpoint) end
reload!()
click to toggle source
# 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!()
click to toggle source
# 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] sync_comments unless @changes[:new_comments].zero? sync_attachments unless @changes[:new_attachments].zero? self.reload! self.reset_changes! self end
updated_at()
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 79 def updated_at @fields['updated'] end
Private Instance Methods
create_ticket()
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 109 def create_ticket response = Client.new(@endpoint).create_ticket(self) @ticket_id = response['key'] self.reload! self.reset_changes! self end
sync_attachments()
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 126 def sync_attachments @attachments.last(@changes[:new_attachments]).map(&:sync!) end
sync_comments()
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 130 def sync_comments @comments.last(@changes[:new_comments]).map(&:sync!) end
update_status()
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 118 def update_status Client.new(@endpoint).transit_ticket(self) end
update_ticket()
click to toggle source
# File lib/ticket_abstractor_client/jira/ticket.rb, line 122 def update_ticket Client.new(@endpoint).update_ticket(self) end