gitlab_controller.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Integration::GitLabController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  4. def verify
  5. gitlab = ::GitLab.new(params[:endpoint], params[:api_token], verify_ssl: params[:verify_ssl])
  6. gitlab.verify!
  7. render json: {
  8. result: 'ok',
  9. }
  10. rescue => e
  11. logger.error e
  12. render json: {
  13. result: 'failed',
  14. message: e.message,
  15. }
  16. end
  17. def query
  18. config = Setting.get('gitlab_config')
  19. gitlab = ::GitLab.new(config['endpoint'], config['api_token'], verify_ssl: config['verify_ssl'])
  20. data = gitlab.issues_by_urls(params[:links])
  21. gitlab.fix_urls_for_ticket(params[:ticket_id], data[:url_replacements])
  22. render json: {
  23. result: 'ok',
  24. response: data[:issues],
  25. }
  26. rescue => e
  27. logger.error e
  28. render json: {
  29. result: 'failed',
  30. message: e.message,
  31. }
  32. end
  33. def update
  34. ticket = Ticket.find(params[:ticket_id])
  35. ticket.with_lock do
  36. authorize!(ticket, :show?)
  37. ticket.preferences[:gitlab] ||= {}
  38. ticket.preferences[:gitlab][:issue_links] = Array(params[:issue_links]).uniq
  39. ticket.save!
  40. end
  41. render json: {
  42. result: 'ok',
  43. }
  44. end
  45. end