diff --git a/Gemfile b/Gemfile index fd6364427..3cddb2774 100644 --- a/Gemfile +++ b/Gemfile @@ -123,7 +123,6 @@ gem 'acts_as_list' # integrations gem 'clearbit' -gem 'graphql-client' gem 'net-ldap' gem 'slack-notifier' gem 'zendesk_api' diff --git a/Gemfile.lock b/Gemfile.lock index 03bdd0727..cb397af57 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -218,10 +218,6 @@ GEM activesupport (>= 4.2.0) gmail_xoauth (0.4.2) oauth (>= 0.3.6) - graphql (1.11.6) - graphql-client (0.16.0) - activesupport (>= 3.0) - graphql (~> 1.8) guard (2.15.0) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) @@ -617,7 +613,6 @@ DEPENDENCIES faker github_changelog_generator gmail_xoauth - graphql-client guard guard-livereload guard-symlink diff --git a/app/assets/javascripts/app/controllers/_integration/github.coffee b/app/assets/javascripts/app/controllers/_integration/github.coffee index e3ace7e5a..284f01945 100644 --- a/app/assets/javascripts/app/controllers/_integration/github.coffee +++ b/app/assets/javascripts/app/controllers/_integration/github.coffee @@ -51,8 +51,7 @@ class Form extends App.Controller ) return - config.schema = data.response - App.Setting.set('github_config', config) + App.Setting.set('github_config', config, notify: true) error: (data, status) -> diff --git a/app/assets/javascripts/app/controllers/_integration/gitlab.coffee b/app/assets/javascripts/app/controllers/_integration/gitlab.coffee index 223905ca0..a0220d37c 100644 --- a/app/assets/javascripts/app/controllers/_integration/gitlab.coffee +++ b/app/assets/javascripts/app/controllers/_integration/gitlab.coffee @@ -51,8 +51,7 @@ class Form extends App.Controller ) return - config.schema = data.response - App.Setting.set('gitlab_config', config) + App.Setting.set('gitlab_config', config, notify: true) error: (data, status) -> diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_git_issue.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_git_issue.coffee index 9590e4461..19d28e93d 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_git_issue.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_git_issue.coffee @@ -4,7 +4,8 @@ class App.SidebarGitIssue extends App.Controller constructor: -> super - @issueLinks = [] + @issueLinks = [] + @issueLinkData = [] @providerIdentifier = @provider.toLowerCase() sidebarItem: => @@ -13,7 +14,7 @@ class App.SidebarGitIssue extends App.Controller name: @providerIdentifier badgeCallback: @badgeRender sidebarHead: @provider - sidebarCallback: @showObjects + sidebarCallback: @reloadIssues sidebarActions: [ { title: 'Link issue' @@ -26,8 +27,8 @@ class App.SidebarGitIssue extends App.Controller shown: -> return if !@ticket - return if !@ticket.id - @showIssues() + + @listIssues() metaBadge: => counter = '' @@ -45,6 +46,7 @@ class App.SidebarGitIssue extends App.Controller @badgeRenderLocal() badgeRenderLocal: => + return if !@badgeEl @badgeEl.html(App.view('generic/sidebar_tabs_item')(@metaBadge())) linkIssue: => @@ -54,86 +56,141 @@ class App.SidebarGitIssue extends App.Controller taskKey: @taskKey container: @el.closest('.content') callback: (link, ui) => - if @ticket && @ticket.id - @saveTicketIssues = true - ui.close() - @showIssues([link]) + @getIssues( + links: [link] + success: (result) => + if !_.contains(@issueLinks, link) + @issueLinks.push(result[0].url) + @issueLinkData = @issueLinkData.concat(result) + + if @ticket && @ticket.id + @saveIssues( + ticket_id: @ticket.id + links: @issueLinks + success: => + ui.close() + @renderIssues() + error: (message = 'Unable to save issue') => + ui.showAlert(App.i18n.translatePlain(message)) + form = ui.el.find('.js-result') + @formEnable(form) + ) + else + ui.close() + @renderIssues() + error: (message = 'Unable to load issues') => + ui.showAlert(App.i18n.translatePlain(message)) + form = ui.el.find('.js-result') + @formEnable(form) + ) ) - showObjects: (el) => - @el = el + reloadIssues: (el) => + if el + @el = el - # show placeholder - if @ticket && @ticket.preferences && @ticket.preferences[@providerIdentifier] && @ticket.preferences[@providerIdentifier].issue_links - @issueLinks = @ticket.preferences[@providerIdentifier].issue_links - queryParams = @queryParam() + return @renderIssues() if !@ticket - # TODO: what is 'gitlab_issue_links' - if queryParams && queryParams.gitlab_issue_links - @issueLinks.push queryParams.gitlab_issue_links - @showIssues() + ticketLinks = @ticket?.preferences?[@providerIdentifier]?.issue_links || [] + return @renderIssues() if _.isEqual(@issueLinks, ticketLinks) - showIssues: (issueLinks) => - if issueLinks - @issueLinks = _.uniq(@issueLinks.concat(issueLinks)) + @issueLinks = ticketLinks + @listIssues(true) - # show placeholder - if _.isEmpty(@issueLinks) - @html("
#{App.i18n.translateInline('No linked issues')}
") + renderIssues: => + if _.isEmpty(@issueLinkData) + @showEmpty() return - # AJAX call to show items - @ajax( - id: "#{@providerIdentifier}-#{@taskKey}" - type: 'POST' - url: "#{@apiPath}/integration/#{@providerIdentifier}" - data: JSON.stringify(links: @issueLinks) - success: (data, status, xhr) => - if data.response - @showList(data.response) - if @saveTicketIssues - @saveTicketIssues = false - @issueLinks = data.response.map((issue) -> issue.url) - @updateTicket(@ticket.id, @issueLinks) - return - @showError('Unable to load data...') - - error: (xhr, status, error) => - - # do not close window if request is aborted - return if status is 'abort' - - # show error message - @showError('Unable to load data...') - ) - - showList: (issues) => list = $(App.view('ticket_zoom/sidebar_git_issue')( - issues: issues + issues: @issueLinkData )) list.delegate('.js-delete', 'click', (e) => e.preventDefault() issueLink = $(e.currentTarget).attr 'data-issue-id' - @delete(issueLink) + @deleteIssue(issueLink) ) @html(list) @badgeRenderLocal() + listIssues: (force = false) => + return @renderIssues() if !force && @fetchFullActive && @fetchFullActive > new Date().getTime() - 5000 + @fetchFullActive = new Date().getTime() + + return @renderIssues() if _.isEmpty(@issueLinks) + + @getIssues( + links: @issueLinks + success: (result) => + @issueLinks = result.map((element) -> element.url) + @issueLinkData = result + @renderIssues() + error: => + @showError(App.i18n.translateInline('Unable to load issues')) + ) + + getIssues: (params) -> + @ajax( + id: "#{@providerIdentifier}-#{@taskKey}" + type: 'POST' + url: "#{@apiPath}/integration/#{@providerIdentifier}" + data: JSON.stringify(links: params.links) + success: (data, status, xhr) -> + if data.response + + # some issues redirect to pull requests like + # https://github.com/zammad/zammad/issues/1574 + # in this case throw error + return params.error('Unable to load issues') if _.isEmpty(data.response) + + params.success(data.response) + else + params.error(data.message) + error: (xhr, status, error) -> + return if status is 'abort' + + params.error() + ) + + saveIssues: (params) -> + App.Ajax.request( + id: "#{@providerIdentifier}-update-#{params.ticket_id}" + type: 'POST' + url: "#{@apiPath}/integration/#{@providerIdentifier}_ticket_update" + data: JSON.stringify(ticket_id: params.ticket_id, issue_links: params.links) + success: (data, status, xhr) -> + params.success(data) + error: (xhr, status, details) -> + return if status is 'abort' + + params.error() + ) + + deleteIssue: (link) -> + @issueLinks = _.filter(@issueLinks, (element) -> element isnt link) + @issueLinkData = _.filter(@issueLinkData, (element) -> element.url isnt link) + + if @ticket && @ticket.id + @saveIssues( + ticket_id: @ticket.id + links: @issueLinks + success: => + @renderIssues() + error: (message = 'Unable to save issue') => + @showError(App.i18n.translateInline(message)) + ) + else + @renderIssues() + + showEmpty: -> + @html("
#{App.i18n.translateInline('No linked issues')}
") + @badgeRenderLocal() + showError: (message) => @html App.i18n.translateInline(message) reload: => - @showIssues() - - delete: (issueLink) => - localLinks = [] - for localLink in @issueLinks - if issueLink.toString() isnt localLink.toString() - localLinks.push localLink - @issueLinks = localLinks - if @ticket && @ticket.id - @updateTicket(@ticket.id, @issueLinks) - @showIssues() + @reloadIssues() postParams: (args) => return if !args.ticket @@ -143,25 +200,3 @@ class App.SidebarGitIssue extends App.Controller args.ticket.preferences ||= {} args.ticket.preferences[@providerIdentifier] ||= {} args.ticket.preferences[@providerIdentifier].issue_links = @issueLinks - - updateTicket: (ticket_id, issueLinks) => - App.Ajax.request( - id: "#{@providerIdentifier}-update-#{ticket_id}" - type: 'POST' - url: "#{@apiPath}/integration/#{@providerIdentifier}_ticket_update" - data: JSON.stringify(ticket_id: ticket_id, issue_links: issueLinks) - success: (data, status, xhr) => - @badgeRenderLocal() - error: (xhr, status, details) => - - # do not close window if request is aborted - return if status is 'abort' - - # show error message - @log 'errors', details - @notify( - type: 'error' - msg: App.i18n.translateContent(details.error_human || details.error || 'Unable to update object!') - timeout: 6000 - ) - ) diff --git a/app/assets/javascripts/app/views/integration/git_issue_link_modal.jst.eco b/app/assets/javascripts/app/views/integration/git_issue_link_modal.jst.eco index 6d9734423..389ab9cfc 100644 --- a/app/assets/javascripts/app/views/integration/git_issue_link_modal.jst.eco +++ b/app/assets/javascripts/app/views/integration/git_issue_link_modal.jst.eco @@ -1,3 +1,3 @@ -
+
- +
diff --git a/app/controllers/integration/github_controller.rb b/app/controllers/integration/github_controller.rb index 2cab8e130..ee2f05179 100644 --- a/app/controllers/integration/github_controller.rb +++ b/app/controllers/integration/github_controller.rb @@ -5,9 +5,11 @@ class Integration::GitHubController < ApplicationController def verify github = ::GitHub.new(params[:endpoint], params[:api_token]) + + github.verify! + render json: { - result: 'ok', - response: github.schema.to_json, + result: 'ok', } rescue => e logger.error e @@ -21,7 +23,7 @@ class Integration::GitHubController < ApplicationController def query config = Setting.get('github_config') - github = ::GitHub.new(config['endpoint'], config['api_token'], schema: config['schema']) + github = ::GitHub.new(config['endpoint'], config['api_token']) render json: { result: 'ok', diff --git a/app/controllers/integration/gitlab_controller.rb b/app/controllers/integration/gitlab_controller.rb index abc2e8e61..0143054ee 100644 --- a/app/controllers/integration/gitlab_controller.rb +++ b/app/controllers/integration/gitlab_controller.rb @@ -5,9 +5,11 @@ class Integration::GitLabController < ApplicationController def verify gitlab = ::GitLab.new(params[:endpoint], params[:api_token]) + + gitlab.verify! + render json: { - result: 'ok', - response: gitlab.schema.to_json, + result: 'ok', } rescue => e logger.error e @@ -21,7 +23,7 @@ class Integration::GitLabController < ApplicationController def query config = Setting.get('gitlab_config') - gitlab = ::GitLab.new(config['endpoint'], config['api_token'], schema: config['schema']) + gitlab = ::GitLab.new(config['endpoint'], config['api_token']) render json: { result: 'ok', diff --git a/lib/github.rb b/lib/github.rb index de35f63c6..f6dc5c74d 100644 --- a/lib/github.rb +++ b/lib/github.rb @@ -1,14 +1,14 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ class GitHub - extend Forwardable - attr_reader :client - def_delegator :client, :schema + def initialize(endpoint, api_token) + @client = GitHub::HttpClient.new(endpoint, api_token) + end - def initialize(*args, **kargs) - @client = GitHub::Client.new(*args, **kargs) + def verify! + GitHub::Credentials.new(client).verify! end def issues_by_urls(urls) diff --git a/lib/github/client.rb b/lib/github/client.rb deleted file mode 100644 index adbcfde6d..000000000 --- a/lib/github/client.rb +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'graphql/client' - -class GitHub - class Client - - delegate_missing_to :client - - attr_reader :endpoint - - def initialize(endpoint, api_token, schema: nil) - @endpoint = endpoint - @api_token = api_token - schema(schema) if schema.present? - end - - def schema(source = http_client) - @schema ||= ::GraphQL::Client.load_schema(source) - end - - private - - def http_client - @http_client ||= GitHub::HttpClient.new(@endpoint, @api_token) - end - - def client - @client ||= begin - GraphQL::Client.new( - schema: schema, - execute: http_client, - ).tap do |client| - client.allow_dynamic_queries = true - end - end - end - end -end diff --git a/lib/github/credentials.rb b/lib/github/credentials.rb new file mode 100644 index 000000000..e21db67d9 --- /dev/null +++ b/lib/github/credentials.rb @@ -0,0 +1,28 @@ +# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ +class GitHub + class Credentials + + QUERY = <<-'GRAPHQL'.freeze + query { + viewer { + login + } + } + GRAPHQL + + attr_reader :client + + def initialize(client) + @client = client + end + + def verify! + response = client.perform( + query: GitHub::Credentials::QUERY, + ) + return if response.dig('data', 'viewer', 'login').present? + + raise 'Invalid GitHub GraphQL API token' + end + end +end diff --git a/lib/github/http_client.rb b/lib/github/http_client.rb index e00c3da54..71a4b5270 100644 --- a/lib/github/http_client.rb +++ b/lib/github/http_client.rb @@ -1,22 +1,45 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'graphql/client' -require 'graphql/client/http' class GitHub - class HttpClient < ::GraphQL::Client::HTTP + 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? @api_token = api_token - - super(endpoint) + @endpoint = endpoint end - def headers(_context) + def perform(payload) + response = UserAgent.post( + endpoint, + payload, + { + headers: headers, + json: true, + open_timeout: 6, + read_timeout: 16, + log: { + facility: 'GitHub', + }, + }, + ) + + if !response.success? + Rails.logger.error response.error + raise "Error while requesting GitHub GraphQL API: #{response.error}" + end + + response.data + end + + private + + def headers { - Authorization: "bearer #{@api_token}" + Authorization: "bearer #{api_token}" } end end diff --git a/lib/github/linked_issue.rb b/lib/github/linked_issue.rb index cc3c49163..72b9e6517 100644 --- a/lib/github/linked_issue.rb +++ b/lib/github/linked_issue.rb @@ -87,28 +87,28 @@ class GitHub @result.dig('milestone', 'title') end - def query - @query ||= client.parse GitHub::LinkedIssue::QUERY - end - def query_by_url(url) - variables = variables(url) - return if variables.blank? + response = client.perform( + query: GitHub::LinkedIssue::QUERY, + variables: variables!(url) + ) - response = client.query(query, variables: variables) - - response&.data&.repository&.issue&.to_h&.deep_dup + response.dig('data', 'repository', 'issue') end - def variables(url) - return if url !~ %r{^https://([^/]+)/([^/]+)/([^/]+)/issues/(\d+)$} + def variables!(url) + if url !~ %r{^https://([^/]+)/([^/]+)/([^/]+)/issues/(\d+)$} + raise Exceptions::UnprocessableEntity, 'Invalid GitHub issue link format' + end host = $1 repositor_owner = $2 repository_name = $3 id = $4 - return if client.endpoint.exclude?(host) + if client.endpoint.exclude?(host) + raise Exceptions::UnprocessableEntity, "Issue link doesn't match configured GitHub endpoint '#{client.endpoint}'" + end { repositor_owner: repositor_owner, diff --git a/lib/gitlab.rb b/lib/gitlab.rb index 81d96aa05..200a97748 100644 --- a/lib/gitlab.rb +++ b/lib/gitlab.rb @@ -1,14 +1,14 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ class GitLab - extend Forwardable - attr_reader :client - def_delegator :client, :schema + def initialize(endpoint, api_token) + @client = GitLab::HttpClient.new(endpoint, api_token) + end - def initialize(*args, **kargs) - @client = GitLab::Client.new(*args, **kargs) + def verify! + GitLab::Credentials.new(client).verify! end def issues_by_urls(urls) diff --git a/lib/gitlab/client.rb b/lib/gitlab/client.rb deleted file mode 100644 index 7fc371361..000000000 --- a/lib/gitlab/client.rb +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'graphql/client' - -class GitLab - class Client - - delegate_missing_to :client - - attr_reader :endpoint - - def initialize(endpoint, api_token, schema: nil) - @endpoint = endpoint - @api_token = api_token - schema(schema) if schema.present? - end - - def schema(source = http_client) - @schema ||= ::GraphQL::Client.load_schema(source) - end - - private - - def http_client - @http_client ||= GitLab::HttpClient.new(@endpoint, @api_token) - end - - def client - @client ||= begin - GraphQL::Client.new( - schema: schema, - execute: http_client, - ).tap do |client| - client.allow_dynamic_queries = true - end - end - end - end -end diff --git a/lib/gitlab/credentials.rb b/lib/gitlab/credentials.rb new file mode 100644 index 000000000..fa335ecf9 --- /dev/null +++ b/lib/gitlab/credentials.rb @@ -0,0 +1,28 @@ +# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ +class GitLab + class Credentials + + QUERY = <<-'GRAPHQL'.freeze + query { + currentUser { + username + } + } + GRAPHQL + + attr_reader :client + + def initialize(client) + @client = client + end + + def verify! + response = client.perform( + query: GitLab::Credentials::QUERY, + ) + return if response.dig('data', 'currentUser', 'username').present? + + raise 'Invalid GitLab GraphQL API token' + end + end +end diff --git a/lib/gitlab/http_client.rb b/lib/gitlab/http_client.rb index 8a6fc6825..8a97b37d6 100644 --- a/lib/gitlab/http_client.rb +++ b/lib/gitlab/http_client.rb @@ -1,20 +1,43 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'graphql/client' -require 'graphql/client/http' class GitLab - class HttpClient < ::GraphQL::Client::HTTP + 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? @api_token = api_token - - super(endpoint) + @endpoint = endpoint end - def headers(_context) + def perform(payload) + response = UserAgent.post( + endpoint, + payload, + { + headers: headers, + json: true, + open_timeout: 6, + read_timeout: 16, + log: { + facility: 'GitLab', + }, + }, + ) + + if !response.success? + Rails.logger.error response.error + raise "Error while requesting GitLab GraphQL API: #{response.error}" + end + + response.data + end + + private + + def headers { "PRIVATE-TOKEN": @api_token } diff --git a/lib/gitlab/linked_issue.rb b/lib/gitlab/linked_issue.rb index a3762eb47..144f7cfd9 100644 --- a/lib/gitlab/linked_issue.rb +++ b/lib/gitlab/linked_issue.rb @@ -84,27 +84,30 @@ class GitLab @result.dig('milestone', 'title') end - def query - @query ||= client.parse GitLab::LinkedIssue::QUERY - end - def query_by_url(url) variables = variables(url) return if variables.blank? - response = client.query(query, variables: variables) + response = client.perform( + query: GitLab::LinkedIssue::QUERY, + variables: variables + ) - response&.data&.project&.issue&.to_h&.deep_dup + response.dig('data', 'project', 'issue') end def variables(url) - return if url !~ %r{^https://([^/]+)/(.*)/-/issues/(\d+)$} + if url !~ %r{^https://([^/]+)/(.*)/-/issues/(\d+)$} + raise Exceptions::UnprocessableEntity, 'Invalid GitLab issue link format' + end host = $1 fullpath = $2 id = $3 - return if client.endpoint.exclude?(host) + if client.endpoint.exclude?(host) + raise Exceptions::UnprocessableEntity, "Issue link doesn't match configured GitLab endpoint '#{client.endpoint}'" + end { fullpath: fullpath, diff --git a/spec/integration/github_spec.rb b/spec/integration/github_spec.rb index 1b0f049e3..633823add 100644 --- a/spec/integration/github_spec.rb +++ b/spec/integration/github_spec.rb @@ -6,13 +6,9 @@ RSpec.describe GitHub, type: :integration do # rubocop:disable RSpec/FilePath required_envs.each do |key| skip("NOTICE: Missing environment variable #{key} for test! (Please fill up: #{required_envs.join(' && ')})") if ENV[key].blank? end - - # request schema only once for performance reasons - @cached_schema = described_class.new(ENV['GITHUB_ENDPOINT'], ENV['GITHUB_APITOKEN']).schema end - let(:instance) { described_class.new(ENV['GITHUB_ENDPOINT'], ENV['GITHUB_APITOKEN'], schema: schema) } - let(:schema) { @cached_schema } # rubocop:disable RSpec/InstanceVariable + let(:instance) { described_class.new(ENV['GITHUB_ENDPOINT'], ENV['GITHUB_APITOKEN']) } let(:issue_data) do { id: '1575', @@ -37,12 +33,6 @@ RSpec.describe GitHub, type: :integration do # rubocop:disable RSpec/FilePath end let(:invalid_issue_url) { 'https://github.com/organization/repository/issues/42' } - describe '#schema' do - it 'returns GraphQL schema' do - expect(instance.schema).to respond_to(:to_graphql) - end - end - describe '#issues_by_urls' do let(:result) { instance.issues_by_urls([ issue_url ]) } diff --git a/spec/integration/gitlab_spec.rb b/spec/integration/gitlab_spec.rb index 6c598cb78..9d37fc64a 100644 --- a/spec/integration/gitlab_spec.rb +++ b/spec/integration/gitlab_spec.rb @@ -6,13 +6,9 @@ RSpec.describe GitLab, type: :integration do # rubocop:disable RSpec/FilePath required_envs.each do |key| skip("NOTICE: Missing environment variable #{key} for test! (Please fill up: #{required_envs.join(' && ')})") if ENV[key].blank? end - - # request schema only once for performance reasons - @cached_schema = described_class.new(ENV['GITLAB_ENDPOINT'], ENV['GITLAB_APITOKEN']).schema end - let(:instance) { described_class.new(ENV['GITLAB_ENDPOINT'], ENV['GITLAB_APITOKEN'], schema: schema) } - let(:schema) { @cached_schema } # rubocop:disable RSpec/InstanceVariable + let(:instance) { described_class.new(ENV['GITLAB_ENDPOINT'], ENV['GITLAB_APITOKEN']) } let(:issue_data) do { id: '1', @@ -40,13 +36,7 @@ RSpec.describe GitLab, type: :integration do # rubocop:disable RSpec/FilePath ], } end - let(:invalid_issue_url) { 'https://git.example.com/group/project/-/issues/1' } - - describe '#schema' do - it 'returns GraphQL schema' do - expect(instance.schema).to respond_to(:to_graphql) - end - end + let(:invalid_issue_url) { "https://#{URI.parse(ENV['GITLAB_ISSUE_LINK']).host}/group/project/-/issues/1" } describe '#issues_by_urls' do let(:result) { instance.issues_by_urls([ issue_url ]) } diff --git a/spec/requests/integration/github_spec.rb b/spec/requests/integration/github_spec.rb index 873134c1a..b7a263e71 100644 --- a/spec/requests/integration/github_spec.rb +++ b/spec/requests/integration/github_spec.rb @@ -60,14 +60,13 @@ RSpec.describe 'GitHub', type: :request do authenticated_as(admin) instance = instance_double('GitHub') expect(GitHub).to receive(:new).with(endpoint, token).and_return instance - expect(instance).to receive(:schema).and_return(dummy_schema) + expect(instance).to receive(:verify!).and_return(true) post '/api/v1/integration/github/verify', params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response).not_to be_blank expect(json_response['result']).to eq('ok') - expect(json_response['response']).to eq(dummy_schema.to_json) end it 'does query objects' do diff --git a/spec/requests/integration/gitlab_spec.rb b/spec/requests/integration/gitlab_spec.rb index 914e179a6..6fb58d8d4 100644 --- a/spec/requests/integration/gitlab_spec.rb +++ b/spec/requests/integration/gitlab_spec.rb @@ -65,14 +65,13 @@ RSpec.describe 'GitLab', type: :request do authenticated_as(admin) instance = instance_double('GitLab') expect(GitLab).to receive(:new).with(endpoint, token).and_return instance - expect(instance).to receive(:schema).and_return(dummy_schema) + expect(instance).to receive(:verify!).and_return(true) post '/api/v1/integration/gitlab/verify', params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response).not_to be_blank expect(json_response['result']).to eq('ok') - expect(json_response['response']).to eq(dummy_schema.to_json) end it 'does query objects' do diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index 2f6ef8dc3..56da031fe 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -352,9 +352,6 @@ RSpec.describe 'Ticket Create', type: :system do required_envs.each do |key| skip("NOTICE: Missing environment variable #{key} for test! (Please fill up: #{required_envs.join(' && ')})") if ENV[key].blank? end - - # request schema only once for performance reasons - @cached_schema = GitLab.new(ENV['GITLAB_ENDPOINT'], ENV['GITLAB_APITOKEN']).schema.to_json end def authenticate @@ -362,7 +359,6 @@ RSpec.describe 'Ticket Create', type: :system do Setting.set('gitlab_config', { api_token: ENV['GITLAB_APITOKEN'], endpoint: ENV['GITLAB_ENDPOINT'], - schema: @cached_schema, # rubocop:disable RSpec/InstanceVariable }) true end @@ -410,9 +406,6 @@ RSpec.describe 'Ticket Create', type: :system do required_envs.each do |key| skip("NOTICE: Missing environment variable #{key} for test! (Please fill up: #{required_envs.join(' && ')})") if ENV[key].blank? end - - # request schema only once for performance reasons - @cached_schema = GitHub.new(ENV['GITHUB_ENDPOINT'], ENV['GITHUB_APITOKEN']).schema.to_json end def authenticate @@ -420,7 +413,6 @@ RSpec.describe 'Ticket Create', type: :system do Setting.set('github_config', { api_token: ENV['GITHUB_APITOKEN'], endpoint: ENV['GITHUB_ENDPOINT'], - schema: @cached_schema, # rubocop:disable RSpec/InstanceVariable }) true end diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index 1739edb71..b94678cd4 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -1513,9 +1513,6 @@ RSpec.describe 'Ticket zoom', type: :system do required_envs.each do |key| skip("NOTICE: Missing environment variable #{key} for test! (Please fill up: #{required_envs.join(' && ')})") if ENV[key].blank? end - - # request schema only once for performance reasons - @cached_schema = GitLab.new(ENV['GITLAB_ENDPOINT'], ENV['GITLAB_APITOKEN']).schema.to_json end def authenticate @@ -1523,7 +1520,6 @@ RSpec.describe 'Ticket zoom', type: :system do Setting.set('gitlab_config', { api_token: ENV['GITLAB_APITOKEN'], endpoint: ENV['GITLAB_ENDPOINT'], - schema: @cached_schema, # rubocop:disable RSpec/InstanceVariable }) true end @@ -1577,9 +1573,6 @@ RSpec.describe 'Ticket zoom', type: :system do required_envs.each do |key| skip("NOTICE: Missing environment variable #{key} for test! (Please fill up: #{required_envs.join(' && ')})") if ENV[key].blank? end - - # request schema only once for performance reasons - @cached_schema = GitHub.new(ENV['GITHUB_ENDPOINT'], ENV['GITHUB_APITOKEN']).schema.to_json end def authenticate @@ -1587,7 +1580,6 @@ RSpec.describe 'Ticket zoom', type: :system do Setting.set('github_config', { api_token: ENV['GITHUB_APITOKEN'], endpoint: ENV['GITHUB_ENDPOINT'], - schema: @cached_schema, # rubocop:disable RSpec/InstanceVariable }) true end