Maintenance: Enhanced GitHub and GitLab GraphQL endpoint check

This commit is contained in:
Rolf Schmidt 2021-08-23 16:51:16 +02:00 committed by Thorsten Eckel
parent 25155eb6a3
commit 573c975bad
2 changed files with 8 additions and 4 deletions

View file

@ -1,12 +1,14 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'uri'
class GitHub
class HttpClient
attr_reader :api_token, :endpoint
def initialize(endpoint, api_token)
raise 'api_token required' if api_token.blank?
raise 'endpoint required' if endpoint.blank?
raise 'endpoint required' if endpoint.blank? || endpoint.exclude?('/graphql') || endpoint.scan(URI::DEFAULT_PARSER.make_regexp).blank?
@api_token = api_token
@endpoint = endpoint
@ -30,7 +32,7 @@ class GitHub
if !response.success?
Rails.logger.error response.error
raise "Error while requesting GitHub GraphQL API: #{response.error}"
raise 'GitHub request failed! Please have a look at the log file for details'
end
response.data

View file

@ -1,12 +1,14 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'uri'
class GitLab
class HttpClient
attr_reader :api_token, :endpoint
def initialize(endpoint, api_token)
raise 'api_token required' if api_token.blank?
raise 'endpoint required' if endpoint.blank?
raise 'endpoint required' if endpoint.blank? || endpoint.exclude?('/graphql') || endpoint.scan(URI::DEFAULT_PARSER.make_regexp).blank?
@api_token = api_token
@endpoint = endpoint
@ -30,7 +32,7 @@ class GitLab
if !response.success?
Rails.logger.error response.error
raise "Error while requesting GitLab GraphQL API: #{response.error}"
raise 'GitLab request failed! Please have a look at the log file for details'
end
response.data