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,57 +9,91 @@ 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
context 'when jira_integration feature disabled' do
it 'returns 404 status' do
stub_feature_flags(jira_integration: false)
get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:not_found)
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) }
before do
sign_in(user)
project.add_developer(user)
create(:jira_service, project: project)
project.route.destroy!
new_project.redirect_routes.create!(path: project.full_path)
new_project.add_developer(user)
end
it 'renders the "index" template' do
it 'redirects to the new issue tracker from the old one' 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)
expect(response).to redirect_to(project_integrations_jira_issues_path(new_project))
expect(response).to have_gitlab_http_status(:found)
end
end
context 'when jira_integration feature disabled' do
it 'returns 404 status' do
stub_feature_flags(jira_integration: false)
context 'json request' do
let(:jira_issues) { [] }
get :index, params: { namespace_id: project.namespace, project_id: project }
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(response).to have_gitlab_http_status(:not_found)
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
context 'when project has moved' do
let(:new_project) { create(:project) }
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')
before do
project.route.destroy!
new_project.redirect_routes.create!(path: project.full_path)
new_project.add_developer(user)
end
get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json
it 'redirects to the new issue tracker from the old one' do
get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['errors']).to eq ['Integration error']
end
expect(response).to redirect_to(project_integrations_jira_issues_path(new_project))
expect(response).to have_gitlab_http_status(:found)
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
before do
sign_in user
project.add_developer(user)
end
context 'external authorization' do
before do
sign_in user
project.add_developer(user)
end
it_behaves_like 'unauthorized when external service denies access' do
subject { get :index, params: { namespace_id: project.namespace, project_id: project } }
end
it_behaves_like 'unauthorized when external service denies access' do
subject { get :index, params: { namespace_id: project.namespace, project_id: project } }
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