diff --git a/app/controllers/api/v1/accounts/integrations/linear_controller.rb b/app/controllers/api/v1/accounts/integrations/linear_controller.rb index 1c8f5f182..ef9fcf235 100644 --- a/app/controllers/api/v1/accounts/integrations/linear_controller.rb +++ b/app/controllers/api/v1/accounts/integrations/linear_controller.rb @@ -1,5 +1,5 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::BaseController - before_action :fetch_conversation, only: [:link_issue] + before_action :fetch_conversation, only: [:link_issue, :linked_issue] def teams teams = linear_processor_service.teams @@ -51,10 +51,7 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::Bas end def linked_issue - render json: { error: 'Specify link with parameter link' }, status: :unprocessable_entity if params[:link].blank? && return - - url = params[:link] - issues = linear_processor_service.linked_issue(url) + issues = linear_processor_service.linked_issue(conversation_link) if issues.is_a?(Hash) && issues[:error] render json: { error: issues[:error] }, status: :unprocessable_entity diff --git a/lib/linear_queries.rb b/lib/linear_queries.rb index f76f1dedc..630a84f0d 100644 --- a/lib/linear_queries.rb +++ b/lib/linear_queries.rb @@ -68,8 +68,26 @@ module LinearQueries title issue { id + identifier title description + priority + createdAt + state { + name + } + state { + name + } + assignee { + name + } + labels { + nodes{ + id + name + } + } } } } diff --git a/spec/controllers/api/v1/accounts/integrations/linear_controller_spec.rb b/spec/controllers/api/v1/accounts/integrations/linear_controller_spec.rb index cda3e6671..e81042b03 100644 --- a/spec/controllers/api/v1/accounts/integrations/linear_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/integrations/linear_controller_spec.rb @@ -222,7 +222,8 @@ RSpec.describe 'Linear Integration API', type: :request do end describe 'GET /api/v1/accounts/:account_id/integrations/linear/linked_issue' do - let(:link) { 'https://linear.app/issue1' } + let(:conversation) { create(:conversation, account: account) } + let(:link) { "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{account.id}/conversations/#{conversation.display_id}" } context 'when it is an authenticated user' do context 'when linked issue is found' do @@ -231,7 +232,7 @@ RSpec.describe 'Linear Integration API', type: :request do it 'returns linked issue' do allow(processor_service).to receive(:linked_issue).with(link).and_return(linked_issue) get "/api/v1/accounts/#{account.id}/integrations/linear/linked_issue", - params: { link: link }, + params: { conversation_id: conversation.display_id }, headers: agent.create_new_auth_token, as: :json expect(response).to have_http_status(:ok) @@ -243,7 +244,7 @@ RSpec.describe 'Linear Integration API', type: :request do it 'returns error message' do allow(processor_service).to receive(:linked_issue).with(link).and_return(error: 'error message') get "/api/v1/accounts/#{account.id}/integrations/linear/linked_issue", - params: { link: link }, + params: { conversation_id: conversation.display_id }, headers: agent.create_new_auth_token, as: :json expect(response).to have_http_status(:unprocessable_entity)