Commit 4f7ccca0 authored by Michael Kozono's avatar Michael Kozono

Merge branch '224850-create-api-endpoint-for-querying-jira-issues' into 'master'

Create a JSON endpoint for querying Jira issues

See merge request gitlab-org/gitlab!35477
parents 629c7f77 7de3ae9c
......@@ -14,6 +14,22 @@ module Projects
end
def index
respond_to do |format|
format.html
format.json do
render json: issues_json
rescue Projects::Integrations::Jira::IntegrationError, Projects::Integrations::Jira::RequestError => e
render_bad_request(e)
end
end
end
private
def issues_json
jira_issues = ::Projects::Integrations::Jira::IssuesFinder.new(project, {}).execute
::Integrations::Jira::IssueSerializer.new.represent(jira_issues, project: project)
end
protected
......@@ -21,6 +37,10 @@ module Projects
def check_feature_enabled!
return render_404 unless Feature.enabled?(:jira_integration, project)
end
def render_bad_request(error)
render json: { errors: [error.message] }, status: :bad_request
end
end
end
end
......
- page_title _('Jira Issues')
.js-issuables-list{ data: { endpoint: expose_url(api_v4_groups_issues_path(id: @project.group.id)),
.js-issuables-list{ data: { endpoint: expose_path(project_integrations_jira_issues_path(@project, format: :json)),
'can-bulk-edit': false,
'empty-svg-path': image_path('illustrations/issues.svg'),
'sort-key': @sort } }
......@@ -9,20 +9,12 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
let(:user) { create(:user) }
describe 'GET #index' do
context 'external issue tracker' do
before do
sign_in(user)
project.add_developer(user)
create(:jira_service, project: project)
end
it 'renders the "index" template' do
get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
end
context 'when jira_integration feature disabled' do
it 'returns 404 status' do
stub_feature_flags(jira_integration: false)
......@@ -33,6 +25,13 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
end
end
it 'renders the "index" template' do
get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
end
context 'when project has moved' do
let(:new_project) { create(:project) }
......@@ -49,6 +48,42 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
expect(response).to have_gitlab_http_status(:found)
end
end
context 'json request' do
let(:jira_issues) { [] }
it 'returns a list of serialized jira issues' do
expect_next_instance_of(Projects::Integrations::Jira::IssuesFinder, project, {}) do |finder|
expect(finder).to receive(:execute).and_return(jira_issues)
end
expect_next_instance_of(Integrations::Jira::IssueSerializer) do |serializer|
expect(serializer).to receive(:represent).with(jira_issues, project: project)
end
get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json
end
it 'renders bad request for IntegrationError' do
expect_any_instance_of(Projects::Integrations::Jira::IssuesFinder).to receive(:execute)
.and_raise(Projects::Integrations::Jira::IntegrationError, 'Integration error')
get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['errors']).to eq ['Integration error']
end
it 'renders bad request for RequestError' do
expect_any_instance_of(Projects::Integrations::Jira::IssuesFinder).to receive(:execute)
.and_raise(Projects::Integrations::Jira::RequestError, 'Request error')
get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['errors']).to eq ['Request error']
end
end
end
context 'external authorization' do
......@@ -61,5 +96,4 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
subject { get :index, params: { namespace_id: project.namespace, project_id: project } }
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment