gitlab.rb 858 B

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