Maintenance: Enhanced GitHub and GitLab GraphQL endpoint check
This commit is contained in:
parent
5ddec48643
commit
6602d19dbf
2 changed files with 8 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue