gitlab_controller.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Integration::GitLabController < ApplicationController
  3. prepend_before_action { authentication_check && authorize! }
  4. def verify
  5. gitlab = ::GitLab.new(params[:endpoint], params[:api_token])
  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'])
  20. render json: {
  21. result: 'ok',
  22. response: gitlab.issues_by_urls(params[:links]),
  23. }
  24. rescue => e
  25. logger.error e
  26. render json: {
  27. result: 'failed',
  28. message: e.message,
  29. }
  30. end
  31. def update
  32. ticket = Ticket.find(params[:ticket_id])
  33. ticket.with_lock do
  34. authorize!(ticket, :show?)
  35. ticket.preferences[:gitlab] ||= {}
  36. ticket.preferences[:gitlab][:issue_links] = Array(params[:issue_links]).uniq
  37. ticket.save!
  38. end
  39. render json: {
  40. result: 'ok',
  41. }
  42. end
  43. end