github_controller.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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(endpoint: params[:endpoint], api_token: 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. issue_tracker_list_service = if params[:ticket_id]
  19. Service::Ticket::ExternalReferences::IssueTracker::TicketList.new(
  20. type: 'github',
  21. ticket: Ticket.find(params[:ticket_id]),
  22. )
  23. else
  24. Service::Ticket::ExternalReferences::IssueTracker::FetchMetadata.new(
  25. type: 'github',
  26. issue_links: params[:links],
  27. )
  28. end
  29. render json: {
  30. result: 'ok',
  31. response: issue_tracker_list_service.execute,
  32. }
  33. rescue => e
  34. logger.error e
  35. render json: {
  36. result: 'failed',
  37. message: e.message,
  38. }
  39. end
  40. def update
  41. ticket = Ticket.find(params[:ticket_id])
  42. ticket.with_lock do
  43. authorize!(ticket, :show?)
  44. ticket.preferences[:github] ||= {}
  45. ticket.preferences[:github][:issue_links] = Array(params[:issue_links]).uniq
  46. ticket.save!
  47. end
  48. render json: {
  49. result: 'ok',
  50. }
  51. end
  52. end