credentials.rb 538 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class GitHub
  3. class Credentials
  4. QUERY = <<-GRAPHQL.freeze
  5. query {
  6. viewer {
  7. login
  8. }
  9. }
  10. GRAPHQL
  11. attr_reader :client
  12. def initialize(client)
  13. @client = client
  14. end
  15. def verify!
  16. response = client.perform(
  17. query: GitHub::Credentials::QUERY,
  18. )
  19. return if response.dig('data', 'viewer', 'login').present?
  20. raise __('Invalid GitHub GraphQL API token')
  21. end
  22. end
  23. end