github_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Integration::GitHubController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  4. def verify
  5. github = ::GitHub.new(params[:endpoint], params[:api_token])
  6. github.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('github_config')
  19. github = ::GitHub.new(config['endpoint'], config['api_token'])
  20. data = github.issues_by_urls(params[:links])
  21. github.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[:github] ||= {}
  38. ticket.preferences[:github][:issue_links] = Array(params[:issue_links]).uniq
  39. ticket.save!
  40. end
  41. render json: {
  42. result: 'ok',
  43. }
  44. end
  45. end