Skip to content

Instantly share code, notes, and snippets.

@fairchild
Created October 23, 2008 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fairchild/18899 to your computer and use it in GitHub Desktop.
Save fairchild/18899 to your computer and use it in GitHub Desktop.
#Query LH for ticket, and update db cache. Allow ticket number or lh ticket object
def self.update_or_create_from_lighthouse(ticket, project_id)
lh_ticket = case ticket.class
when Fixnum: Ticket.retrieve_from_lh(ticket, project_id)
when Lighthouse::Ticket: Ticket.retrieve_from_lh(ticket.number, project_id)
else return false
end
if lh_ticket == 404 #delete ticket if it was deleted from LH
Ticket[:number=>ticket, :project_id=>project_id].destroy
else
if ticket = Ticket[:number=>lh_ticket.last['number'], :project_id=>project_id]
ticket.update( self.build_attributes(lh_ticket) )
else
#TODO: add exception handling when create fails. probably just retry a few times
t=Ticket.new( self.build_attributes(lh_ticket) )
t.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment