git_integration_base.rb 850 B

123456789101112131415161718192021222324
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class GitIntegrationBase
  3. attr_reader :client, :issue_type
  4. def fix_urls_for_ticket(ticket_id, url_replacements)
  5. return if ticket_id.blank?
  6. return if url_replacements.blank?
  7. ticket = Ticket.find_by(id: ticket_id)
  8. return if ticket.blank?
  9. return if ticket.preferences.blank?
  10. return if ticket.preferences[issue_type].blank?
  11. return if ticket.preferences[issue_type][:issue_links].blank?
  12. ticket.with_lock do
  13. new_issue_links = Array(ticket.preferences[issue_type][:issue_links])
  14. new_issue_links.map! { |original_link| url_replacements[original_link].presence ? url_replacements[original_link] : original_link }
  15. ticket.preferences[issue_type][:issue_links] = Array(new_issue_links).uniq
  16. ticket.save!
  17. end
  18. end
  19. end