github.rb 837 B

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class GitHub < GitIntegrationBase
  3. def initialize(endpoint, api_token) # rubocop:disable Lint/MissingSuper
  4. @client = GitHub::HttpClient.new(endpoint, api_token)
  5. @issue_type = :github
  6. end
  7. def verify!
  8. GitHub::Credentials.new(client).verify!
  9. end
  10. def issues_by_urls(urls)
  11. url_replacements = {}
  12. issues = urls.uniq.each_with_object([]) do |url, result|
  13. issue = issue_by_url(url)
  14. next if issue.blank?
  15. if issue[:url] != url
  16. url_replacements.store(url, issue[:url])
  17. end
  18. result << issue
  19. end
  20. {
  21. issues: issues,
  22. url_replacements: url_replacements
  23. }
  24. end
  25. def issue_by_url(url)
  26. issue = GitHub::LinkedIssue.new(client)
  27. issue.find_by(url)&.to_h
  28. end
  29. end